blob: 8ad10c88c1a512d646701f44c8f1d325be54a3c9 [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;
6934 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
6935 rs_state_ci.depthBiasEnable = VK_FALSE;
6936
Tony Barboureb254902015-07-15 12:50:33 -06006937 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006938 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
6939 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07006940 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07006941 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
6942 gp_ci.layout = pipeline_layout;
6943 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06006944
6945 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006946 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
6947 pc_ci.initialDataSize = 0;
6948 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006949
6950 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06006951 VkPipelineCache pipelineCache;
6952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006953 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06006954 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006955 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006956
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006957 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006958
Chia-I Wuf7458c52015-10-26 21:10:41 +08006959 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
6960 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6961 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6962 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006963}
Tobin Ehlis912df022015-09-17 08:46:18 -06006964/*// TODO : This test should be good, but needs Tess support in compiler to run
6965TEST_F(VkLayerTest, InvalidPatchControlPoints)
6966{
6967 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06006968 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006969
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07006970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07006971 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
6972primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006973
Tobin Ehlis912df022015-09-17 08:46:18 -06006974 ASSERT_NO_FATAL_FAILURE(InitState());
6975 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06006976
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006977 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06006978 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08006979 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006980
6981 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6982 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6983 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006984 ds_pool_ci.poolSizeCount = 1;
6985 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06006986
6987 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07006988 err = vkCreateDescriptorPool(m_device->device(),
6989VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06006990 ASSERT_VK_SUCCESS(err);
6991
6992 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08006993 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06006994 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08006995 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06006996 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6997 dsl_binding.pImmutableSamplers = NULL;
6998
6999 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007000 ds_layout_ci.sType =
7001VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007002 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007003 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007004 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007005
7006 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007007 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7008&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007009 ASSERT_VK_SUCCESS(err);
7010
7011 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007012 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7013VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007014 ASSERT_VK_SUCCESS(err);
7015
7016 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007017 pipeline_layout_ci.sType =
7018VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007019 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007020 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007021 pipeline_layout_ci.pSetLayouts = &ds_layout;
7022
7023 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007024 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7025&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007026 ASSERT_VK_SUCCESS(err);
7027
7028 VkPipelineShaderStageCreateInfo shaderStages[3];
7029 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7030
Karl Schultz6addd812016-02-02 17:17:23 -07007031 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7032this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007033 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007034 VkShaderObj
7035tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7036this);
7037 VkShaderObj
7038te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7039this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007040
Karl Schultz6addd812016-02-02 17:17:23 -07007041 shaderStages[0].sType =
7042VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007043 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007044 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007045 shaderStages[1].sType =
7046VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007047 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007048 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007049 shaderStages[2].sType =
7050VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007051 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007052 shaderStages[2].shader = te.handle();
7053
7054 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007055 iaCI.sType =
7056VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007057 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007058
7059 VkPipelineTessellationStateCreateInfo tsCI = {};
7060 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7061 tsCI.patchControlPoints = 0; // This will cause an error
7062
7063 VkGraphicsPipelineCreateInfo gp_ci = {};
7064 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7065 gp_ci.pNext = NULL;
7066 gp_ci.stageCount = 3;
7067 gp_ci.pStages = shaderStages;
7068 gp_ci.pVertexInputState = NULL;
7069 gp_ci.pInputAssemblyState = &iaCI;
7070 gp_ci.pTessellationState = &tsCI;
7071 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007072 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007073 gp_ci.pMultisampleState = NULL;
7074 gp_ci.pDepthStencilState = NULL;
7075 gp_ci.pColorBlendState = NULL;
7076 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7077 gp_ci.layout = pipeline_layout;
7078 gp_ci.renderPass = renderPass();
7079
7080 VkPipelineCacheCreateInfo pc_ci = {};
7081 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7082 pc_ci.pNext = NULL;
7083 pc_ci.initialSize = 0;
7084 pc_ci.initialData = 0;
7085 pc_ci.maxSize = 0;
7086
7087 VkPipeline pipeline;
7088 VkPipelineCache pipelineCache;
7089
Karl Schultz6addd812016-02-02 17:17:23 -07007090 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7091&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007092 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007093 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7094&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007095
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007096 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007097
Chia-I Wuf7458c52015-10-26 21:10:41 +08007098 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7099 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7100 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7101 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007102}
7103*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007104
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007105TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007106 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007107
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007108 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007109
Tobin Ehlise68360f2015-10-01 11:15:13 -06007110 ASSERT_NO_FATAL_FAILURE(InitState());
7111 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007112
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007113 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007114 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7115 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007116
7117 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007118 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7119 ds_pool_ci.maxSets = 1;
7120 ds_pool_ci.poolSizeCount = 1;
7121 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007122
7123 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007124 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007125 ASSERT_VK_SUCCESS(err);
7126
7127 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007128 dsl_binding.binding = 0;
7129 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7130 dsl_binding.descriptorCount = 1;
7131 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007132
7133 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007134 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7135 ds_layout_ci.bindingCount = 1;
7136 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007137
7138 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007139 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007140 ASSERT_VK_SUCCESS(err);
7141
7142 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007143 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007144 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007145 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007146 alloc_info.descriptorPool = ds_pool;
7147 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007148 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007149 ASSERT_VK_SUCCESS(err);
7150
7151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7153 pipeline_layout_ci.setLayoutCount = 1;
7154 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007155
7156 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007157 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007158 ASSERT_VK_SUCCESS(err);
7159
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007160 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007161 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007162 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007163 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007164 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007165 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007166
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007167 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7168 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7169 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7170 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7171 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7172 rs_state_ci.depthClampEnable = VK_FALSE;
7173 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7174 rs_state_ci.depthBiasEnable = VK_FALSE;
7175
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007176 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7177 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7178 vi_ci.pNext = nullptr;
7179 vi_ci.vertexBindingDescriptionCount = 0;
7180 vi_ci.pVertexBindingDescriptions = nullptr;
7181 vi_ci.vertexAttributeDescriptionCount = 0;
7182 vi_ci.pVertexAttributeDescriptions = nullptr;
7183
7184 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7185 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7186 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7187
7188 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7189 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7190 pipe_ms_state_ci.pNext = NULL;
7191 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7192 pipe_ms_state_ci.sampleShadingEnable = 0;
7193 pipe_ms_state_ci.minSampleShading = 1.0;
7194 pipe_ms_state_ci.pSampleMask = NULL;
7195
Cody Northropeb3a6c12015-10-05 14:44:45 -06007196 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007197 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007198
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007199 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007200 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007201 shaderStages[0] = vs.GetStageCreateInfo();
7202 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007203
7204 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007205 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7206 gp_ci.stageCount = 2;
7207 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007208 gp_ci.pVertexInputState = &vi_ci;
7209 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007210 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007211 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007212 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007213 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7214 gp_ci.layout = pipeline_layout;
7215 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007216
7217 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007218 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007219
7220 VkPipeline pipeline;
7221 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007222 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007223 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007224
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007225 if (!m_device->phy().features().multiViewport) {
7226 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7227
7228 // Check case where multiViewport is disabled and viewport count is not 1
7229 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7230 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7232 vp_state_ci.scissorCount = 0;
7233 vp_state_ci.viewportCount = 0;
7234 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7235 m_errorMonitor->VerifyFound();
7236 } else {
7237 if (m_device->props.limits.maxViewports == 1) {
7238 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7239 } else {
7240 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7241
7242 // Check is that viewportcount and scissorcount match
7243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7244 vp_state_ci.scissorCount = 1;
7245 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7246 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7247 m_errorMonitor->VerifyFound();
7248
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007249 // Check case where multiViewport is enabled and viewport count is greater than max
7250 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7253 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7254 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7255 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7256 m_errorMonitor->VerifyFound();
7257 }
7258 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007259
Chia-I Wuf7458c52015-10-26 21:10:41 +08007260 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7261 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7262 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7263 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007264}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007265
7266// 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
7267// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007268TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007269 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007270
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007271 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7272
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007274
Tobin Ehlise68360f2015-10-01 11:15:13 -06007275 ASSERT_NO_FATAL_FAILURE(InitState());
7276 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007277
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007278 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007279 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7280 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007281
7282 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007283 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7284 ds_pool_ci.maxSets = 1;
7285 ds_pool_ci.poolSizeCount = 1;
7286 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007287
7288 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007289 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007290 ASSERT_VK_SUCCESS(err);
7291
7292 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007293 dsl_binding.binding = 0;
7294 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7295 dsl_binding.descriptorCount = 1;
7296 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007297
7298 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007299 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7300 ds_layout_ci.bindingCount = 1;
7301 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007302
7303 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007304 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007305 ASSERT_VK_SUCCESS(err);
7306
7307 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007308 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007309 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007310 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007311 alloc_info.descriptorPool = ds_pool;
7312 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007313 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007314 ASSERT_VK_SUCCESS(err);
7315
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007316 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7317 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7318 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7319
7320 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7321 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7322 vi_ci.pNext = nullptr;
7323 vi_ci.vertexBindingDescriptionCount = 0;
7324 vi_ci.pVertexBindingDescriptions = nullptr;
7325 vi_ci.vertexAttributeDescriptionCount = 0;
7326 vi_ci.pVertexAttributeDescriptions = nullptr;
7327
7328 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7329 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7330 pipe_ms_state_ci.pNext = NULL;
7331 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7332 pipe_ms_state_ci.sampleShadingEnable = 0;
7333 pipe_ms_state_ci.minSampleShading = 1.0;
7334 pipe_ms_state_ci.pSampleMask = NULL;
7335
Tobin Ehlise68360f2015-10-01 11:15:13 -06007336 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007337 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7338 pipeline_layout_ci.setLayoutCount = 1;
7339 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007340
7341 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007342 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007343 ASSERT_VK_SUCCESS(err);
7344
7345 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7346 // Set scissor as dynamic to avoid second error
7347 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007348 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7349 dyn_state_ci.dynamicStateCount = 1;
7350 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007351
Cody Northropeb3a6c12015-10-05 14:44:45 -06007352 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007353 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007354
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007355 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007356 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7357 // 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 +08007358 shaderStages[0] = vs.GetStageCreateInfo();
7359 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007360
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007361 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7362 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7363 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7364 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7365 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7366 rs_state_ci.depthClampEnable = VK_FALSE;
7367 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7368 rs_state_ci.depthBiasEnable = VK_FALSE;
7369
Tobin Ehlise68360f2015-10-01 11:15:13 -06007370 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007371 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7372 gp_ci.stageCount = 2;
7373 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007374 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007375 // Not setting VP state w/o dynamic vp state should cause validation error
7376 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007377 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007378 gp_ci.pVertexInputState = &vi_ci;
7379 gp_ci.pInputAssemblyState = &ia_ci;
7380 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007381 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7382 gp_ci.layout = pipeline_layout;
7383 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007384
7385 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007386 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007387
7388 VkPipeline pipeline;
7389 VkPipelineCache pipelineCache;
7390
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007391 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007392 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007393 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007394
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007395 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007396
Chia-I Wuf7458c52015-10-26 21:10:41 +08007397 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7398 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7399 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7400 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007401}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007402
7403// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7404// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007405TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7406 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007407
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007409
Tobin Ehlise68360f2015-10-01 11:15:13 -06007410 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007411
7412 if (!m_device->phy().features().multiViewport) {
7413 printf("Device does not support multiple viewports/scissors; skipped.\n");
7414 return;
7415 }
7416
Tobin Ehlise68360f2015-10-01 11:15:13 -06007417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007418
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007419 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007420 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7421 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007422
7423 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007424 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7425 ds_pool_ci.maxSets = 1;
7426 ds_pool_ci.poolSizeCount = 1;
7427 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007428
7429 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007430 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007431 ASSERT_VK_SUCCESS(err);
7432
7433 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007434 dsl_binding.binding = 0;
7435 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7436 dsl_binding.descriptorCount = 1;
7437 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007438
7439 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007440 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7441 ds_layout_ci.bindingCount = 1;
7442 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007443
7444 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007445 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007446 ASSERT_VK_SUCCESS(err);
7447
7448 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007449 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007450 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007451 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007452 alloc_info.descriptorPool = ds_pool;
7453 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007454 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007455 ASSERT_VK_SUCCESS(err);
7456
7457 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007458 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7459 pipeline_layout_ci.setLayoutCount = 1;
7460 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007461
7462 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007463 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007464 ASSERT_VK_SUCCESS(err);
7465
7466 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007467 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7468 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007469 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007470 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007471 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007472
7473 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7474 // Set scissor as dynamic to avoid that error
7475 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007476 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7477 dyn_state_ci.dynamicStateCount = 1;
7478 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007479
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007480 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7481 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7482 pipe_ms_state_ci.pNext = NULL;
7483 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7484 pipe_ms_state_ci.sampleShadingEnable = 0;
7485 pipe_ms_state_ci.minSampleShading = 1.0;
7486 pipe_ms_state_ci.pSampleMask = NULL;
7487
Cody Northropeb3a6c12015-10-05 14:44:45 -06007488 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007489 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007490
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007491 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007492 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7493 // 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 +08007494 shaderStages[0] = vs.GetStageCreateInfo();
7495 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007496
Cody Northropf6622dc2015-10-06 10:33:21 -06007497 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7498 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7499 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007500 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007501 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007502 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007503 vi_ci.pVertexAttributeDescriptions = nullptr;
7504
7505 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7506 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7507 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7508
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007509 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007510 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007511 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007512 rs_ci.pNext = nullptr;
7513
Mark Youngc89c6312016-03-31 16:03:20 -06007514 VkPipelineColorBlendAttachmentState att = {};
7515 att.blendEnable = VK_FALSE;
7516 att.colorWriteMask = 0xf;
7517
Cody Northropf6622dc2015-10-06 10:33:21 -06007518 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7519 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7520 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007521 cb_ci.attachmentCount = 1;
7522 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007523
Tobin Ehlise68360f2015-10-01 11:15:13 -06007524 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007525 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7526 gp_ci.stageCount = 2;
7527 gp_ci.pStages = shaderStages;
7528 gp_ci.pVertexInputState = &vi_ci;
7529 gp_ci.pInputAssemblyState = &ia_ci;
7530 gp_ci.pViewportState = &vp_state_ci;
7531 gp_ci.pRasterizationState = &rs_ci;
7532 gp_ci.pColorBlendState = &cb_ci;
7533 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007534 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007535 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7536 gp_ci.layout = pipeline_layout;
7537 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007538
7539 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007540 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007541
7542 VkPipeline pipeline;
7543 VkPipelineCache pipelineCache;
7544
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007545 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007546 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007547 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007548
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007549 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007550
Tobin Ehlisd332f282015-10-02 11:00:56 -06007551 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007552 // First need to successfully create the PSO from above by setting
7553 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007554 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 -07007555
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007556 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07007557 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007558 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007559 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007560 m_commandBuffer->BeginCommandBuffer();
7561 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007562 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007563 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007564 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007565 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007566 Draw(1, 0, 0, 0);
7567
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007568 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007569
7570 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7571 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7572 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7573 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007574 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007575}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007576
7577// 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 -07007578// viewportCount
7579TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7580 VkResult err;
7581
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007583
7584 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007585
7586 if (!m_device->phy().features().multiViewport) {
7587 printf("Device does not support multiple viewports/scissors; skipped.\n");
7588 return;
7589 }
7590
Karl Schultz6addd812016-02-02 17:17:23 -07007591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7592
7593 VkDescriptorPoolSize ds_type_count = {};
7594 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7595 ds_type_count.descriptorCount = 1;
7596
7597 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7598 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7599 ds_pool_ci.maxSets = 1;
7600 ds_pool_ci.poolSizeCount = 1;
7601 ds_pool_ci.pPoolSizes = &ds_type_count;
7602
7603 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007604 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007605 ASSERT_VK_SUCCESS(err);
7606
7607 VkDescriptorSetLayoutBinding dsl_binding = {};
7608 dsl_binding.binding = 0;
7609 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7610 dsl_binding.descriptorCount = 1;
7611 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7612
7613 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7614 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7615 ds_layout_ci.bindingCount = 1;
7616 ds_layout_ci.pBindings = &dsl_binding;
7617
7618 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007619 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007620 ASSERT_VK_SUCCESS(err);
7621
7622 VkDescriptorSet descriptorSet;
7623 VkDescriptorSetAllocateInfo alloc_info = {};
7624 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7625 alloc_info.descriptorSetCount = 1;
7626 alloc_info.descriptorPool = ds_pool;
7627 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007628 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007629 ASSERT_VK_SUCCESS(err);
7630
7631 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7632 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7633 pipeline_layout_ci.setLayoutCount = 1;
7634 pipeline_layout_ci.pSetLayouts = &ds_layout;
7635
7636 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007637 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007638 ASSERT_VK_SUCCESS(err);
7639
7640 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7641 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7642 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007643 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007644 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007645 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007646
7647 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7648 // Set scissor as dynamic to avoid that error
7649 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7650 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7651 dyn_state_ci.dynamicStateCount = 1;
7652 dyn_state_ci.pDynamicStates = &vp_state;
7653
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007654 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7655 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7656 pipe_ms_state_ci.pNext = NULL;
7657 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7658 pipe_ms_state_ci.sampleShadingEnable = 0;
7659 pipe_ms_state_ci.minSampleShading = 1.0;
7660 pipe_ms_state_ci.pSampleMask = NULL;
7661
Karl Schultz6addd812016-02-02 17:17:23 -07007662 VkPipelineShaderStageCreateInfo shaderStages[2];
7663 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7664
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007665 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007666 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7667 // 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 -07007668 shaderStages[0] = vs.GetStageCreateInfo();
7669 shaderStages[1] = fs.GetStageCreateInfo();
7670
7671 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7672 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7673 vi_ci.pNext = nullptr;
7674 vi_ci.vertexBindingDescriptionCount = 0;
7675 vi_ci.pVertexBindingDescriptions = nullptr;
7676 vi_ci.vertexAttributeDescriptionCount = 0;
7677 vi_ci.pVertexAttributeDescriptions = nullptr;
7678
7679 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7680 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7681 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7682
7683 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7684 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007685 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007686 rs_ci.pNext = nullptr;
7687
Mark Youngc89c6312016-03-31 16:03:20 -06007688 VkPipelineColorBlendAttachmentState att = {};
7689 att.blendEnable = VK_FALSE;
7690 att.colorWriteMask = 0xf;
7691
Karl Schultz6addd812016-02-02 17:17:23 -07007692 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7693 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7694 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007695 cb_ci.attachmentCount = 1;
7696 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007697
7698 VkGraphicsPipelineCreateInfo gp_ci = {};
7699 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7700 gp_ci.stageCount = 2;
7701 gp_ci.pStages = shaderStages;
7702 gp_ci.pVertexInputState = &vi_ci;
7703 gp_ci.pInputAssemblyState = &ia_ci;
7704 gp_ci.pViewportState = &vp_state_ci;
7705 gp_ci.pRasterizationState = &rs_ci;
7706 gp_ci.pColorBlendState = &cb_ci;
7707 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007708 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007709 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7710 gp_ci.layout = pipeline_layout;
7711 gp_ci.renderPass = renderPass();
7712
7713 VkPipelineCacheCreateInfo pc_ci = {};
7714 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7715
7716 VkPipeline pipeline;
7717 VkPipelineCache pipelineCache;
7718
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007719 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007720 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007721 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007722
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007723 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007724
7725 // Now hit second fail case where we set scissor w/ different count than PSO
7726 // First need to successfully create the PSO from above by setting
7727 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7729 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007730
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007731 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06007732 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007733 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007734 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007735 m_commandBuffer->BeginCommandBuffer();
7736 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007737 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007738 VkViewport viewports[1] = {};
7739 viewports[0].width = 8;
7740 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007741 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007742 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007743 Draw(1, 0, 0, 0);
7744
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007745 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007746
Chia-I Wuf7458c52015-10-26 21:10:41 +08007747 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7748 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7749 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7750 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007751 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007752}
7753
Mark Young7394fdd2016-03-31 14:56:43 -06007754TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7755 VkResult err;
7756
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007758
7759 ASSERT_NO_FATAL_FAILURE(InitState());
7760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7761
7762 VkDescriptorPoolSize ds_type_count = {};
7763 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7764 ds_type_count.descriptorCount = 1;
7765
7766 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7767 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7768 ds_pool_ci.maxSets = 1;
7769 ds_pool_ci.poolSizeCount = 1;
7770 ds_pool_ci.pPoolSizes = &ds_type_count;
7771
7772 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007773 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007774 ASSERT_VK_SUCCESS(err);
7775
7776 VkDescriptorSetLayoutBinding dsl_binding = {};
7777 dsl_binding.binding = 0;
7778 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7779 dsl_binding.descriptorCount = 1;
7780 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7781
7782 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7783 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7784 ds_layout_ci.bindingCount = 1;
7785 ds_layout_ci.pBindings = &dsl_binding;
7786
7787 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007788 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007789 ASSERT_VK_SUCCESS(err);
7790
7791 VkDescriptorSet descriptorSet;
7792 VkDescriptorSetAllocateInfo alloc_info = {};
7793 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7794 alloc_info.descriptorSetCount = 1;
7795 alloc_info.descriptorPool = ds_pool;
7796 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007797 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007798 ASSERT_VK_SUCCESS(err);
7799
7800 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7801 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7802 pipeline_layout_ci.setLayoutCount = 1;
7803 pipeline_layout_ci.pSetLayouts = &ds_layout;
7804
7805 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007806 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007807 ASSERT_VK_SUCCESS(err);
7808
7809 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7810 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7811 vp_state_ci.scissorCount = 1;
7812 vp_state_ci.pScissors = NULL;
7813 vp_state_ci.viewportCount = 1;
7814 vp_state_ci.pViewports = NULL;
7815
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007816 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007817 // Set scissor as dynamic to avoid that error
7818 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7819 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7820 dyn_state_ci.dynamicStateCount = 2;
7821 dyn_state_ci.pDynamicStates = dynamic_states;
7822
7823 VkPipelineShaderStageCreateInfo shaderStages[2];
7824 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7825
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007826 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7827 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007828 this); // TODO - We shouldn't need a fragment shader
7829 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06007830 shaderStages[0] = vs.GetStageCreateInfo();
7831 shaderStages[1] = fs.GetStageCreateInfo();
7832
7833 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7834 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7835 vi_ci.pNext = nullptr;
7836 vi_ci.vertexBindingDescriptionCount = 0;
7837 vi_ci.pVertexBindingDescriptions = nullptr;
7838 vi_ci.vertexAttributeDescriptionCount = 0;
7839 vi_ci.pVertexAttributeDescriptions = nullptr;
7840
7841 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7842 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7843 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7844
7845 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7846 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7847 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07007848 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06007849
Mark Young47107952016-05-02 15:59:55 -06007850 // Check too low (line width of -1.0f).
7851 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007852
7853 VkPipelineColorBlendAttachmentState att = {};
7854 att.blendEnable = VK_FALSE;
7855 att.colorWriteMask = 0xf;
7856
7857 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7858 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7859 cb_ci.pNext = nullptr;
7860 cb_ci.attachmentCount = 1;
7861 cb_ci.pAttachments = &att;
7862
7863 VkGraphicsPipelineCreateInfo gp_ci = {};
7864 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7865 gp_ci.stageCount = 2;
7866 gp_ci.pStages = shaderStages;
7867 gp_ci.pVertexInputState = &vi_ci;
7868 gp_ci.pInputAssemblyState = &ia_ci;
7869 gp_ci.pViewportState = &vp_state_ci;
7870 gp_ci.pRasterizationState = &rs_ci;
7871 gp_ci.pColorBlendState = &cb_ci;
7872 gp_ci.pDynamicState = &dyn_state_ci;
7873 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7874 gp_ci.layout = pipeline_layout;
7875 gp_ci.renderPass = renderPass();
7876
7877 VkPipelineCacheCreateInfo pc_ci = {};
7878 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7879
7880 VkPipeline pipeline;
7881 VkPipelineCache pipelineCache;
7882
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007883 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007884 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007885 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007886
7887 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007888 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007891
7892 // Check too high (line width of 65536.0f).
7893 rs_ci.lineWidth = 65536.0f;
7894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007895 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007896 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007897 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007898
7899 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007900 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007903
7904 dyn_state_ci.dynamicStateCount = 3;
7905
7906 rs_ci.lineWidth = 1.0f;
7907
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007908 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007909 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007910 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07007911 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007913
7914 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007915 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007916 m_errorMonitor->VerifyFound();
7917
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007919
7920 // Check too high with dynamic setting.
7921 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
7922 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07007923 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06007924
7925 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7926 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007929 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007930}
7931
Karl Schultz6addd812016-02-02 17:17:23 -07007932TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007933 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07007935 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007936
7937 ASSERT_NO_FATAL_FAILURE(InitState());
7938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007939
Tony Barbour552f6c02016-12-21 14:34:07 -07007940 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07007941 // Don't care about RenderPass handle b/c error should be flagged before
7942 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007943 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007944
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007945 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06007946}
7947
Karl Schultz6addd812016-02-02 17:17:23 -07007948TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007949 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7951 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007952
7953 ASSERT_NO_FATAL_FAILURE(InitState());
7954 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007955
Tony Barbour552f6c02016-12-21 14:34:07 -07007956 m_commandBuffer->BeginCommandBuffer();
7957 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07007958 // Just create a dummy Renderpass that's non-NULL so we can get to the
7959 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007961
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007962 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06007963}
7964
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007965TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007966 TEST_DESCRIPTION(
7967 "Begin a renderPass where clearValueCount is less than"
7968 "the number of renderPass attachments that use loadOp"
7969 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06007970
7971 ASSERT_NO_FATAL_FAILURE(InitState());
7972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7973
7974 // Create a renderPass with a single attachment that uses loadOp CLEAR
7975 VkAttachmentReference attach = {};
7976 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
7977 VkSubpassDescription subpass = {};
7978 subpass.inputAttachmentCount = 1;
7979 subpass.pInputAttachments = &attach;
7980 VkRenderPassCreateInfo rpci = {};
7981 rpci.subpassCount = 1;
7982 rpci.pSubpasses = &subpass;
7983 rpci.attachmentCount = 1;
7984 VkAttachmentDescription attach_desc = {};
7985 attach_desc.format = VK_FORMAT_UNDEFINED;
7986 // Set loadOp to CLEAR
7987 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
7988 rpci.pAttachments = &attach_desc;
7989 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
7990 VkRenderPass rp;
7991 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
7992
7993 VkCommandBufferInheritanceInfo hinfo = {};
7994 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7995 hinfo.renderPass = VK_NULL_HANDLE;
7996 hinfo.subpass = 0;
7997 hinfo.framebuffer = VK_NULL_HANDLE;
7998 hinfo.occlusionQueryEnable = VK_FALSE;
7999 hinfo.queryFlags = 0;
8000 hinfo.pipelineStatistics = 0;
8001 VkCommandBufferBeginInfo info = {};
8002 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8003 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8004 info.pInheritanceInfo = &hinfo;
8005
8006 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8007 VkRenderPassBeginInfo rp_begin = {};
8008 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8009 rp_begin.pNext = NULL;
8010 rp_begin.renderPass = renderPass();
8011 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008012 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008013
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008015
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008016 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008017
8018 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008019
8020 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008021}
8022
Slawomir Cygan0808f392016-11-28 17:53:23 +01008023TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008024 TEST_DESCRIPTION(
8025 "Begin a renderPass where clearValueCount is greater than"
8026 "the number of renderPass attachments that use loadOp"
8027 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008028
8029 ASSERT_NO_FATAL_FAILURE(InitState());
8030 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8031
8032 // Create a renderPass with a single attachment that uses loadOp CLEAR
8033 VkAttachmentReference attach = {};
8034 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8035 VkSubpassDescription subpass = {};
8036 subpass.inputAttachmentCount = 1;
8037 subpass.pInputAttachments = &attach;
8038 VkRenderPassCreateInfo rpci = {};
8039 rpci.subpassCount = 1;
8040 rpci.pSubpasses = &subpass;
8041 rpci.attachmentCount = 1;
8042 VkAttachmentDescription attach_desc = {};
8043 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8044 // Set loadOp to CLEAR
8045 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8046 rpci.pAttachments = &attach_desc;
8047 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8048 VkRenderPass rp;
8049 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8050
8051 VkCommandBufferBeginInfo info = {};
8052 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8053 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8054
8055 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8056 VkRenderPassBeginInfo rp_begin = {};
8057 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8058 rp_begin.pNext = NULL;
8059 rp_begin.renderPass = renderPass();
8060 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008061 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008062
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8064 " has a clearValueCount of"
8065 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008066
8067 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8068
8069 m_errorMonitor->VerifyFound();
8070
8071 vkDestroyRenderPass(m_device->device(), rp, NULL);
8072}
8073
Cody Northrop3bb4d962016-05-09 16:15:57 -06008074TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008075 TEST_DESCRIPTION("End a command buffer with an active render pass");
8076
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8078 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008079
8080 ASSERT_NO_FATAL_FAILURE(InitState());
8081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8082
Tony Barbour552f6c02016-12-21 14:34:07 -07008083 m_commandBuffer->BeginCommandBuffer();
8084 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8085 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008086
8087 m_errorMonitor->VerifyFound();
8088
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008089 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8090 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008091}
8092
Karl Schultz6addd812016-02-02 17:17:23 -07008093TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008094 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8096 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008097
8098 ASSERT_NO_FATAL_FAILURE(InitState());
8099 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008100
Tony Barbour552f6c02016-12-21 14:34:07 -07008101 m_commandBuffer->BeginCommandBuffer();
8102 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008103
8104 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008105 vk_testing::Buffer dstBuffer;
8106 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008107
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008108 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008109
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008110 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008111}
8112
Karl Schultz6addd812016-02-02 17:17:23 -07008113TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008114 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8116 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008117
8118 ASSERT_NO_FATAL_FAILURE(InitState());
8119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008120
Tony Barbour552f6c02016-12-21 14:34:07 -07008121 m_commandBuffer->BeginCommandBuffer();
8122 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008123
8124 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008125 vk_testing::Buffer dstBuffer;
8126 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008127
Karl Schultz6addd812016-02-02 17:17:23 -07008128 VkDeviceSize dstOffset = 0;
8129 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008130 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008131
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008132 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008133
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008134 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008135}
8136
Karl Schultz6addd812016-02-02 17:17:23 -07008137TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008138 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8140 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008141
8142 ASSERT_NO_FATAL_FAILURE(InitState());
8143 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008144
Tony Barbour552f6c02016-12-21 14:34:07 -07008145 m_commandBuffer->BeginCommandBuffer();
8146 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008147
Michael Lentine0a369f62016-02-03 16:51:46 -06008148 VkClearColorValue clear_color;
8149 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008150 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8151 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8152 const int32_t tex_width = 32;
8153 const int32_t tex_height = 32;
8154 VkImageCreateInfo image_create_info = {};
8155 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8156 image_create_info.pNext = NULL;
8157 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8158 image_create_info.format = tex_format;
8159 image_create_info.extent.width = tex_width;
8160 image_create_info.extent.height = tex_height;
8161 image_create_info.extent.depth = 1;
8162 image_create_info.mipLevels = 1;
8163 image_create_info.arrayLayers = 1;
8164 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8165 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8166 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008167
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008168 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008169 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008170
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008171 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008172
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008174
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008175 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008176}
8177
Karl Schultz6addd812016-02-02 17:17:23 -07008178TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008179 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8181 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008182
8183 ASSERT_NO_FATAL_FAILURE(InitState());
8184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008185
Tony Barbour552f6c02016-12-21 14:34:07 -07008186 m_commandBuffer->BeginCommandBuffer();
8187 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008188
8189 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008190 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008191 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8192 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8193 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8194 image_create_info.extent.width = 64;
8195 image_create_info.extent.height = 64;
8196 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8197 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008198
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008199 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008200 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008201
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008202 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008203
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008204 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8205 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008206
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008207 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008208}
8209
Karl Schultz6addd812016-02-02 17:17:23 -07008210TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008211 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008212 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008213
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8215 "vkCmdClearAttachments(): This call "
8216 "must be issued inside an active "
8217 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008218
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008219 ASSERT_NO_FATAL_FAILURE(InitState());
8220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008221
8222 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008223 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008224 ASSERT_VK_SUCCESS(err);
8225
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008226 VkClearAttachment color_attachment;
8227 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8228 color_attachment.clearValue.color.float32[0] = 0;
8229 color_attachment.clearValue.color.float32[1] = 0;
8230 color_attachment.clearValue.color.float32[2] = 0;
8231 color_attachment.clearValue.color.float32[3] = 0;
8232 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008233 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008234 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008235
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008236 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008237}
8238
Chris Forbes3b97e932016-09-07 11:29:24 +12008239TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008240 TEST_DESCRIPTION(
8241 "Test that an error is produced when CmdNextSubpass is "
8242 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008243
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8245 "vkCmdNextSubpass(): Attempted to advance "
8246 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008247
8248 ASSERT_NO_FATAL_FAILURE(InitState());
8249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8250
Tony Barbour552f6c02016-12-21 14:34:07 -07008251 m_commandBuffer->BeginCommandBuffer();
8252 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008253
8254 // error here.
8255 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8256 m_errorMonitor->VerifyFound();
8257
Tony Barbour552f6c02016-12-21 14:34:07 -07008258 m_commandBuffer->EndRenderPass();
8259 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008260}
8261
Chris Forbes6d624702016-09-07 13:57:05 +12008262TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008263 TEST_DESCRIPTION(
8264 "Test that an error is produced when CmdEndRenderPass is "
8265 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008266
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8268 "vkCmdEndRenderPass(): Called before reaching "
8269 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008270
8271 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008272 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8273 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008274
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008275 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008276
8277 VkRenderPass rp;
8278 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8279 ASSERT_VK_SUCCESS(err);
8280
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008281 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008282
8283 VkFramebuffer fb;
8284 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8285 ASSERT_VK_SUCCESS(err);
8286
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008287 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008289 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 +12008290
8291 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8292
8293 // Error here.
8294 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8295 m_errorMonitor->VerifyFound();
8296
8297 // Clean up.
8298 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8299 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8300}
8301
Karl Schultz9e66a292016-04-21 15:57:51 -06008302TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8303 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8305 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008306
8307 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008308 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008309
8310 VkBufferMemoryBarrier buf_barrier = {};
8311 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8312 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8313 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8314 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8315 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8316 buf_barrier.buffer = VK_NULL_HANDLE;
8317 buf_barrier.offset = 0;
8318 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008319 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8320 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008321
8322 m_errorMonitor->VerifyFound();
8323}
8324
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008325TEST_F(VkLayerTest, InvalidBarriers) {
8326 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8327
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008329
8330 ASSERT_NO_FATAL_FAILURE(InitState());
8331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8332
8333 VkMemoryBarrier mem_barrier = {};
8334 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8335 mem_barrier.pNext = NULL;
8336 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8337 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008338 m_commandBuffer->BeginCommandBuffer();
8339 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008340 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008342 &mem_barrier, 0, nullptr, 0, nullptr);
8343 m_errorMonitor->VerifyFound();
8344
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008346 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008347 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 -06008348 ASSERT_TRUE(image.initialized());
8349 VkImageMemoryBarrier img_barrier = {};
8350 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8351 img_barrier.pNext = NULL;
8352 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8353 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8354 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8355 // New layout can't be UNDEFINED
8356 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8357 img_barrier.image = image.handle();
8358 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8359 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8360 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8361 img_barrier.subresourceRange.baseArrayLayer = 0;
8362 img_barrier.subresourceRange.baseMipLevel = 0;
8363 img_barrier.subresourceRange.layerCount = 1;
8364 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008365 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8366 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008367 m_errorMonitor->VerifyFound();
8368 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8369
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8371 "Subresource must have the sum of the "
8372 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008373 // baseArrayLayer + layerCount must be <= image's arrayLayers
8374 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008375 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8376 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008377 m_errorMonitor->VerifyFound();
8378 img_barrier.subresourceRange.baseArrayLayer = 0;
8379
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008381 // baseMipLevel + levelCount must be <= image's mipLevels
8382 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008383 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8384 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008385 m_errorMonitor->VerifyFound();
8386 img_barrier.subresourceRange.baseMipLevel = 0;
8387
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008388 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 -06008389 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008390 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8391 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008392 VkBufferMemoryBarrier buf_barrier = {};
8393 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8394 buf_barrier.pNext = NULL;
8395 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8396 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8397 buf_barrier.buffer = buffer.handle();
8398 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8399 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8400 buf_barrier.offset = 0;
8401 buf_barrier.size = VK_WHOLE_SIZE;
8402 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008403 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8404 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008405 m_errorMonitor->VerifyFound();
8406 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8407
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008409 buf_barrier.offset = 257;
8410 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008411 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8412 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008413 m_errorMonitor->VerifyFound();
8414 buf_barrier.offset = 0;
8415
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008417 buf_barrier.size = 257;
8418 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008419 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8420 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008421 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008422
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008423 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008424 m_errorMonitor->SetDesiredFailureMsg(
8425 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008426 "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 -06008427 VkDepthStencilObj ds_image(m_device);
8428 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8429 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008430 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8431 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008432 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008433
8434 // Not having DEPTH or STENCIL set is an error
8435 img_barrier.subresourceRange.aspectMask = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008436 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8437 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008438 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07008439
8440 // Having anything other than DEPTH or STENCIL is an error
8441 m_errorMonitor->SetDesiredFailureMsg(
8442 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8443 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8444 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
8445 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8446 nullptr, 0, nullptr, 1, &img_barrier);
8447 m_errorMonitor->VerifyFound();
8448
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008449 // Now test depth-only
8450 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008451 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8452 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008453 VkDepthStencilObj d_image(m_device);
8454 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8455 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008456 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008457 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008458 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008459
8460 // DEPTH bit must be set
8461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8462 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8463 img_barrier.subresourceRange.aspectMask = 0;
8464 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8465 0, nullptr, 0, nullptr, 1, &img_barrier);
8466 m_errorMonitor->VerifyFound();
8467
8468 // No bits other than DEPTH may be set
8469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8470 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8471 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008472 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8473 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008474 m_errorMonitor->VerifyFound();
8475 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008476
8477 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008478 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8479 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8481 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008482 VkDepthStencilObj s_image(m_device);
8483 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8484 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008485 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008486 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008487 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008488 // Use of COLOR aspect on depth image is error
8489 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008490 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8491 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008492 m_errorMonitor->VerifyFound();
8493 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008494
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008495 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008496 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008497 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 -06008498 ASSERT_TRUE(c_image.initialized());
8499 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8500 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8501 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008502
8503 // COLOR bit must be set
8504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8505 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8506 img_barrier.subresourceRange.aspectMask = 0;
8507 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8508 nullptr, 0, nullptr, 1, &img_barrier);
8509 m_errorMonitor->VerifyFound();
8510
8511 // No bits other than COLOR may be set
8512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8513 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
8514 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008515 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8516 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008517 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008518
8519 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8520
8521 // Create command pool with incompatible queueflags
8522 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8523 uint32_t queue_family_index = UINT32_MAX;
8524 for (uint32_t i = 0; i < queue_props.size(); i++) {
8525 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8526 queue_family_index = i;
8527 break;
8528 }
8529 }
8530 if (queue_family_index == UINT32_MAX) {
8531 printf("No non-compute queue found; skipped.\n");
8532 return;
8533 }
8534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8535
8536 VkCommandPool command_pool;
8537 VkCommandPoolCreateInfo pool_create_info{};
8538 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8539 pool_create_info.queueFamilyIndex = queue_family_index;
8540 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8541 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8542
8543 // Allocate a command buffer
8544 VkCommandBuffer bad_command_buffer;
8545 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8546 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8547 command_buffer_allocate_info.commandPool = command_pool;
8548 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8549 command_buffer_allocate_info.commandBufferCount = 1;
8550 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8551
8552 VkCommandBufferBeginInfo cbbi = {};
8553 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8554 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8555 buf_barrier.offset = 0;
8556 buf_barrier.size = VK_WHOLE_SIZE;
8557 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8558 &buf_barrier, 0, nullptr);
8559 m_errorMonitor->VerifyFound();
8560
8561 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8562 vkEndCommandBuffer(bad_command_buffer);
8563 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8564 printf("The non-compute queue does not support graphics; skipped.\n");
8565 return;
8566 }
8567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8568 VkEvent event;
8569 VkEventCreateInfo event_create_info{};
8570 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8571 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8572 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8573 nullptr, 0, nullptr);
8574 m_errorMonitor->VerifyFound();
8575
8576 vkEndCommandBuffer(bad_command_buffer);
8577 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008578}
8579
Tony Barbour18ba25c2016-09-29 13:42:40 -06008580TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8581 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8582
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06008584 ASSERT_NO_FATAL_FAILURE(InitState());
8585 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008586 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 -06008587 ASSERT_TRUE(image.initialized());
8588
8589 VkImageMemoryBarrier barrier = {};
8590 VkImageSubresourceRange range;
8591 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8592 barrier.srcAccessMask = 0;
8593 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8594 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8595 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8596 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8597 barrier.image = image.handle();
8598 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8599 range.baseMipLevel = 0;
8600 range.levelCount = 1;
8601 range.baseArrayLayer = 0;
8602 range.layerCount = 1;
8603 barrier.subresourceRange = range;
8604 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8605 cmdbuf.BeginCommandBuffer();
8606 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8607 &barrier);
8608 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8609 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8610 barrier.srcAccessMask = 0;
8611 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8612 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8613 &barrier);
8614
8615 m_errorMonitor->VerifyFound();
8616}
8617
Karl Schultz6addd812016-02-02 17:17:23 -07008618TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008619 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008620 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008621
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008623
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008624 ASSERT_NO_FATAL_FAILURE(InitState());
8625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008626 uint32_t qfi = 0;
8627 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008628 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8629 buffCI.size = 1024;
8630 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8631 buffCI.queueFamilyIndexCount = 1;
8632 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008633
8634 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008635 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008636 ASSERT_VK_SUCCESS(err);
8637
Tony Barbour552f6c02016-12-21 14:34:07 -07008638 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008639 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008640 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8641 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008642 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008643 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008644
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008645 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008646
Chia-I Wuf7458c52015-10-26 21:10:41 +08008647 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008648}
8649
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008650TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8651 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008652 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8653 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8654 "of the indices specified when the device was created, via the "
8655 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008656
8657 ASSERT_NO_FATAL_FAILURE(InitState());
8658 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8659 VkBufferCreateInfo buffCI = {};
8660 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8661 buffCI.size = 1024;
8662 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8663 buffCI.queueFamilyIndexCount = 1;
8664 // Introduce failure by specifying invalid queue_family_index
8665 uint32_t qfi = 777;
8666 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008667 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008668
8669 VkBuffer ib;
8670 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8671
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008672 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008673 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008674}
8675
Karl Schultz6addd812016-02-02 17:17:23 -07008676TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008677 TEST_DESCRIPTION(
8678 "Attempt vkCmdExecuteCommands with a primary command buffer"
8679 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008680
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008681 ASSERT_NO_FATAL_FAILURE(InitState());
8682 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008683
Chris Forbesf29a84f2016-10-06 18:39:28 +13008684 // An empty primary command buffer
8685 VkCommandBufferObj cb(m_device, m_commandPool);
8686 cb.BeginCommandBuffer();
8687 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008688
Chris Forbesf29a84f2016-10-06 18:39:28 +13008689 m_commandBuffer->BeginCommandBuffer();
8690 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8691 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008692
Chris Forbesf29a84f2016-10-06 18:39:28 +13008693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8694 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008695 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008696}
8697
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008698TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008699 TEST_DESCRIPTION(
8700 "Attempt to update descriptor sets for images and buffers "
8701 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008702 VkResult err;
8703
8704 ASSERT_NO_FATAL_FAILURE(InitState());
8705 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8706 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8707 ds_type_count[i].type = VkDescriptorType(i);
8708 ds_type_count[i].descriptorCount = 1;
8709 }
8710 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8711 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8712 ds_pool_ci.pNext = NULL;
8713 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8714 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8715 ds_pool_ci.pPoolSizes = ds_type_count;
8716
8717 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008718 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008719 ASSERT_VK_SUCCESS(err);
8720
8721 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008722 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008723 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8724 dsl_binding[i].binding = 0;
8725 dsl_binding[i].descriptorType = VkDescriptorType(i);
8726 dsl_binding[i].descriptorCount = 1;
8727 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8728 dsl_binding[i].pImmutableSamplers = NULL;
8729 }
8730
8731 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8732 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8733 ds_layout_ci.pNext = NULL;
8734 ds_layout_ci.bindingCount = 1;
8735 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8736 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8737 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008739 ASSERT_VK_SUCCESS(err);
8740 }
8741 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8742 VkDescriptorSetAllocateInfo alloc_info = {};
8743 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8744 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8745 alloc_info.descriptorPool = ds_pool;
8746 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008747 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008748 ASSERT_VK_SUCCESS(err);
8749
8750 // Create a buffer & bufferView to be used for invalid updates
8751 VkBufferCreateInfo buff_ci = {};
8752 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07008753 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008754 buff_ci.size = 256;
8755 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07008756 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008757 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8758 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07008759
8760 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
8761 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
8762 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
8763 ASSERT_VK_SUCCESS(err);
8764
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008765 VkMemoryRequirements mem_reqs;
8766 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8767 VkMemoryAllocateInfo mem_alloc_info = {};
8768 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8769 mem_alloc_info.pNext = NULL;
8770 mem_alloc_info.memoryTypeIndex = 0;
8771 mem_alloc_info.allocationSize = mem_reqs.size;
8772 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8773 if (!pass) {
8774 vkDestroyBuffer(m_device->device(), buffer, NULL);
8775 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8776 return;
8777 }
8778 VkDeviceMemory mem;
8779 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
8780 ASSERT_VK_SUCCESS(err);
8781 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8782 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008783
8784 VkBufferViewCreateInfo buff_view_ci = {};
8785 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8786 buff_view_ci.buffer = buffer;
8787 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8788 buff_view_ci.range = VK_WHOLE_SIZE;
8789 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008790 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008791 ASSERT_VK_SUCCESS(err);
8792
Tony Barbour415497c2017-01-24 10:06:09 -07008793 // Now get resources / view for storage_texel_buffer
8794 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
8795 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8796 if (!pass) {
8797 vkDestroyBuffer(m_device->device(), buffer, NULL);
8798 vkDestroyBufferView(m_device->device(), buff_view, NULL);
8799 vkFreeMemory(m_device->device(), mem, NULL);
8800 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
8801 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8802 return;
8803 }
8804 VkDeviceMemory storage_texel_buffer_mem;
8805 VkBufferView storage_texel_buffer_view;
8806 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
8807 ASSERT_VK_SUCCESS(err);
8808 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
8809 ASSERT_VK_SUCCESS(err);
8810 buff_view_ci.buffer = storage_texel_buffer;
8811 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
8812 ASSERT_VK_SUCCESS(err);
8813
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008814 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07008815 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008816 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07008817 image_ci.format = VK_FORMAT_UNDEFINED;
8818 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
8819 VkFormat format = static_cast<VkFormat>(f);
8820 VkFormatProperties fProps = m_device->format_properties(format);
8821 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
8822 image_ci.format = format;
8823 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8824 break;
8825 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
8826 image_ci.format = format;
8827 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
8828 break;
8829 }
8830 }
8831 if (image_ci.format == VK_FORMAT_UNDEFINED) {
8832 return;
8833 }
8834
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008835 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8836 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008837 image_ci.extent.width = 64;
8838 image_ci.extent.height = 64;
8839 image_ci.extent.depth = 1;
8840 image_ci.mipLevels = 1;
8841 image_ci.arrayLayers = 1;
8842 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008843 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07008844 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008845 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8846 VkImage image;
8847 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8848 ASSERT_VK_SUCCESS(err);
8849 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008850 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008851
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008852 VkMemoryAllocateInfo mem_alloc = {};
8853 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8854 mem_alloc.pNext = NULL;
8855 mem_alloc.allocationSize = 0;
8856 mem_alloc.memoryTypeIndex = 0;
8857 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8858 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008859 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008860 ASSERT_TRUE(pass);
8861 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8862 ASSERT_VK_SUCCESS(err);
8863 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8864 ASSERT_VK_SUCCESS(err);
8865 // Now create view for image
8866 VkImageViewCreateInfo image_view_ci = {};
8867 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8868 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07008869 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008870 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8871 image_view_ci.subresourceRange.layerCount = 1;
8872 image_view_ci.subresourceRange.baseArrayLayer = 0;
8873 image_view_ci.subresourceRange.levelCount = 1;
8874 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8875 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008876 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008877 ASSERT_VK_SUCCESS(err);
8878
8879 VkDescriptorBufferInfo buff_info = {};
8880 buff_info.buffer = buffer;
8881 VkDescriptorImageInfo img_info = {};
8882 img_info.imageView = image_view;
8883 VkWriteDescriptorSet descriptor_write = {};
8884 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8885 descriptor_write.dstBinding = 0;
8886 descriptor_write.descriptorCount = 1;
8887 descriptor_write.pTexelBufferView = &buff_view;
8888 descriptor_write.pBufferInfo = &buff_info;
8889 descriptor_write.pImageInfo = &img_info;
8890
8891 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008892 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008893 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
8894 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
8895 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
8896 VALIDATION_ERROR_00943, // STORAGE_IMAGE
8897 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
8898 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
8899 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
8900 VALIDATION_ERROR_00947, // STORAGE_BUFFER
8901 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
8902 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
8903 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008904 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008905 // Start loop at 1 as SAMPLER desc type has no usage bit error
8906 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07008907 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
8908 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
8909 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
8910 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008911 descriptor_write.descriptorType = VkDescriptorType(i);
8912 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008915 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008916
8917 m_errorMonitor->VerifyFound();
8918 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008919 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
8920 descriptor_write.pTexelBufferView = &buff_view;
8921 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008922 }
Tony Barbour415497c2017-01-24 10:06:09 -07008923
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008924 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8925 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008926 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008927 vkDestroyImageView(m_device->device(), image_view, NULL);
8928 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008929 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008930 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008931 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008932 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07008933 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008934 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8935}
8936
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008937TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008938 TEST_DESCRIPTION(
8939 "Attempt to update buffer descriptor set that has incorrect "
8940 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8941 "1. offset value greater than buffer size\n"
8942 "2. range value of 0\n"
8943 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008944 VkResult err;
8945
8946 ASSERT_NO_FATAL_FAILURE(InitState());
8947 VkDescriptorPoolSize ds_type_count = {};
8948 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8949 ds_type_count.descriptorCount = 1;
8950
8951 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8952 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8953 ds_pool_ci.pNext = NULL;
8954 ds_pool_ci.maxSets = 1;
8955 ds_pool_ci.poolSizeCount = 1;
8956 ds_pool_ci.pPoolSizes = &ds_type_count;
8957
8958 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008959 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008960 ASSERT_VK_SUCCESS(err);
8961
8962 // Create layout with single uniform buffer descriptor
8963 VkDescriptorSetLayoutBinding dsl_binding = {};
8964 dsl_binding.binding = 0;
8965 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8966 dsl_binding.descriptorCount = 1;
8967 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8968 dsl_binding.pImmutableSamplers = NULL;
8969
8970 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8971 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8972 ds_layout_ci.pNext = NULL;
8973 ds_layout_ci.bindingCount = 1;
8974 ds_layout_ci.pBindings = &dsl_binding;
8975 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008977 ASSERT_VK_SUCCESS(err);
8978
8979 VkDescriptorSet descriptor_set = {};
8980 VkDescriptorSetAllocateInfo alloc_info = {};
8981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8982 alloc_info.descriptorSetCount = 1;
8983 alloc_info.descriptorPool = ds_pool;
8984 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008986 ASSERT_VK_SUCCESS(err);
8987
8988 // Create a buffer to be used for invalid updates
8989 VkBufferCreateInfo buff_ci = {};
8990 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8991 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
8992 buff_ci.size = 256;
8993 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8994 VkBuffer buffer;
8995 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8996 ASSERT_VK_SUCCESS(err);
8997 // Have to bind memory to buffer before descriptor update
8998 VkMemoryAllocateInfo mem_alloc = {};
8999 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9000 mem_alloc.pNext = NULL;
9001 mem_alloc.allocationSize = 256;
9002 mem_alloc.memoryTypeIndex = 0;
9003
9004 VkMemoryRequirements mem_reqs;
9005 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009006 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009007 if (!pass) {
9008 vkDestroyBuffer(m_device->device(), buffer, NULL);
9009 return;
9010 }
9011
9012 VkDeviceMemory mem;
9013 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9014 ASSERT_VK_SUCCESS(err);
9015 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9016 ASSERT_VK_SUCCESS(err);
9017
9018 VkDescriptorBufferInfo buff_info = {};
9019 buff_info.buffer = buffer;
9020 // First make offset 1 larger than buffer size
9021 buff_info.offset = 257;
9022 buff_info.range = VK_WHOLE_SIZE;
9023 VkWriteDescriptorSet descriptor_write = {};
9024 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9025 descriptor_write.dstBinding = 0;
9026 descriptor_write.descriptorCount = 1;
9027 descriptor_write.pTexelBufferView = nullptr;
9028 descriptor_write.pBufferInfo = &buff_info;
9029 descriptor_write.pImageInfo = nullptr;
9030
9031 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9032 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009034
9035 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9036
9037 m_errorMonitor->VerifyFound();
9038 // Now cause error due to range of 0
9039 buff_info.offset = 0;
9040 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009042
9043 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9044
9045 m_errorMonitor->VerifyFound();
9046 // Now cause error due to range exceeding buffer size - offset
9047 buff_info.offset = 128;
9048 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009050
9051 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9052
9053 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009054 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009055 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9056 vkDestroyBuffer(m_device->device(), buffer, NULL);
9057 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9058 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9059}
9060
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009061TEST_F(VkLayerTest, DSAspectBitsErrors) {
9062 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9063 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009064 TEST_DESCRIPTION(
9065 "Attempt to update descriptor sets for images "
9066 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009067 VkResult err;
9068
9069 ASSERT_NO_FATAL_FAILURE(InitState());
9070 VkDescriptorPoolSize ds_type_count = {};
9071 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9072 ds_type_count.descriptorCount = 1;
9073
9074 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9075 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9076 ds_pool_ci.pNext = NULL;
9077 ds_pool_ci.maxSets = 5;
9078 ds_pool_ci.poolSizeCount = 1;
9079 ds_pool_ci.pPoolSizes = &ds_type_count;
9080
9081 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009082 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009083 ASSERT_VK_SUCCESS(err);
9084
9085 VkDescriptorSetLayoutBinding dsl_binding = {};
9086 dsl_binding.binding = 0;
9087 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9088 dsl_binding.descriptorCount = 1;
9089 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9090 dsl_binding.pImmutableSamplers = NULL;
9091
9092 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9093 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9094 ds_layout_ci.pNext = NULL;
9095 ds_layout_ci.bindingCount = 1;
9096 ds_layout_ci.pBindings = &dsl_binding;
9097 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009098 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009099 ASSERT_VK_SUCCESS(err);
9100
9101 VkDescriptorSet descriptor_set = {};
9102 VkDescriptorSetAllocateInfo alloc_info = {};
9103 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9104 alloc_info.descriptorSetCount = 1;
9105 alloc_info.descriptorPool = ds_pool;
9106 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009107 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009108 ASSERT_VK_SUCCESS(err);
9109
9110 // Create an image to be used for invalid updates
9111 VkImageCreateInfo image_ci = {};
9112 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9113 image_ci.imageType = VK_IMAGE_TYPE_2D;
9114 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9115 image_ci.extent.width = 64;
9116 image_ci.extent.height = 64;
9117 image_ci.extent.depth = 1;
9118 image_ci.mipLevels = 1;
9119 image_ci.arrayLayers = 1;
9120 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9121 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9122 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9123 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9124 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9125 VkImage image;
9126 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9127 ASSERT_VK_SUCCESS(err);
9128 // Bind memory to image
9129 VkMemoryRequirements mem_reqs;
9130 VkDeviceMemory image_mem;
9131 bool pass;
9132 VkMemoryAllocateInfo mem_alloc = {};
9133 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9134 mem_alloc.pNext = NULL;
9135 mem_alloc.allocationSize = 0;
9136 mem_alloc.memoryTypeIndex = 0;
9137 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9138 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009139 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009140 ASSERT_TRUE(pass);
9141 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9142 ASSERT_VK_SUCCESS(err);
9143 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9144 ASSERT_VK_SUCCESS(err);
9145 // Now create view for image
9146 VkImageViewCreateInfo image_view_ci = {};
9147 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9148 image_view_ci.image = image;
9149 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9150 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9151 image_view_ci.subresourceRange.layerCount = 1;
9152 image_view_ci.subresourceRange.baseArrayLayer = 0;
9153 image_view_ci.subresourceRange.levelCount = 1;
9154 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009155 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009156
9157 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009158 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009159 ASSERT_VK_SUCCESS(err);
9160
9161 VkDescriptorImageInfo img_info = {};
9162 img_info.imageView = image_view;
9163 VkWriteDescriptorSet descriptor_write = {};
9164 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9165 descriptor_write.dstBinding = 0;
9166 descriptor_write.descriptorCount = 1;
9167 descriptor_write.pTexelBufferView = NULL;
9168 descriptor_write.pBufferInfo = NULL;
9169 descriptor_write.pImageInfo = &img_info;
9170 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9171 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009172 const char *error_msg =
9173 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9174 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009176
9177 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9178
9179 m_errorMonitor->VerifyFound();
9180 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9181 vkDestroyImage(m_device->device(), image, NULL);
9182 vkFreeMemory(m_device->device(), image_mem, NULL);
9183 vkDestroyImageView(m_device->device(), image_view, NULL);
9184 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9185 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9186}
9187
Karl Schultz6addd812016-02-02 17:17:23 -07009188TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009189 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009190 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009191
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9193 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9194 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009195
Tobin Ehlis3b780662015-05-28 12:11:26 -06009196 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009197 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009198 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009199 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9200 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009201
9202 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009203 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9204 ds_pool_ci.pNext = NULL;
9205 ds_pool_ci.maxSets = 1;
9206 ds_pool_ci.poolSizeCount = 1;
9207 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009208
Tobin Ehlis3b780662015-05-28 12:11:26 -06009209 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009210 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009211 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009212 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009213 dsl_binding.binding = 0;
9214 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9215 dsl_binding.descriptorCount = 1;
9216 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9217 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009218
Tony Barboureb254902015-07-15 12:50:33 -06009219 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009220 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9221 ds_layout_ci.pNext = NULL;
9222 ds_layout_ci.bindingCount = 1;
9223 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009224
Tobin Ehlis3b780662015-05-28 12:11:26 -06009225 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009226 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009227 ASSERT_VK_SUCCESS(err);
9228
9229 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009230 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009231 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009232 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009233 alloc_info.descriptorPool = ds_pool;
9234 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009235 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009236 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009237
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009238 VkSamplerCreateInfo sampler_ci = {};
9239 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9240 sampler_ci.pNext = NULL;
9241 sampler_ci.magFilter = VK_FILTER_NEAREST;
9242 sampler_ci.minFilter = VK_FILTER_NEAREST;
9243 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9244 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9245 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9246 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9247 sampler_ci.mipLodBias = 1.0;
9248 sampler_ci.anisotropyEnable = VK_FALSE;
9249 sampler_ci.maxAnisotropy = 1;
9250 sampler_ci.compareEnable = VK_FALSE;
9251 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9252 sampler_ci.minLod = 1.0;
9253 sampler_ci.maxLod = 1.0;
9254 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9255 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9256 VkSampler sampler;
9257 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9258 ASSERT_VK_SUCCESS(err);
9259
9260 VkDescriptorImageInfo info = {};
9261 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009262
9263 VkWriteDescriptorSet descriptor_write;
9264 memset(&descriptor_write, 0, sizeof(descriptor_write));
9265 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009266 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009267 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009268 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009269 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009270 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009271
9272 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9273
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009274 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009275
Chia-I Wuf7458c52015-10-26 21:10:41 +08009276 vkDestroySampler(m_device->device(), sampler, NULL);
9277 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9278 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009279}
9280
Karl Schultz6addd812016-02-02 17:17:23 -07009281TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009282 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009283 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009284
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009286
Tobin Ehlis3b780662015-05-28 12:11:26 -06009287 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009288 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009289 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009290 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9291 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009292
9293 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009294 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9295 ds_pool_ci.pNext = NULL;
9296 ds_pool_ci.maxSets = 1;
9297 ds_pool_ci.poolSizeCount = 1;
9298 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009299
Tobin Ehlis3b780662015-05-28 12:11:26 -06009300 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009301 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009302 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009303
Tony Barboureb254902015-07-15 12:50:33 -06009304 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009305 dsl_binding.binding = 0;
9306 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9307 dsl_binding.descriptorCount = 1;
9308 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9309 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009310
9311 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009312 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9313 ds_layout_ci.pNext = NULL;
9314 ds_layout_ci.bindingCount = 1;
9315 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009316
Tobin Ehlis3b780662015-05-28 12:11:26 -06009317 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009318 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009319 ASSERT_VK_SUCCESS(err);
9320
9321 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009322 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009323 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009324 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009325 alloc_info.descriptorPool = ds_pool;
9326 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009327 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009328 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009329
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009330 // Correctly update descriptor to avoid "NOT_UPDATED" error
9331 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009332 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009333 buff_info.offset = 0;
9334 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009335
9336 VkWriteDescriptorSet descriptor_write;
9337 memset(&descriptor_write, 0, sizeof(descriptor_write));
9338 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009339 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009340 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009341 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009342 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9343 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009344
9345 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9346
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009347 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009348
Chia-I Wuf7458c52015-10-26 21:10:41 +08009349 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9350 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009351}
9352
Karl Schultz6addd812016-02-02 17:17:23 -07009353TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009354 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009355 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009356
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009358
Tobin Ehlis3b780662015-05-28 12:11:26 -06009359 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009360 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009361 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009362 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9363 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009364
9365 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009366 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9367 ds_pool_ci.pNext = NULL;
9368 ds_pool_ci.maxSets = 1;
9369 ds_pool_ci.poolSizeCount = 1;
9370 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009371
Tobin Ehlis3b780662015-05-28 12:11:26 -06009372 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009373 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009374 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009375
Tony Barboureb254902015-07-15 12:50:33 -06009376 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009377 dsl_binding.binding = 0;
9378 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9379 dsl_binding.descriptorCount = 1;
9380 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9381 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009382
9383 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009384 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9385 ds_layout_ci.pNext = NULL;
9386 ds_layout_ci.bindingCount = 1;
9387 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009388 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009389 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009390 ASSERT_VK_SUCCESS(err);
9391
9392 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009393 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009394 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009395 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009396 alloc_info.descriptorPool = ds_pool;
9397 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009398 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009399 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009400
Tony Barboureb254902015-07-15 12:50:33 -06009401 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009402 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9403 sampler_ci.pNext = NULL;
9404 sampler_ci.magFilter = VK_FILTER_NEAREST;
9405 sampler_ci.minFilter = VK_FILTER_NEAREST;
9406 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9407 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9408 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9409 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9410 sampler_ci.mipLodBias = 1.0;
9411 sampler_ci.anisotropyEnable = VK_FALSE;
9412 sampler_ci.maxAnisotropy = 1;
9413 sampler_ci.compareEnable = VK_FALSE;
9414 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9415 sampler_ci.minLod = 1.0;
9416 sampler_ci.maxLod = 1.0;
9417 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9418 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009419
Tobin Ehlis3b780662015-05-28 12:11:26 -06009420 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009421 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009422 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009423
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009424 VkDescriptorImageInfo info = {};
9425 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009426
9427 VkWriteDescriptorSet descriptor_write;
9428 memset(&descriptor_write, 0, sizeof(descriptor_write));
9429 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009430 descriptor_write.dstSet = descriptorSet;
9431 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009432 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009433 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009434 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009435 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009436
9437 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9438
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009439 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009440
Chia-I Wuf7458c52015-10-26 21:10:41 +08009441 vkDestroySampler(m_device->device(), sampler, NULL);
9442 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9443 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009444}
9445
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009446TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9447 // Create layout w/ empty binding and attempt to update it
9448 VkResult err;
9449
9450 ASSERT_NO_FATAL_FAILURE(InitState());
9451
9452 VkDescriptorPoolSize ds_type_count = {};
9453 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9454 ds_type_count.descriptorCount = 1;
9455
9456 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9457 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9458 ds_pool_ci.pNext = NULL;
9459 ds_pool_ci.maxSets = 1;
9460 ds_pool_ci.poolSizeCount = 1;
9461 ds_pool_ci.pPoolSizes = &ds_type_count;
9462
9463 VkDescriptorPool ds_pool;
9464 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9465 ASSERT_VK_SUCCESS(err);
9466
9467 VkDescriptorSetLayoutBinding dsl_binding = {};
9468 dsl_binding.binding = 0;
9469 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9470 dsl_binding.descriptorCount = 0;
9471 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9472 dsl_binding.pImmutableSamplers = NULL;
9473
9474 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9475 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9476 ds_layout_ci.pNext = NULL;
9477 ds_layout_ci.bindingCount = 1;
9478 ds_layout_ci.pBindings = &dsl_binding;
9479 VkDescriptorSetLayout ds_layout;
9480 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9481 ASSERT_VK_SUCCESS(err);
9482
9483 VkDescriptorSet descriptor_set;
9484 VkDescriptorSetAllocateInfo alloc_info = {};
9485 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9486 alloc_info.descriptorSetCount = 1;
9487 alloc_info.descriptorPool = ds_pool;
9488 alloc_info.pSetLayouts = &ds_layout;
9489 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9490 ASSERT_VK_SUCCESS(err);
9491
9492 VkSamplerCreateInfo sampler_ci = {};
9493 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9494 sampler_ci.magFilter = VK_FILTER_NEAREST;
9495 sampler_ci.minFilter = VK_FILTER_NEAREST;
9496 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9497 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9498 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9499 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9500 sampler_ci.mipLodBias = 1.0;
9501 sampler_ci.maxAnisotropy = 1;
9502 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9503 sampler_ci.minLod = 1.0;
9504 sampler_ci.maxLod = 1.0;
9505 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9506
9507 VkSampler sampler;
9508 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9509 ASSERT_VK_SUCCESS(err);
9510
9511 VkDescriptorImageInfo info = {};
9512 info.sampler = sampler;
9513
9514 VkWriteDescriptorSet descriptor_write;
9515 memset(&descriptor_write, 0, sizeof(descriptor_write));
9516 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9517 descriptor_write.dstSet = descriptor_set;
9518 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009519 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009520 // This is the wrong type, but empty binding error will be flagged first
9521 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9522 descriptor_write.pImageInfo = &info;
9523
9524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9525 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9526 m_errorMonitor->VerifyFound();
9527
9528 vkDestroySampler(m_device->device(), sampler, NULL);
9529 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9530 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9531}
9532
Karl Schultz6addd812016-02-02 17:17:23 -07009533TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9534 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9535 // types
9536 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009537
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009538 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 -06009539
Tobin Ehlis3b780662015-05-28 12:11:26 -06009540 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009541
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009542 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009543 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9544 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009545
9546 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009547 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9548 ds_pool_ci.pNext = NULL;
9549 ds_pool_ci.maxSets = 1;
9550 ds_pool_ci.poolSizeCount = 1;
9551 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009552
Tobin Ehlis3b780662015-05-28 12:11:26 -06009553 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009554 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009555 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009556 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009557 dsl_binding.binding = 0;
9558 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9559 dsl_binding.descriptorCount = 1;
9560 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9561 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009562
Tony Barboureb254902015-07-15 12:50:33 -06009563 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009564 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9565 ds_layout_ci.pNext = NULL;
9566 ds_layout_ci.bindingCount = 1;
9567 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009568
Tobin Ehlis3b780662015-05-28 12:11:26 -06009569 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009570 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009571 ASSERT_VK_SUCCESS(err);
9572
9573 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009574 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009575 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009576 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009577 alloc_info.descriptorPool = ds_pool;
9578 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009579 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009580 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009581
Tony Barboureb254902015-07-15 12:50:33 -06009582 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009583 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9584 sampler_ci.pNext = NULL;
9585 sampler_ci.magFilter = VK_FILTER_NEAREST;
9586 sampler_ci.minFilter = VK_FILTER_NEAREST;
9587 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9588 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9589 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9590 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9591 sampler_ci.mipLodBias = 1.0;
9592 sampler_ci.anisotropyEnable = VK_FALSE;
9593 sampler_ci.maxAnisotropy = 1;
9594 sampler_ci.compareEnable = VK_FALSE;
9595 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9596 sampler_ci.minLod = 1.0;
9597 sampler_ci.maxLod = 1.0;
9598 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9599 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009600 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009601 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009602 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009603
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009604 VkDescriptorImageInfo info = {};
9605 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009606
9607 VkWriteDescriptorSet descriptor_write;
9608 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009609 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009610 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009611 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009612 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009613 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009614 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009615
9616 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9617
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009618 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009619
Chia-I Wuf7458c52015-10-26 21:10:41 +08009620 vkDestroySampler(m_device->device(), sampler, NULL);
9621 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9622 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009623}
9624
Karl Schultz6addd812016-02-02 17:17:23 -07009625TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009626 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009627 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009628
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009630
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009631 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009632 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9633 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009634 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009635 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9636 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009637
9638 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009639 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9640 ds_pool_ci.pNext = NULL;
9641 ds_pool_ci.maxSets = 1;
9642 ds_pool_ci.poolSizeCount = 1;
9643 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009644
9645 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009646 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009647 ASSERT_VK_SUCCESS(err);
9648
9649 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009650 dsl_binding.binding = 0;
9651 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9652 dsl_binding.descriptorCount = 1;
9653 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9654 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009655
9656 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009657 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9658 ds_layout_ci.pNext = NULL;
9659 ds_layout_ci.bindingCount = 1;
9660 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009661 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009662 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009663 ASSERT_VK_SUCCESS(err);
9664
9665 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009666 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009667 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009668 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009669 alloc_info.descriptorPool = ds_pool;
9670 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009671 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009672 ASSERT_VK_SUCCESS(err);
9673
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009674 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009675
9676 VkDescriptorImageInfo descriptor_info;
9677 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9678 descriptor_info.sampler = sampler;
9679
9680 VkWriteDescriptorSet descriptor_write;
9681 memset(&descriptor_write, 0, sizeof(descriptor_write));
9682 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009683 descriptor_write.dstSet = descriptorSet;
9684 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009685 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009686 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9687 descriptor_write.pImageInfo = &descriptor_info;
9688
9689 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9690
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009691 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009692
Chia-I Wuf7458c52015-10-26 21:10:41 +08009693 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9694 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009695}
9696
Karl Schultz6addd812016-02-02 17:17:23 -07009697TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9698 // Create a single combined Image/Sampler descriptor and send it an invalid
9699 // imageView
9700 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009701
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009703
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009704 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009705 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009706 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9707 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009708
9709 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009710 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9711 ds_pool_ci.pNext = NULL;
9712 ds_pool_ci.maxSets = 1;
9713 ds_pool_ci.poolSizeCount = 1;
9714 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009715
9716 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009717 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009718 ASSERT_VK_SUCCESS(err);
9719
9720 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009721 dsl_binding.binding = 0;
9722 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9723 dsl_binding.descriptorCount = 1;
9724 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9725 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009726
9727 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009728 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9729 ds_layout_ci.pNext = NULL;
9730 ds_layout_ci.bindingCount = 1;
9731 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009732 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009734 ASSERT_VK_SUCCESS(err);
9735
9736 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009737 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009738 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009739 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009740 alloc_info.descriptorPool = ds_pool;
9741 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009743 ASSERT_VK_SUCCESS(err);
9744
9745 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009746 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9747 sampler_ci.pNext = NULL;
9748 sampler_ci.magFilter = VK_FILTER_NEAREST;
9749 sampler_ci.minFilter = VK_FILTER_NEAREST;
9750 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9751 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9752 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9753 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9754 sampler_ci.mipLodBias = 1.0;
9755 sampler_ci.anisotropyEnable = VK_FALSE;
9756 sampler_ci.maxAnisotropy = 1;
9757 sampler_ci.compareEnable = VK_FALSE;
9758 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9759 sampler_ci.minLod = 1.0;
9760 sampler_ci.maxLod = 1.0;
9761 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9762 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009763
9764 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009765 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009766 ASSERT_VK_SUCCESS(err);
9767
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009768 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009769
9770 VkDescriptorImageInfo descriptor_info;
9771 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9772 descriptor_info.sampler = sampler;
9773 descriptor_info.imageView = view;
9774
9775 VkWriteDescriptorSet descriptor_write;
9776 memset(&descriptor_write, 0, sizeof(descriptor_write));
9777 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009778 descriptor_write.dstSet = descriptorSet;
9779 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009780 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009781 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9782 descriptor_write.pImageInfo = &descriptor_info;
9783
9784 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9785
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009786 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009787
Chia-I Wuf7458c52015-10-26 21:10:41 +08009788 vkDestroySampler(m_device->device(), sampler, NULL);
9789 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9790 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009791}
9792
Karl Schultz6addd812016-02-02 17:17:23 -07009793TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9794 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9795 // into the other
9796 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009797
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9799 " binding #1 with type "
9800 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9801 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009802
Tobin Ehlis04356f92015-10-27 16:35:27 -06009803 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009804 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009805 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009806 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9807 ds_type_count[0].descriptorCount = 1;
9808 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9809 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009810
9811 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009812 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9813 ds_pool_ci.pNext = NULL;
9814 ds_pool_ci.maxSets = 1;
9815 ds_pool_ci.poolSizeCount = 2;
9816 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009817
9818 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009819 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009820 ASSERT_VK_SUCCESS(err);
9821 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009822 dsl_binding[0].binding = 0;
9823 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9824 dsl_binding[0].descriptorCount = 1;
9825 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9826 dsl_binding[0].pImmutableSamplers = NULL;
9827 dsl_binding[1].binding = 1;
9828 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9829 dsl_binding[1].descriptorCount = 1;
9830 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9831 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009832
9833 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009834 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9835 ds_layout_ci.pNext = NULL;
9836 ds_layout_ci.bindingCount = 2;
9837 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009838
9839 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009840 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009841 ASSERT_VK_SUCCESS(err);
9842
9843 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009844 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009845 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009846 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009847 alloc_info.descriptorPool = ds_pool;
9848 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009849 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009850 ASSERT_VK_SUCCESS(err);
9851
9852 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009853 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9854 sampler_ci.pNext = NULL;
9855 sampler_ci.magFilter = VK_FILTER_NEAREST;
9856 sampler_ci.minFilter = VK_FILTER_NEAREST;
9857 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9858 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9859 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9860 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9861 sampler_ci.mipLodBias = 1.0;
9862 sampler_ci.anisotropyEnable = VK_FALSE;
9863 sampler_ci.maxAnisotropy = 1;
9864 sampler_ci.compareEnable = VK_FALSE;
9865 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9866 sampler_ci.minLod = 1.0;
9867 sampler_ci.maxLod = 1.0;
9868 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9869 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009870
9871 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009872 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009873 ASSERT_VK_SUCCESS(err);
9874
9875 VkDescriptorImageInfo info = {};
9876 info.sampler = sampler;
9877
9878 VkWriteDescriptorSet descriptor_write;
9879 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9880 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009881 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009882 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009883 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009884 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9885 descriptor_write.pImageInfo = &info;
9886 // This write update should succeed
9887 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9888 // Now perform a copy update that fails due to type mismatch
9889 VkCopyDescriptorSet copy_ds_update;
9890 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9891 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9892 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009893 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009894 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009895 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
9896 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009897 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9898
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009899 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009900 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009901 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 -06009902 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9903 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9904 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009905 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009906 copy_ds_update.dstSet = descriptorSet;
9907 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009908 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009909 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9910
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009911 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009912
Tobin Ehlis04356f92015-10-27 16:35:27 -06009913 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9915 " binding#1 with offset index of 1 plus "
9916 "update array offset of 0 and update of "
9917 "5 descriptors oversteps total number "
9918 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009919
Tobin Ehlis04356f92015-10-27 16:35:27 -06009920 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9921 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9922 copy_ds_update.srcSet = descriptorSet;
9923 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009924 copy_ds_update.dstSet = descriptorSet;
9925 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009926 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009927 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9928
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009929 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009930
Chia-I Wuf7458c52015-10-26 21:10:41 +08009931 vkDestroySampler(m_device->device(), sampler, NULL);
9932 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9933 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009934}
9935
Karl Schultz6addd812016-02-02 17:17:23 -07009936TEST_F(VkLayerTest, NumSamplesMismatch) {
9937 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9938 // sampleCount
9939 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009940
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009942
Tobin Ehlis3b780662015-05-28 12:11:26 -06009943 ASSERT_NO_FATAL_FAILURE(InitState());
9944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009945 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009946 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009947 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009948
9949 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009950 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9951 ds_pool_ci.pNext = NULL;
9952 ds_pool_ci.maxSets = 1;
9953 ds_pool_ci.poolSizeCount = 1;
9954 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009955
Tobin Ehlis3b780662015-05-28 12:11:26 -06009956 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009957 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009958 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009959
Tony Barboureb254902015-07-15 12:50:33 -06009960 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009961 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009962 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009963 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009964 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9965 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009966
Tony Barboureb254902015-07-15 12:50:33 -06009967 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9968 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9969 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009970 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009971 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009972
Tobin Ehlis3b780662015-05-28 12:11:26 -06009973 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009974 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009975 ASSERT_VK_SUCCESS(err);
9976
9977 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009978 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009979 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009980 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009981 alloc_info.descriptorPool = ds_pool;
9982 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009983 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009984 ASSERT_VK_SUCCESS(err);
9985
Tony Barboureb254902015-07-15 12:50:33 -06009986 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009987 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07009988 pipe_ms_state_ci.pNext = NULL;
9989 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
9990 pipe_ms_state_ci.sampleShadingEnable = 0;
9991 pipe_ms_state_ci.minSampleShading = 1.0;
9992 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009993
Tony Barboureb254902015-07-15 12:50:33 -06009994 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009995 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
9996 pipeline_layout_ci.pNext = NULL;
9997 pipeline_layout_ci.setLayoutCount = 1;
9998 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009999
10000 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010002 ASSERT_VK_SUCCESS(err);
10003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010004 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010005 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 -060010006 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010007 VkPipelineObj pipe(m_device);
10008 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010009 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010010 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010011 pipe.SetMSAA(&pipe_ms_state_ci);
10012 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010013
Tony Barbour552f6c02016-12-21 14:34:07 -070010014 m_commandBuffer->BeginCommandBuffer();
10015 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010016 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010017
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010018 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10019 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10020 VkRect2D scissor = {{0, 0}, {16, 16}};
10021 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10022
Mark Young29927482016-05-04 14:38:51 -060010023 // Render triangle (the error should trigger on the attempt to draw).
10024 Draw(3, 1, 0, 0);
10025
10026 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010027 m_commandBuffer->EndRenderPass();
10028 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010029
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010030 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010031
Chia-I Wuf7458c52015-10-26 21:10:41 +080010032 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10033 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10034 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010035}
Mark Young29927482016-05-04 14:38:51 -060010036
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010037TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010038 TEST_DESCRIPTION(
10039 "Hit RenderPass incompatible cases. "
10040 "Initial case is drawing with an active renderpass that's "
10041 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010042 VkResult err;
10043
10044 ASSERT_NO_FATAL_FAILURE(InitState());
10045 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10046
10047 VkDescriptorSetLayoutBinding dsl_binding = {};
10048 dsl_binding.binding = 0;
10049 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10050 dsl_binding.descriptorCount = 1;
10051 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10052 dsl_binding.pImmutableSamplers = NULL;
10053
10054 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10055 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10056 ds_layout_ci.pNext = NULL;
10057 ds_layout_ci.bindingCount = 1;
10058 ds_layout_ci.pBindings = &dsl_binding;
10059
10060 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010061 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010062 ASSERT_VK_SUCCESS(err);
10063
10064 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10065 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10066 pipeline_layout_ci.pNext = NULL;
10067 pipeline_layout_ci.setLayoutCount = 1;
10068 pipeline_layout_ci.pSetLayouts = &ds_layout;
10069
10070 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010071 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010072 ASSERT_VK_SUCCESS(err);
10073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010074 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010075 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 -060010076 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010077 // Create a renderpass that will be incompatible with default renderpass
10078 VkAttachmentReference attach = {};
10079 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10080 VkAttachmentReference color_att = {};
10081 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10082 VkSubpassDescription subpass = {};
10083 subpass.inputAttachmentCount = 1;
10084 subpass.pInputAttachments = &attach;
10085 subpass.colorAttachmentCount = 1;
10086 subpass.pColorAttachments = &color_att;
10087 VkRenderPassCreateInfo rpci = {};
10088 rpci.subpassCount = 1;
10089 rpci.pSubpasses = &subpass;
10090 rpci.attachmentCount = 1;
10091 VkAttachmentDescription attach_desc = {};
10092 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010093 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10094 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010095 rpci.pAttachments = &attach_desc;
10096 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10097 VkRenderPass rp;
10098 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10099 VkPipelineObj pipe(m_device);
10100 pipe.AddShader(&vs);
10101 pipe.AddShader(&fs);
10102 pipe.AddColorAttachment();
10103 VkViewport view_port = {};
10104 m_viewports.push_back(view_port);
10105 pipe.SetViewport(m_viewports);
10106 VkRect2D rect = {};
10107 m_scissors.push_back(rect);
10108 pipe.SetScissor(m_scissors);
10109 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10110
10111 VkCommandBufferInheritanceInfo cbii = {};
10112 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10113 cbii.renderPass = rp;
10114 cbii.subpass = 0;
10115 VkCommandBufferBeginInfo cbbi = {};
10116 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10117 cbbi.pInheritanceInfo = &cbii;
10118 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10119 VkRenderPassBeginInfo rpbi = {};
10120 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10121 rpbi.framebuffer = m_framebuffer;
10122 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010123 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10124 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010125
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010127 // Render triangle (the error should trigger on the attempt to draw).
10128 Draw(3, 1, 0, 0);
10129
10130 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010131 m_commandBuffer->EndRenderPass();
10132 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010133
10134 m_errorMonitor->VerifyFound();
10135
10136 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10137 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10138 vkDestroyRenderPass(m_device->device(), rp, NULL);
10139}
10140
Mark Youngc89c6312016-03-31 16:03:20 -060010141TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10142 // Create Pipeline where the number of blend attachments doesn't match the
10143 // number of color attachments. In this case, we don't add any color
10144 // blend attachments even though we have a color attachment.
10145 VkResult err;
10146
10147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010148 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010149
10150 ASSERT_NO_FATAL_FAILURE(InitState());
10151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10152 VkDescriptorPoolSize ds_type_count = {};
10153 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10154 ds_type_count.descriptorCount = 1;
10155
10156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10158 ds_pool_ci.pNext = NULL;
10159 ds_pool_ci.maxSets = 1;
10160 ds_pool_ci.poolSizeCount = 1;
10161 ds_pool_ci.pPoolSizes = &ds_type_count;
10162
10163 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010164 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010165 ASSERT_VK_SUCCESS(err);
10166
10167 VkDescriptorSetLayoutBinding dsl_binding = {};
10168 dsl_binding.binding = 0;
10169 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10170 dsl_binding.descriptorCount = 1;
10171 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10172 dsl_binding.pImmutableSamplers = NULL;
10173
10174 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10175 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10176 ds_layout_ci.pNext = NULL;
10177 ds_layout_ci.bindingCount = 1;
10178 ds_layout_ci.pBindings = &dsl_binding;
10179
10180 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010181 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010182 ASSERT_VK_SUCCESS(err);
10183
10184 VkDescriptorSet descriptorSet;
10185 VkDescriptorSetAllocateInfo alloc_info = {};
10186 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10187 alloc_info.descriptorSetCount = 1;
10188 alloc_info.descriptorPool = ds_pool;
10189 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010190 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010191 ASSERT_VK_SUCCESS(err);
10192
10193 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010194 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010195 pipe_ms_state_ci.pNext = NULL;
10196 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10197 pipe_ms_state_ci.sampleShadingEnable = 0;
10198 pipe_ms_state_ci.minSampleShading = 1.0;
10199 pipe_ms_state_ci.pSampleMask = NULL;
10200
10201 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10202 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10203 pipeline_layout_ci.pNext = NULL;
10204 pipeline_layout_ci.setLayoutCount = 1;
10205 pipeline_layout_ci.pSetLayouts = &ds_layout;
10206
10207 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010209 ASSERT_VK_SUCCESS(err);
10210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010211 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010212 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 -060010213 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010214 VkPipelineObj pipe(m_device);
10215 pipe.AddShader(&vs);
10216 pipe.AddShader(&fs);
10217 pipe.SetMSAA(&pipe_ms_state_ci);
10218 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10219
Tony Barbour552f6c02016-12-21 14:34:07 -070010220 m_commandBuffer->BeginCommandBuffer();
10221 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010222 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010223
Rene Lindsay6d5c4fe2017-01-13 09:41:19 -070010224 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10225 VkRect2D scissor = {{0, 0}, {16, 16}};
10226 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10227 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10228
Mark Young29927482016-05-04 14:38:51 -060010229 // Render triangle (the error should trigger on the attempt to draw).
10230 Draw(3, 1, 0, 0);
10231
10232 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010233 m_commandBuffer->EndRenderPass();
10234 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010235
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010236 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010237
10238 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10239 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10240 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10241}
Mark Young29927482016-05-04 14:38:51 -060010242
Mark Muellerd4914412016-06-13 17:52:06 -060010243TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010244 TEST_DESCRIPTION(
10245 "Points to a wrong colorAttachment index in a VkClearAttachment "
10246 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010247 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010249
10250 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10251 m_errorMonitor->VerifyFound();
10252}
10253
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010254TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010255 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10256 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010257
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010258 ASSERT_NO_FATAL_FAILURE(InitState());
10259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010260
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010261 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010262 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10263 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010264
10265 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010266 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10267 ds_pool_ci.pNext = NULL;
10268 ds_pool_ci.maxSets = 1;
10269 ds_pool_ci.poolSizeCount = 1;
10270 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010271
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010272 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010273 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010274 ASSERT_VK_SUCCESS(err);
10275
Tony Barboureb254902015-07-15 12:50:33 -060010276 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010277 dsl_binding.binding = 0;
10278 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10279 dsl_binding.descriptorCount = 1;
10280 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10281 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010282
Tony Barboureb254902015-07-15 12:50:33 -060010283 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010284 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10285 ds_layout_ci.pNext = NULL;
10286 ds_layout_ci.bindingCount = 1;
10287 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010288
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010289 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010290 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010291 ASSERT_VK_SUCCESS(err);
10292
10293 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010294 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010295 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010296 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010297 alloc_info.descriptorPool = ds_pool;
10298 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010299 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010300 ASSERT_VK_SUCCESS(err);
10301
Tony Barboureb254902015-07-15 12:50:33 -060010302 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010303 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010304 pipe_ms_state_ci.pNext = NULL;
10305 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10306 pipe_ms_state_ci.sampleShadingEnable = 0;
10307 pipe_ms_state_ci.minSampleShading = 1.0;
10308 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010309
Tony Barboureb254902015-07-15 12:50:33 -060010310 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010311 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10312 pipeline_layout_ci.pNext = NULL;
10313 pipeline_layout_ci.setLayoutCount = 1;
10314 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010315
10316 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010317 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010318 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010319
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010320 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010321 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010322 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010323 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010324
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010325 VkPipelineObj pipe(m_device);
10326 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010327 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010328 pipe.SetMSAA(&pipe_ms_state_ci);
10329 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010330
Tony Barbour552f6c02016-12-21 14:34:07 -070010331 m_commandBuffer->BeginCommandBuffer();
10332 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010333
Karl Schultz6addd812016-02-02 17:17:23 -070010334 // Main thing we care about for this test is that the VkImage obj we're
10335 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010336 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010337 VkClearAttachment color_attachment;
10338 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10339 color_attachment.clearValue.color.float32[0] = 1.0;
10340 color_attachment.clearValue.color.float32[1] = 1.0;
10341 color_attachment.clearValue.color.float32[2] = 1.0;
10342 color_attachment.clearValue.color.float32[3] = 1.0;
10343 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010344 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010345
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010346 // Call for full-sized FB Color attachment prior to issuing a Draw
10347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070010348 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010349 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010350 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010351
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010352 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10353 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10355 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10356 m_errorMonitor->VerifyFound();
10357
10358 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10359 clear_rect.layerCount = 2;
10360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10361 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010362 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010363
Chia-I Wuf7458c52015-10-26 21:10:41 +080010364 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10365 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10366 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010367}
10368
Karl Schultz6addd812016-02-02 17:17:23 -070010369TEST_F(VkLayerTest, VtxBufferBadIndex) {
10370 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010372 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10373 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010374
Tobin Ehlis502480b2015-06-24 15:53:07 -060010375 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010376 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010377 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010378
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010379 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010380 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10381 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010382
10383 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010384 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10385 ds_pool_ci.pNext = NULL;
10386 ds_pool_ci.maxSets = 1;
10387 ds_pool_ci.poolSizeCount = 1;
10388 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010389
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010390 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010391 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010392 ASSERT_VK_SUCCESS(err);
10393
Tony Barboureb254902015-07-15 12:50:33 -060010394 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010395 dsl_binding.binding = 0;
10396 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10397 dsl_binding.descriptorCount = 1;
10398 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10399 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010400
Tony Barboureb254902015-07-15 12:50:33 -060010401 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010402 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10403 ds_layout_ci.pNext = NULL;
10404 ds_layout_ci.bindingCount = 1;
10405 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010406
Tobin Ehlis502480b2015-06-24 15:53:07 -060010407 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010409 ASSERT_VK_SUCCESS(err);
10410
10411 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010412 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010413 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010414 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010415 alloc_info.descriptorPool = ds_pool;
10416 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010417 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010418 ASSERT_VK_SUCCESS(err);
10419
Tony Barboureb254902015-07-15 12:50:33 -060010420 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010421 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010422 pipe_ms_state_ci.pNext = NULL;
10423 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10424 pipe_ms_state_ci.sampleShadingEnable = 0;
10425 pipe_ms_state_ci.minSampleShading = 1.0;
10426 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010427
Tony Barboureb254902015-07-15 12:50:33 -060010428 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010429 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10430 pipeline_layout_ci.pNext = NULL;
10431 pipeline_layout_ci.setLayoutCount = 1;
10432 pipeline_layout_ci.pSetLayouts = &ds_layout;
10433 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010434
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010435 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010436 ASSERT_VK_SUCCESS(err);
10437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010438 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010439 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 -060010440 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010441 VkPipelineObj pipe(m_device);
10442 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010443 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010444 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010445 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010446 pipe.SetViewport(m_viewports);
10447 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010448 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010449
Tony Barbour552f6c02016-12-21 14:34:07 -070010450 m_commandBuffer->BeginCommandBuffer();
10451 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010452 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010453 // Don't care about actual data, just need to get to draw to flag error
10454 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010455 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010456 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010457 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010458
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010459 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010460
Chia-I Wuf7458c52015-10-26 21:10:41 +080010461 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10462 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10463 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010464}
Mark Muellerdfe37552016-07-07 14:47:42 -060010465
Mark Mueller2ee294f2016-08-04 12:59:48 -060010466TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010467 TEST_DESCRIPTION(
10468 "Use an invalid count in a vkEnumeratePhysicalDevices call."
10469 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010470 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010471
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010472 const char *invalid_queueFamilyIndex_message =
10473 "Invalid queue create request in vkCreateDevice(). Invalid "
10474 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010476 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010477
Mark Mueller880fce52016-08-17 15:23:23 -060010478 // The following test fails with recent NVidia drivers.
10479 // By the time core_validation is reached, the NVidia
10480 // driver has sanitized the invalid condition and core_validation
10481 // is not introduced to the failure condition. This is not the case
10482 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010483 // uint32_t count = static_cast<uint32_t>(~0);
10484 // VkPhysicalDevice physical_device;
10485 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10486 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010489 float queue_priority = 0.0;
10490
10491 VkDeviceQueueCreateInfo queue_create_info = {};
10492 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10493 queue_create_info.queueCount = 1;
10494 queue_create_info.pQueuePriorities = &queue_priority;
10495 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10496
10497 VkPhysicalDeviceFeatures features = m_device->phy().features();
10498 VkDevice testDevice;
10499 VkDeviceCreateInfo device_create_info = {};
10500 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10501 device_create_info.queueCreateInfoCount = 1;
10502 device_create_info.pQueueCreateInfos = &queue_create_info;
10503 device_create_info.pEnabledFeatures = &features;
10504 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10505 m_errorMonitor->VerifyFound();
10506
10507 queue_create_info.queueFamilyIndex = 1;
10508
10509 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10510 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10511 for (unsigned i = 0; i < feature_count; i++) {
10512 if (VK_FALSE == feature_array[i]) {
10513 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010515 device_create_info.pEnabledFeatures = &features;
10516 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10517 m_errorMonitor->VerifyFound();
10518 break;
10519 }
10520 }
10521}
10522
Tobin Ehlis16edf082016-11-21 12:33:49 -070010523TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10524 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10525
10526 ASSERT_NO_FATAL_FAILURE(InitState());
10527
10528 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10529 std::vector<VkDeviceQueueCreateInfo> queue_info;
10530 queue_info.reserve(queue_props.size());
10531 std::vector<std::vector<float>> queue_priorities;
10532 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10533 VkDeviceQueueCreateInfo qi{};
10534 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10535 qi.queueFamilyIndex = i;
10536 qi.queueCount = queue_props[i].queueCount;
10537 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10538 qi.pQueuePriorities = queue_priorities[i].data();
10539 queue_info.push_back(qi);
10540 }
10541
10542 std::vector<const char *> device_extension_names;
10543
10544 VkDevice local_device;
10545 VkDeviceCreateInfo device_create_info = {};
10546 auto features = m_device->phy().features();
10547 // Intentionally disable pipeline stats
10548 features.pipelineStatisticsQuery = VK_FALSE;
10549 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10550 device_create_info.pNext = NULL;
10551 device_create_info.queueCreateInfoCount = queue_info.size();
10552 device_create_info.pQueueCreateInfos = queue_info.data();
10553 device_create_info.enabledLayerCount = 0;
10554 device_create_info.ppEnabledLayerNames = NULL;
10555 device_create_info.pEnabledFeatures = &features;
10556 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10557 ASSERT_VK_SUCCESS(err);
10558
10559 VkQueryPoolCreateInfo qpci{};
10560 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10561 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10562 qpci.queryCount = 1;
10563 VkQueryPool query_pool;
10564
10565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10566 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10567 m_errorMonitor->VerifyFound();
10568
10569 vkDestroyDevice(local_device, nullptr);
10570}
10571
Mark Mueller2ee294f2016-08-04 12:59:48 -060010572TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010573 TEST_DESCRIPTION(
10574 "Use an invalid queue index in a vkCmdWaitEvents call."
10575 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060010576
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010577 const char *invalid_queue_index =
10578 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10579 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10580 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010581
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010582 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010583
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010585
10586 ASSERT_NO_FATAL_FAILURE(InitState());
10587
10588 VkEvent event;
10589 VkEventCreateInfo event_create_info{};
10590 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10591 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10592
Mark Mueller2ee294f2016-08-04 12:59:48 -060010593 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010594 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010595
Tony Barbour552f6c02016-12-21 14:34:07 -070010596 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010597
10598 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010599 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 -060010600 ASSERT_TRUE(image.initialized());
10601 VkImageMemoryBarrier img_barrier = {};
10602 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10603 img_barrier.pNext = NULL;
10604 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10605 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10606 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10607 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10608 img_barrier.image = image.handle();
10609 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010610
10611 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10612 // that layer validation catches the case when it is not.
10613 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010614 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10615 img_barrier.subresourceRange.baseArrayLayer = 0;
10616 img_barrier.subresourceRange.baseMipLevel = 0;
10617 img_barrier.subresourceRange.layerCount = 1;
10618 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010619 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10620 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010621 m_errorMonitor->VerifyFound();
10622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010624
10625 VkQueryPool query_pool;
10626 VkQueryPoolCreateInfo query_pool_create_info = {};
10627 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10628 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10629 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010630 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010631
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010632 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010633 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10634
10635 vkEndCommandBuffer(m_commandBuffer->handle());
10636 m_errorMonitor->VerifyFound();
10637
10638 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10639 vkDestroyEvent(m_device->device(), event, nullptr);
10640}
10641
Mark Muellerdfe37552016-07-07 14:47:42 -060010642TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010643 TEST_DESCRIPTION(
10644 "Submit a command buffer using deleted vertex buffer, "
10645 "delete a buffer twice, use an invalid offset for each "
10646 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060010647
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010648 const char *deleted_buffer_in_command_buffer =
10649 "Cannot submit cmd buffer "
10650 "using deleted buffer ";
10651 const char *invalid_offset_message =
10652 "vkBindBufferMemory(): "
10653 "memoryOffset is 0x";
10654 const char *invalid_storage_buffer_offset_message =
10655 "vkBindBufferMemory(): "
10656 "storage memoryOffset "
10657 "is 0x";
10658 const char *invalid_texel_buffer_offset_message =
10659 "vkBindBufferMemory(): "
10660 "texel memoryOffset "
10661 "is 0x";
10662 const char *invalid_uniform_buffer_offset_message =
10663 "vkBindBufferMemory(): "
10664 "uniform memoryOffset "
10665 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010666
10667 ASSERT_NO_FATAL_FAILURE(InitState());
10668 ASSERT_NO_FATAL_FAILURE(InitViewport());
10669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10670
10671 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010672 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010673 pipe_ms_state_ci.pNext = NULL;
10674 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10675 pipe_ms_state_ci.sampleShadingEnable = 0;
10676 pipe_ms_state_ci.minSampleShading = 1.0;
10677 pipe_ms_state_ci.pSampleMask = nullptr;
10678
10679 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10680 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10681 VkPipelineLayout pipeline_layout;
10682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010683 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010684 ASSERT_VK_SUCCESS(err);
10685
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010686 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10687 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010688 VkPipelineObj pipe(m_device);
10689 pipe.AddShader(&vs);
10690 pipe.AddShader(&fs);
10691 pipe.AddColorAttachment();
10692 pipe.SetMSAA(&pipe_ms_state_ci);
10693 pipe.SetViewport(m_viewports);
10694 pipe.SetScissor(m_scissors);
10695 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10696
Tony Barbour552f6c02016-12-21 14:34:07 -070010697 m_commandBuffer->BeginCommandBuffer();
10698 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010699 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010700
10701 {
10702 // Create and bind a vertex buffer in a reduced scope, which will cause
10703 // it to be deleted upon leaving this scope
10704 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010705 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010706 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10707 draw_verticies.AddVertexInputToPipe(pipe);
10708 }
10709
10710 Draw(1, 0, 0, 0);
10711
Tony Barbour552f6c02016-12-21 14:34:07 -070010712 m_commandBuffer->EndRenderPass();
10713 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010714
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010716 QueueCommandBuffer(false);
10717 m_errorMonitor->VerifyFound();
10718
10719 {
10720 // Create and bind a vertex buffer in a reduced scope, and delete it
10721 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010722 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010724 buffer_test.TestDoubleDestroy();
10725 }
10726 m_errorMonitor->VerifyFound();
10727
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010728 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010729 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10731 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10732 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010733 m_errorMonitor->VerifyFound();
10734 }
10735
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010736 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10737 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010738 // Create and bind a memory buffer with an invalid offset again,
10739 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10741 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10742 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010743 m_errorMonitor->VerifyFound();
10744 }
10745
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010746 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010747 // Create and bind a memory buffer with an invalid offset again, but
10748 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10750 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10751 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010752 m_errorMonitor->VerifyFound();
10753 }
10754
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010755 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010756 // Create and bind a memory buffer with an invalid offset again, but
10757 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10759 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10760 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010761 m_errorMonitor->VerifyFound();
10762 }
10763
10764 {
10765 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010767 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10768 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010769 m_errorMonitor->VerifyFound();
10770 }
10771
10772 {
10773 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010775 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10776 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010777 }
10778 m_errorMonitor->VerifyFound();
10779
10780 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10781}
10782
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010783// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10784TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010785 TEST_DESCRIPTION(
10786 "Hit all possible validation checks associated with the "
10787 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10788 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010789 // 3 in ValidateCmdBufImageLayouts
10790 // * -1 Attempt to submit cmd buf w/ deleted image
10791 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10792 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010793
10794 ASSERT_NO_FATAL_FAILURE(InitState());
10795 // Create src & dst images to use for copy operations
10796 VkImage src_image;
10797 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010798 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010799
10800 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10801 const int32_t tex_width = 32;
10802 const int32_t tex_height = 32;
10803
10804 VkImageCreateInfo image_create_info = {};
10805 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10806 image_create_info.pNext = NULL;
10807 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10808 image_create_info.format = tex_format;
10809 image_create_info.extent.width = tex_width;
10810 image_create_info.extent.height = tex_height;
10811 image_create_info.extent.depth = 1;
10812 image_create_info.mipLevels = 1;
10813 image_create_info.arrayLayers = 4;
10814 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10815 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10816 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010817 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010818 image_create_info.flags = 0;
10819
10820 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10821 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010822 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010823 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10824 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010825 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10826 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10827 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10828 ASSERT_VK_SUCCESS(err);
10829
10830 // Allocate memory
10831 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010832 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010833 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010834 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10835 mem_alloc.pNext = NULL;
10836 mem_alloc.allocationSize = 0;
10837 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010838
10839 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010840 mem_alloc.allocationSize = img_mem_reqs.size;
10841 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010842 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010843 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010844 ASSERT_VK_SUCCESS(err);
10845
10846 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010847 mem_alloc.allocationSize = img_mem_reqs.size;
10848 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010849 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010850 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010851 ASSERT_VK_SUCCESS(err);
10852
10853 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010854 mem_alloc.allocationSize = img_mem_reqs.size;
10855 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010856 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010857 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010858 ASSERT_VK_SUCCESS(err);
10859
10860 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10861 ASSERT_VK_SUCCESS(err);
10862 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10863 ASSERT_VK_SUCCESS(err);
10864 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10865 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010866
Tony Barbour552f6c02016-12-21 14:34:07 -070010867 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010868 VkImageCopy copy_region;
10869 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10870 copy_region.srcSubresource.mipLevel = 0;
10871 copy_region.srcSubresource.baseArrayLayer = 0;
10872 copy_region.srcSubresource.layerCount = 1;
10873 copy_region.srcOffset.x = 0;
10874 copy_region.srcOffset.y = 0;
10875 copy_region.srcOffset.z = 0;
10876 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10877 copy_region.dstSubresource.mipLevel = 0;
10878 copy_region.dstSubresource.baseArrayLayer = 0;
10879 copy_region.dstSubresource.layerCount = 1;
10880 copy_region.dstOffset.x = 0;
10881 copy_region.dstOffset.y = 0;
10882 copy_region.dstOffset.z = 0;
10883 copy_region.extent.width = 1;
10884 copy_region.extent.height = 1;
10885 copy_region.extent.depth = 1;
10886
10887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10888 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10889 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 -060010890 m_errorMonitor->VerifyFound();
10891 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10893 "Cannot copy from an image whose source layout is "
10894 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10895 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010896 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 -060010897 m_errorMonitor->VerifyFound();
10898 // Final src error is due to bad layout type
10899 m_errorMonitor->SetDesiredFailureMsg(
10900 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10901 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010902 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 -060010903 m_errorMonitor->VerifyFound();
10904 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10906 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010907 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 -060010908 m_errorMonitor->VerifyFound();
10909 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10911 "Cannot copy from an image whose dest layout is "
10912 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10913 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010914 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 -060010915 m_errorMonitor->VerifyFound();
10916 m_errorMonitor->SetDesiredFailureMsg(
10917 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10918 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010919 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 -060010920 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010921
Cort3b021012016-12-07 12:00:57 -080010922 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10923 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10924 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10925 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10926 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10927 transfer_dst_image_barrier[0].srcAccessMask = 0;
10928 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10929 transfer_dst_image_barrier[0].image = dst_image;
10930 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10931 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10932 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10933 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10934 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10935 transfer_dst_image_barrier[0].image = depth_image;
10936 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10937 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10938 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10939
10940 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010941 VkClearColorValue color_clear_value = {};
10942 VkImageSubresourceRange clear_range;
10943 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10944 clear_range.baseMipLevel = 0;
10945 clear_range.baseArrayLayer = 0;
10946 clear_range.layerCount = 1;
10947 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010948
Cort3b021012016-12-07 12:00:57 -080010949 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10950 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010953 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010954 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010955 // Fail due to provided layout not matching actual current layout for color clear.
10956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010957 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010958 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010959
Cort530cf382016-12-08 09:59:47 -080010960 VkClearDepthStencilValue depth_clear_value = {};
10961 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010962
10963 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10964 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010967 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010968 m_errorMonitor->VerifyFound();
10969 // Fail due to provided layout not matching actual current layout for depth clear.
10970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010971 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010972 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010973
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010974 // Now cause error due to bad image layout transition in PipelineBarrier
10975 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010976 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010977 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010978 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010979 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010980 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10981 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010982 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10984 "You cannot transition the layout of aspect 1 from "
10985 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10986 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010987 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10988 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010989 m_errorMonitor->VerifyFound();
10990
10991 // Finally some layout errors at RenderPass create time
10992 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10993 VkAttachmentReference attach = {};
10994 // perf warning for GENERAL layout w/ non-DS input attachment
10995 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10996 VkSubpassDescription subpass = {};
10997 subpass.inputAttachmentCount = 1;
10998 subpass.pInputAttachments = &attach;
10999 VkRenderPassCreateInfo rpci = {};
11000 rpci.subpassCount = 1;
11001 rpci.pSubpasses = &subpass;
11002 rpci.attachmentCount = 1;
11003 VkAttachmentDescription attach_desc = {};
11004 attach_desc.format = VK_FORMAT_UNDEFINED;
11005 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011006 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011007 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11009 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011010 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11011 m_errorMonitor->VerifyFound();
11012 // error w/ non-general layout
11013 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11014
11015 m_errorMonitor->SetDesiredFailureMsg(
11016 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11017 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11018 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11019 m_errorMonitor->VerifyFound();
11020 subpass.inputAttachmentCount = 0;
11021 subpass.colorAttachmentCount = 1;
11022 subpass.pColorAttachments = &attach;
11023 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11024 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11026 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011027 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11028 m_errorMonitor->VerifyFound();
11029 // error w/ non-color opt or GENERAL layout for color attachment
11030 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11031 m_errorMonitor->SetDesiredFailureMsg(
11032 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11033 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11034 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11035 m_errorMonitor->VerifyFound();
11036 subpass.colorAttachmentCount = 0;
11037 subpass.pDepthStencilAttachment = &attach;
11038 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11039 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11041 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011042 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11043 m_errorMonitor->VerifyFound();
11044 // error w/ non-ds opt or GENERAL layout for color attachment
11045 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11047 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11048 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011049 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11050 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011051 // For this error we need a valid renderpass so create default one
11052 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11053 attach.attachment = 0;
11054 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11055 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11056 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11057 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11058 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11059 // Can't do a CLEAR load on READ_ONLY initialLayout
11060 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11061 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11062 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11064 " with invalid first layout "
11065 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11066 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011067 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11068 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011069
Cort3b021012016-12-07 12:00:57 -080011070 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11071 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11072 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011073 vkDestroyImage(m_device->device(), src_image, NULL);
11074 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011075 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011076}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011077
Tobin Ehlise0936662016-10-11 08:10:51 -060011078TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11079 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11080 VkResult err;
11081
11082 ASSERT_NO_FATAL_FAILURE(InitState());
11083
11084 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11085 VkImageTiling tiling;
11086 VkFormatProperties format_properties;
11087 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11088 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11089 tiling = VK_IMAGE_TILING_LINEAR;
11090 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11091 tiling = VK_IMAGE_TILING_OPTIMAL;
11092 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011093 printf(
11094 "Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11095 "skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011096 return;
11097 }
11098
11099 VkDescriptorPoolSize ds_type = {};
11100 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11101 ds_type.descriptorCount = 1;
11102
11103 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11104 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11105 ds_pool_ci.maxSets = 1;
11106 ds_pool_ci.poolSizeCount = 1;
11107 ds_pool_ci.pPoolSizes = &ds_type;
11108 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11109
11110 VkDescriptorPool ds_pool;
11111 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11112 ASSERT_VK_SUCCESS(err);
11113
11114 VkDescriptorSetLayoutBinding dsl_binding = {};
11115 dsl_binding.binding = 0;
11116 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11117 dsl_binding.descriptorCount = 1;
11118 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11119 dsl_binding.pImmutableSamplers = NULL;
11120
11121 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11122 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11123 ds_layout_ci.pNext = NULL;
11124 ds_layout_ci.bindingCount = 1;
11125 ds_layout_ci.pBindings = &dsl_binding;
11126
11127 VkDescriptorSetLayout ds_layout;
11128 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11129 ASSERT_VK_SUCCESS(err);
11130
11131 VkDescriptorSetAllocateInfo alloc_info = {};
11132 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11133 alloc_info.descriptorSetCount = 1;
11134 alloc_info.descriptorPool = ds_pool;
11135 alloc_info.pSetLayouts = &ds_layout;
11136 VkDescriptorSet descriptor_set;
11137 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11138 ASSERT_VK_SUCCESS(err);
11139
11140 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11141 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11142 pipeline_layout_ci.pNext = NULL;
11143 pipeline_layout_ci.setLayoutCount = 1;
11144 pipeline_layout_ci.pSetLayouts = &ds_layout;
11145 VkPipelineLayout pipeline_layout;
11146 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11147 ASSERT_VK_SUCCESS(err);
11148
11149 VkImageObj image(m_device);
11150 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11151 ASSERT_TRUE(image.initialized());
11152 VkImageView view = image.targetView(tex_format);
11153
11154 VkDescriptorImageInfo image_info = {};
11155 image_info.imageView = view;
11156 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11157
11158 VkWriteDescriptorSet descriptor_write = {};
11159 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11160 descriptor_write.dstSet = descriptor_set;
11161 descriptor_write.dstBinding = 0;
11162 descriptor_write.descriptorCount = 1;
11163 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11164 descriptor_write.pImageInfo = &image_info;
11165
11166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11167 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11168 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11169 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11170 m_errorMonitor->VerifyFound();
11171
11172 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11173 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11174 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11175 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11176}
11177
Mark Mueller93b938f2016-08-18 10:27:40 -060011178TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011179 TEST_DESCRIPTION(
11180 "Use vkCmdExecuteCommands with invalid state "
11181 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011182
11183 ASSERT_NO_FATAL_FAILURE(InitState());
11184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11185
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011186 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011187 const char *simultaneous_use_message2 =
11188 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11189 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011190
11191 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011192 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011193 command_buffer_allocate_info.commandPool = m_commandPool;
11194 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11195 command_buffer_allocate_info.commandBufferCount = 1;
11196
11197 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011199 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11200 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011201 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011202 command_buffer_inheritance_info.renderPass = m_renderPass;
11203 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011204
Mark Mueller93b938f2016-08-18 10:27:40 -060011205 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011206 command_buffer_begin_info.flags =
11207 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011208 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11209
11210 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11211 vkEndCommandBuffer(secondary_command_buffer);
11212
Mark Mueller93b938f2016-08-18 10:27:40 -060011213 VkSubmitInfo submit_info = {};
11214 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11215 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011216 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011217
Mark Mueller4042b652016-09-05 22:52:21 -060011218 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011219 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11221 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011222 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011223 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011224 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11225 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011226
Dave Houltonfbf52152017-01-06 12:55:29 -070011227 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011228 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011229 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011230
Mark Mueller4042b652016-09-05 22:52:21 -060011231 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011232 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011233 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11236 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011237 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011238 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11239 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011240
11241 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011242}
11243
Tobin Ehlisb093da82017-01-19 12:05:27 -070011244TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011245 TEST_DESCRIPTION(
11246 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11247 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070011248
11249 ASSERT_NO_FATAL_FAILURE(InitState());
11250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11251
11252 std::vector<const char *> device_extension_names;
11253 auto features = m_device->phy().features();
11254 // Make sure gs & ts are disabled
11255 features.geometryShader = false;
11256 features.tessellationShader = false;
11257 // The sacrificial device object
11258 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11259
11260 VkCommandPoolCreateInfo pool_create_info{};
11261 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11262 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11263
11264 VkCommandPool command_pool;
11265 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11266
11267 VkCommandBufferAllocateInfo cmd = {};
11268 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11269 cmd.pNext = NULL;
11270 cmd.commandPool = command_pool;
11271 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11272 cmd.commandBufferCount = 1;
11273
11274 VkCommandBuffer cmd_buffer;
11275 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11276 ASSERT_VK_SUCCESS(err);
11277
11278 VkEvent event;
11279 VkEventCreateInfo evci = {};
11280 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11281 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11282 ASSERT_VK_SUCCESS(result);
11283
11284 VkCommandBufferBeginInfo cbbi = {};
11285 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11286 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11288 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11289 m_errorMonitor->VerifyFound();
11290
11291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11292 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11293 m_errorMonitor->VerifyFound();
11294
11295 vkDestroyEvent(test_device.handle(), event, NULL);
11296 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11297}
11298
Mark Mueller917f6bc2016-08-30 10:57:19 -060011299TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011300 TEST_DESCRIPTION(
11301 "Use vkCmdExecuteCommands with invalid state "
11302 "in primary and secondary command buffers. "
11303 "Delete objects that are inuse. Call VkQueueSubmit "
11304 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011305
11306 ASSERT_NO_FATAL_FAILURE(InitState());
11307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11308
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011309 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011310 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011311
Tony Barbour552f6c02016-12-21 14:34:07 -070011312 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011313
11314 VkEvent event;
11315 VkEventCreateInfo event_create_info = {};
11316 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11317 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011318 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011319
Tony Barbour552f6c02016-12-21 14:34:07 -070011320 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011321 vkDestroyEvent(m_device->device(), event, nullptr);
11322
11323 VkSubmitInfo submit_info = {};
11324 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11325 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011326 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011328 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11329 m_errorMonitor->VerifyFound();
11330
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011331 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011332 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11333
11334 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11335
Mark Mueller917f6bc2016-08-30 10:57:19 -060011336 VkSemaphoreCreateInfo semaphore_create_info = {};
11337 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11338 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011339 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011340 VkFenceCreateInfo fence_create_info = {};
11341 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11342 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011343 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011344
11345 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011346 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011347 descriptor_pool_type_count.descriptorCount = 1;
11348
11349 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11350 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11351 descriptor_pool_create_info.maxSets = 1;
11352 descriptor_pool_create_info.poolSizeCount = 1;
11353 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011354 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011355
11356 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011357 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011358
11359 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011360 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011361 descriptorset_layout_binding.descriptorCount = 1;
11362 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11363
11364 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011365 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011366 descriptorset_layout_create_info.bindingCount = 1;
11367 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11368
11369 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011370 ASSERT_VK_SUCCESS(
11371 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011372
11373 VkDescriptorSet descriptorset;
11374 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011375 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011376 descriptorset_allocate_info.descriptorSetCount = 1;
11377 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11378 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011379 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011380
Mark Mueller4042b652016-09-05 22:52:21 -060011381 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11382
11383 VkDescriptorBufferInfo buffer_info = {};
11384 buffer_info.buffer = buffer_test.GetBuffer();
11385 buffer_info.offset = 0;
11386 buffer_info.range = 1024;
11387
11388 VkWriteDescriptorSet write_descriptor_set = {};
11389 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11390 write_descriptor_set.dstSet = descriptorset;
11391 write_descriptor_set.descriptorCount = 1;
11392 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11393 write_descriptor_set.pBufferInfo = &buffer_info;
11394
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011395 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011396
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011397 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11398 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011399
11400 VkPipelineObj pipe(m_device);
11401 pipe.AddColorAttachment();
11402 pipe.AddShader(&vs);
11403 pipe.AddShader(&fs);
11404
11405 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011406 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011407 pipeline_layout_create_info.setLayoutCount = 1;
11408 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11409
11410 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011411 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011412
11413 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11414
Tony Barbour552f6c02016-12-21 14:34:07 -070011415 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011416 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011418 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11419 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11420 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011421
Tony Barbour552f6c02016-12-21 14:34:07 -070011422 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011423
Mark Mueller917f6bc2016-08-30 10:57:19 -060011424 submit_info.signalSemaphoreCount = 1;
11425 submit_info.pSignalSemaphores = &semaphore;
11426 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011427 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011428
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011430 vkDestroyEvent(m_device->device(), event, nullptr);
11431 m_errorMonitor->VerifyFound();
11432
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011434 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11435 m_errorMonitor->VerifyFound();
11436
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011438 vkDestroyFence(m_device->device(), fence, nullptr);
11439 m_errorMonitor->VerifyFound();
11440
Tobin Ehlis122207b2016-09-01 08:50:06 -070011441 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011442 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11443 vkDestroyFence(m_device->device(), fence, nullptr);
11444 vkDestroyEvent(m_device->device(), event, nullptr);
11445 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011446 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011447 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11448}
11449
Tobin Ehlis2adda372016-09-01 08:51:06 -070011450TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11451 TEST_DESCRIPTION("Delete in-use query pool.");
11452
11453 ASSERT_NO_FATAL_FAILURE(InitState());
11454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11455
11456 VkQueryPool query_pool;
11457 VkQueryPoolCreateInfo query_pool_ci{};
11458 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11459 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11460 query_pool_ci.queryCount = 1;
11461 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011462 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011463 // Reset query pool to create binding with cmd buffer
11464 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11465
Tony Barbour552f6c02016-12-21 14:34:07 -070011466 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011467
11468 VkSubmitInfo submit_info = {};
11469 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11470 submit_info.commandBufferCount = 1;
11471 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11472 // Submit cmd buffer and then destroy query pool while in-flight
11473 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11474
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011476 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11477 m_errorMonitor->VerifyFound();
11478
11479 vkQueueWaitIdle(m_device->m_queue);
11480 // Now that cmd buffer done we can safely destroy query_pool
11481 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11482}
11483
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011484TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11485 TEST_DESCRIPTION("Delete in-use pipeline.");
11486
11487 ASSERT_NO_FATAL_FAILURE(InitState());
11488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11489
11490 // Empty pipeline layout used for binding PSO
11491 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11492 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11493 pipeline_layout_ci.setLayoutCount = 0;
11494 pipeline_layout_ci.pSetLayouts = NULL;
11495
11496 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011497 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011498 ASSERT_VK_SUCCESS(err);
11499
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011501 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011502 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11503 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011504 // Store pipeline handle so we can actually delete it before test finishes
11505 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011506 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011507 VkPipelineObj pipe(m_device);
11508 pipe.AddShader(&vs);
11509 pipe.AddShader(&fs);
11510 pipe.AddColorAttachment();
11511 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11512 delete_this_pipeline = pipe.handle();
11513
Tony Barbour552f6c02016-12-21 14:34:07 -070011514 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011515 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011516 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011517
Tony Barbour552f6c02016-12-21 14:34:07 -070011518 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011519
11520 VkSubmitInfo submit_info = {};
11521 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11522 submit_info.commandBufferCount = 1;
11523 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11524 // Submit cmd buffer and then pipeline destroyed while in-flight
11525 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011526 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011527 m_errorMonitor->VerifyFound();
11528 // Make sure queue finished and then actually delete pipeline
11529 vkQueueWaitIdle(m_device->m_queue);
11530 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11531 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11532}
11533
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011534TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11535 TEST_DESCRIPTION("Delete in-use imageView.");
11536
11537 ASSERT_NO_FATAL_FAILURE(InitState());
11538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11539
11540 VkDescriptorPoolSize ds_type_count;
11541 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11542 ds_type_count.descriptorCount = 1;
11543
11544 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11545 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11546 ds_pool_ci.maxSets = 1;
11547 ds_pool_ci.poolSizeCount = 1;
11548 ds_pool_ci.pPoolSizes = &ds_type_count;
11549
11550 VkDescriptorPool ds_pool;
11551 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11552 ASSERT_VK_SUCCESS(err);
11553
11554 VkSamplerCreateInfo sampler_ci = {};
11555 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11556 sampler_ci.pNext = NULL;
11557 sampler_ci.magFilter = VK_FILTER_NEAREST;
11558 sampler_ci.minFilter = VK_FILTER_NEAREST;
11559 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11560 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11561 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11562 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11563 sampler_ci.mipLodBias = 1.0;
11564 sampler_ci.anisotropyEnable = VK_FALSE;
11565 sampler_ci.maxAnisotropy = 1;
11566 sampler_ci.compareEnable = VK_FALSE;
11567 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11568 sampler_ci.minLod = 1.0;
11569 sampler_ci.maxLod = 1.0;
11570 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11571 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11572 VkSampler sampler;
11573
11574 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11575 ASSERT_VK_SUCCESS(err);
11576
11577 VkDescriptorSetLayoutBinding layout_binding;
11578 layout_binding.binding = 0;
11579 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11580 layout_binding.descriptorCount = 1;
11581 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11582 layout_binding.pImmutableSamplers = NULL;
11583
11584 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11585 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11586 ds_layout_ci.bindingCount = 1;
11587 ds_layout_ci.pBindings = &layout_binding;
11588 VkDescriptorSetLayout ds_layout;
11589 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11590 ASSERT_VK_SUCCESS(err);
11591
11592 VkDescriptorSetAllocateInfo alloc_info = {};
11593 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11594 alloc_info.descriptorSetCount = 1;
11595 alloc_info.descriptorPool = ds_pool;
11596 alloc_info.pSetLayouts = &ds_layout;
11597 VkDescriptorSet descriptor_set;
11598 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11599 ASSERT_VK_SUCCESS(err);
11600
11601 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11602 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11603 pipeline_layout_ci.pNext = NULL;
11604 pipeline_layout_ci.setLayoutCount = 1;
11605 pipeline_layout_ci.pSetLayouts = &ds_layout;
11606
11607 VkPipelineLayout pipeline_layout;
11608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11609 ASSERT_VK_SUCCESS(err);
11610
11611 VkImageObj image(m_device);
11612 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11613 ASSERT_TRUE(image.initialized());
11614
11615 VkImageView view;
11616 VkImageViewCreateInfo ivci = {};
11617 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11618 ivci.image = image.handle();
11619 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11620 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11621 ivci.subresourceRange.layerCount = 1;
11622 ivci.subresourceRange.baseMipLevel = 0;
11623 ivci.subresourceRange.levelCount = 1;
11624 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11625
11626 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11627 ASSERT_VK_SUCCESS(err);
11628
11629 VkDescriptorImageInfo image_info{};
11630 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11631 image_info.imageView = view;
11632 image_info.sampler = sampler;
11633
11634 VkWriteDescriptorSet descriptor_write = {};
11635 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11636 descriptor_write.dstSet = descriptor_set;
11637 descriptor_write.dstBinding = 0;
11638 descriptor_write.descriptorCount = 1;
11639 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11640 descriptor_write.pImageInfo = &image_info;
11641
11642 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11643
11644 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011645 char const *vsSource =
11646 "#version 450\n"
11647 "\n"
11648 "out gl_PerVertex { \n"
11649 " vec4 gl_Position;\n"
11650 "};\n"
11651 "void main(){\n"
11652 " gl_Position = vec4(1);\n"
11653 "}\n";
11654 char const *fsSource =
11655 "#version 450\n"
11656 "\n"
11657 "layout(set=0, binding=0) uniform sampler2D s;\n"
11658 "layout(location=0) out vec4 x;\n"
11659 "void main(){\n"
11660 " x = texture(s, vec2(1));\n"
11661 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011662 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11663 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11664 VkPipelineObj pipe(m_device);
11665 pipe.AddShader(&vs);
11666 pipe.AddShader(&fs);
11667 pipe.AddColorAttachment();
11668 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11669
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011671
Tony Barbour552f6c02016-12-21 14:34:07 -070011672 m_commandBuffer->BeginCommandBuffer();
11673 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011674 // Bind pipeline to cmd buffer
11675 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11676 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11677 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070011678
11679 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11680 VkRect2D scissor = {{0, 0}, {16, 16}};
11681 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11682 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11683
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011684 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011685 m_commandBuffer->EndRenderPass();
11686 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011687 // Submit cmd buffer then destroy sampler
11688 VkSubmitInfo submit_info = {};
11689 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11690 submit_info.commandBufferCount = 1;
11691 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11692 // Submit cmd buffer and then destroy imageView while in-flight
11693 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11694
11695 vkDestroyImageView(m_device->device(), view, nullptr);
11696 m_errorMonitor->VerifyFound();
11697 vkQueueWaitIdle(m_device->m_queue);
11698 // Now we can actually destroy imageView
11699 vkDestroyImageView(m_device->device(), view, NULL);
11700 vkDestroySampler(m_device->device(), sampler, nullptr);
11701 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11702 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11703 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11704}
11705
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011706TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11707 TEST_DESCRIPTION("Delete in-use bufferView.");
11708
11709 ASSERT_NO_FATAL_FAILURE(InitState());
11710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11711
11712 VkDescriptorPoolSize ds_type_count;
11713 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11714 ds_type_count.descriptorCount = 1;
11715
11716 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11717 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11718 ds_pool_ci.maxSets = 1;
11719 ds_pool_ci.poolSizeCount = 1;
11720 ds_pool_ci.pPoolSizes = &ds_type_count;
11721
11722 VkDescriptorPool ds_pool;
11723 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11724 ASSERT_VK_SUCCESS(err);
11725
11726 VkDescriptorSetLayoutBinding layout_binding;
11727 layout_binding.binding = 0;
11728 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11729 layout_binding.descriptorCount = 1;
11730 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11731 layout_binding.pImmutableSamplers = NULL;
11732
11733 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11734 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11735 ds_layout_ci.bindingCount = 1;
11736 ds_layout_ci.pBindings = &layout_binding;
11737 VkDescriptorSetLayout ds_layout;
11738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11739 ASSERT_VK_SUCCESS(err);
11740
11741 VkDescriptorSetAllocateInfo alloc_info = {};
11742 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11743 alloc_info.descriptorSetCount = 1;
11744 alloc_info.descriptorPool = ds_pool;
11745 alloc_info.pSetLayouts = &ds_layout;
11746 VkDescriptorSet descriptor_set;
11747 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11748 ASSERT_VK_SUCCESS(err);
11749
11750 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11751 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11752 pipeline_layout_ci.pNext = NULL;
11753 pipeline_layout_ci.setLayoutCount = 1;
11754 pipeline_layout_ci.pSetLayouts = &ds_layout;
11755
11756 VkPipelineLayout pipeline_layout;
11757 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11758 ASSERT_VK_SUCCESS(err);
11759
11760 VkBuffer buffer;
11761 uint32_t queue_family_index = 0;
11762 VkBufferCreateInfo buffer_create_info = {};
11763 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11764 buffer_create_info.size = 1024;
11765 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11766 buffer_create_info.queueFamilyIndexCount = 1;
11767 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11768
11769 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11770 ASSERT_VK_SUCCESS(err);
11771
11772 VkMemoryRequirements memory_reqs;
11773 VkDeviceMemory buffer_memory;
11774
11775 VkMemoryAllocateInfo memory_info = {};
11776 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11777 memory_info.allocationSize = 0;
11778 memory_info.memoryTypeIndex = 0;
11779
11780 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11781 memory_info.allocationSize = memory_reqs.size;
11782 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11783 ASSERT_TRUE(pass);
11784
11785 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11786 ASSERT_VK_SUCCESS(err);
11787 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11788 ASSERT_VK_SUCCESS(err);
11789
11790 VkBufferView view;
11791 VkBufferViewCreateInfo bvci = {};
11792 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11793 bvci.buffer = buffer;
11794 bvci.format = VK_FORMAT_R8_UNORM;
11795 bvci.range = VK_WHOLE_SIZE;
11796
11797 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11798 ASSERT_VK_SUCCESS(err);
11799
11800 VkWriteDescriptorSet descriptor_write = {};
11801 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11802 descriptor_write.dstSet = descriptor_set;
11803 descriptor_write.dstBinding = 0;
11804 descriptor_write.descriptorCount = 1;
11805 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11806 descriptor_write.pTexelBufferView = &view;
11807
11808 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11809
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011810 char const *vsSource =
11811 "#version 450\n"
11812 "\n"
11813 "out gl_PerVertex { \n"
11814 " vec4 gl_Position;\n"
11815 "};\n"
11816 "void main(){\n"
11817 " gl_Position = vec4(1);\n"
11818 "}\n";
11819 char const *fsSource =
11820 "#version 450\n"
11821 "\n"
11822 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11823 "layout(location=0) out vec4 x;\n"
11824 "void main(){\n"
11825 " x = imageLoad(s, 0);\n"
11826 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011827 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11828 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11829 VkPipelineObj pipe(m_device);
11830 pipe.AddShader(&vs);
11831 pipe.AddShader(&fs);
11832 pipe.AddColorAttachment();
11833 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11834
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011836
Tony Barbour552f6c02016-12-21 14:34:07 -070011837 m_commandBuffer->BeginCommandBuffer();
11838 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011839 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11840 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11841 VkRect2D scissor = {{0, 0}, {16, 16}};
11842 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11843 // Bind pipeline to cmd buffer
11844 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11845 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11846 &descriptor_set, 0, nullptr);
11847 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011848 m_commandBuffer->EndRenderPass();
11849 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011850
11851 VkSubmitInfo submit_info = {};
11852 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11853 submit_info.commandBufferCount = 1;
11854 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11855 // Submit cmd buffer and then destroy bufferView while in-flight
11856 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11857
11858 vkDestroyBufferView(m_device->device(), view, nullptr);
11859 m_errorMonitor->VerifyFound();
11860 vkQueueWaitIdle(m_device->m_queue);
11861 // Now we can actually destroy bufferView
11862 vkDestroyBufferView(m_device->device(), view, NULL);
11863 vkDestroyBuffer(m_device->device(), buffer, NULL);
11864 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11865 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11866 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11867 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11868}
11869
Tobin Ehlis209532e2016-09-07 13:52:18 -060011870TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11871 TEST_DESCRIPTION("Delete in-use sampler.");
11872
11873 ASSERT_NO_FATAL_FAILURE(InitState());
11874 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11875
11876 VkDescriptorPoolSize ds_type_count;
11877 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11878 ds_type_count.descriptorCount = 1;
11879
11880 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11881 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11882 ds_pool_ci.maxSets = 1;
11883 ds_pool_ci.poolSizeCount = 1;
11884 ds_pool_ci.pPoolSizes = &ds_type_count;
11885
11886 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011887 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011888 ASSERT_VK_SUCCESS(err);
11889
11890 VkSamplerCreateInfo sampler_ci = {};
11891 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11892 sampler_ci.pNext = NULL;
11893 sampler_ci.magFilter = VK_FILTER_NEAREST;
11894 sampler_ci.minFilter = VK_FILTER_NEAREST;
11895 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11896 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11897 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11898 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11899 sampler_ci.mipLodBias = 1.0;
11900 sampler_ci.anisotropyEnable = VK_FALSE;
11901 sampler_ci.maxAnisotropy = 1;
11902 sampler_ci.compareEnable = VK_FALSE;
11903 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11904 sampler_ci.minLod = 1.0;
11905 sampler_ci.maxLod = 1.0;
11906 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11907 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11908 VkSampler sampler;
11909
11910 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11911 ASSERT_VK_SUCCESS(err);
11912
11913 VkDescriptorSetLayoutBinding layout_binding;
11914 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011915 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011916 layout_binding.descriptorCount = 1;
11917 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11918 layout_binding.pImmutableSamplers = NULL;
11919
11920 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11921 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11922 ds_layout_ci.bindingCount = 1;
11923 ds_layout_ci.pBindings = &layout_binding;
11924 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011925 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011926 ASSERT_VK_SUCCESS(err);
11927
11928 VkDescriptorSetAllocateInfo alloc_info = {};
11929 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11930 alloc_info.descriptorSetCount = 1;
11931 alloc_info.descriptorPool = ds_pool;
11932 alloc_info.pSetLayouts = &ds_layout;
11933 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011934 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011935 ASSERT_VK_SUCCESS(err);
11936
11937 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11938 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11939 pipeline_layout_ci.pNext = NULL;
11940 pipeline_layout_ci.setLayoutCount = 1;
11941 pipeline_layout_ci.pSetLayouts = &ds_layout;
11942
11943 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011944 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011945 ASSERT_VK_SUCCESS(err);
11946
11947 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011948 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 -060011949 ASSERT_TRUE(image.initialized());
11950
11951 VkImageView view;
11952 VkImageViewCreateInfo ivci = {};
11953 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11954 ivci.image = image.handle();
11955 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11956 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11957 ivci.subresourceRange.layerCount = 1;
11958 ivci.subresourceRange.baseMipLevel = 0;
11959 ivci.subresourceRange.levelCount = 1;
11960 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11961
11962 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11963 ASSERT_VK_SUCCESS(err);
11964
11965 VkDescriptorImageInfo image_info{};
11966 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11967 image_info.imageView = view;
11968 image_info.sampler = sampler;
11969
11970 VkWriteDescriptorSet descriptor_write = {};
11971 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11972 descriptor_write.dstSet = descriptor_set;
11973 descriptor_write.dstBinding = 0;
11974 descriptor_write.descriptorCount = 1;
11975 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11976 descriptor_write.pImageInfo = &image_info;
11977
11978 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11979
11980 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011981 char const *vsSource =
11982 "#version 450\n"
11983 "\n"
11984 "out gl_PerVertex { \n"
11985 " vec4 gl_Position;\n"
11986 "};\n"
11987 "void main(){\n"
11988 " gl_Position = vec4(1);\n"
11989 "}\n";
11990 char const *fsSource =
11991 "#version 450\n"
11992 "\n"
11993 "layout(set=0, binding=0) uniform sampler2D s;\n"
11994 "layout(location=0) out vec4 x;\n"
11995 "void main(){\n"
11996 " x = texture(s, vec2(1));\n"
11997 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060011998 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11999 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12000 VkPipelineObj pipe(m_device);
12001 pipe.AddShader(&vs);
12002 pipe.AddShader(&fs);
12003 pipe.AddColorAttachment();
12004 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12005
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012007
Tony Barbour552f6c02016-12-21 14:34:07 -070012008 m_commandBuffer->BeginCommandBuffer();
12009 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012010 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012011 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12012 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12013 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012014
12015 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12016 VkRect2D scissor = {{0, 0}, {16, 16}};
12017 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12018 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12019
Tobin Ehlis209532e2016-09-07 13:52:18 -060012020 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012021 m_commandBuffer->EndRenderPass();
12022 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012023 // Submit cmd buffer then destroy sampler
12024 VkSubmitInfo submit_info = {};
12025 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12026 submit_info.commandBufferCount = 1;
12027 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12028 // Submit cmd buffer and then destroy sampler while in-flight
12029 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12030
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012031 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012032 m_errorMonitor->VerifyFound();
12033 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012034
Tobin Ehlis209532e2016-09-07 13:52:18 -060012035 // Now we can actually destroy sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012036 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012037 vkDestroyImageView(m_device->device(), view, NULL);
12038 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12039 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12040 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12041}
12042
Mark Mueller1cd9f412016-08-25 13:23:52 -060012043TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012044 TEST_DESCRIPTION(
12045 "Call VkQueueSubmit with a semaphore that is already "
12046 "signaled but not waited on by the queue. Wait on a "
12047 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012048
12049 ASSERT_NO_FATAL_FAILURE(InitState());
12050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12051
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012052 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 -070012053 const char *invalid_fence_wait_message =
12054 " which has not been submitted on a Queue or during "
12055 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012056
Tony Barbour552f6c02016-12-21 14:34:07 -070012057 m_commandBuffer->BeginCommandBuffer();
12058 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012059
12060 VkSemaphoreCreateInfo semaphore_create_info = {};
12061 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12062 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012063 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012064 VkSubmitInfo submit_info = {};
12065 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12066 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012067 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012068 submit_info.signalSemaphoreCount = 1;
12069 submit_info.pSignalSemaphores = &semaphore;
12070 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012071 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012072 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012073 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012074 m_commandBuffer->BeginCommandBuffer();
12075 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012077 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12078 m_errorMonitor->VerifyFound();
12079
Mark Mueller1cd9f412016-08-25 13:23:52 -060012080 VkFenceCreateInfo fence_create_info = {};
12081 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12082 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012083 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012084
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012086 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12087 m_errorMonitor->VerifyFound();
12088
Mark Mueller4042b652016-09-05 22:52:21 -060012089 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012090 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012091 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12092}
12093
Tobin Ehlis4af23302016-07-19 10:50:30 -060012094TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012095 TEST_DESCRIPTION(
12096 "Bind a secondary command buffer with with a framebuffer "
12097 "that does not match the framebuffer for the active "
12098 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012099 ASSERT_NO_FATAL_FAILURE(InitState());
12100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12101
12102 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012103 VkAttachmentDescription attachment = {0,
12104 VK_FORMAT_B8G8R8A8_UNORM,
12105 VK_SAMPLE_COUNT_1_BIT,
12106 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12107 VK_ATTACHMENT_STORE_OP_STORE,
12108 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12109 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12110 VK_IMAGE_LAYOUT_UNDEFINED,
12111 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012113 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012114
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012115 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012117 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012118
12119 VkRenderPass rp;
12120 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12121 ASSERT_VK_SUCCESS(err);
12122
12123 // A compatible framebuffer.
12124 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012125 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 -060012126 ASSERT_TRUE(image.initialized());
12127
12128 VkImageViewCreateInfo ivci = {
12129 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12130 nullptr,
12131 0,
12132 image.handle(),
12133 VK_IMAGE_VIEW_TYPE_2D,
12134 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012135 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12136 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012137 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12138 };
12139 VkImageView view;
12140 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12141 ASSERT_VK_SUCCESS(err);
12142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012143 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012144 VkFramebuffer fb;
12145 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12146 ASSERT_VK_SUCCESS(err);
12147
12148 VkCommandBufferAllocateInfo cbai = {};
12149 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12150 cbai.commandPool = m_commandPool;
12151 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12152 cbai.commandBufferCount = 1;
12153
12154 VkCommandBuffer sec_cb;
12155 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12156 ASSERT_VK_SUCCESS(err);
12157 VkCommandBufferBeginInfo cbbi = {};
12158 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012159 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012160 cbii.renderPass = renderPass();
12161 cbii.framebuffer = fb;
12162 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12163 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012164 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 -060012165 cbbi.pInheritanceInfo = &cbii;
12166 vkBeginCommandBuffer(sec_cb, &cbbi);
12167 vkEndCommandBuffer(sec_cb);
12168
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012169 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120012170 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12171 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012174 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012175 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12176 m_errorMonitor->VerifyFound();
12177 // Cleanup
12178 vkDestroyImageView(m_device->device(), view, NULL);
12179 vkDestroyRenderPass(m_device->device(), rp, NULL);
12180 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12181}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012182
12183TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012184 TEST_DESCRIPTION(
12185 "If logicOp is available on the device, set it to an "
12186 "invalid value. If logicOp is not available, attempt to "
12187 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012188 ASSERT_NO_FATAL_FAILURE(InitState());
12189 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12190
12191 auto features = m_device->phy().features();
12192 // Set the expected error depending on whether or not logicOp available
12193 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12195 "If logic operations feature not "
12196 "enabled, logicOpEnable must be "
12197 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012198 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012200 }
12201 // Create a pipeline using logicOp
12202 VkResult err;
12203
12204 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12205 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12206
12207 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012208 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012209 ASSERT_VK_SUCCESS(err);
12210
12211 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12212 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12213 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012214 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012215 vp_state_ci.pViewports = &vp;
12216 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012217 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012218 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012219
12220 VkPipelineShaderStageCreateInfo shaderStages[2];
12221 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012223 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12224 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012225 shaderStages[0] = vs.GetStageCreateInfo();
12226 shaderStages[1] = fs.GetStageCreateInfo();
12227
12228 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12229 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12230
12231 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12232 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12233 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12234
12235 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12236 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012237 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012238
12239 VkPipelineColorBlendAttachmentState att = {};
12240 att.blendEnable = VK_FALSE;
12241 att.colorWriteMask = 0xf;
12242
12243 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12244 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12245 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12246 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012247 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012248 cb_ci.attachmentCount = 1;
12249 cb_ci.pAttachments = &att;
12250
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012251 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12252 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12253 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12254
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012255 VkGraphicsPipelineCreateInfo gp_ci = {};
12256 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12257 gp_ci.stageCount = 2;
12258 gp_ci.pStages = shaderStages;
12259 gp_ci.pVertexInputState = &vi_ci;
12260 gp_ci.pInputAssemblyState = &ia_ci;
12261 gp_ci.pViewportState = &vp_state_ci;
12262 gp_ci.pRasterizationState = &rs_ci;
12263 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012264 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012265 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12266 gp_ci.layout = pipeline_layout;
12267 gp_ci.renderPass = renderPass();
12268
12269 VkPipelineCacheCreateInfo pc_ci = {};
12270 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12271
12272 VkPipeline pipeline;
12273 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012274 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012275 ASSERT_VK_SUCCESS(err);
12276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012277 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012278 m_errorMonitor->VerifyFound();
12279 if (VK_SUCCESS == err) {
12280 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12281 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012282 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12283 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12284}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012285#endif // DRAW_STATE_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012286
Tobin Ehlis0788f522015-05-26 16:11:58 -060012287#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012288#if GTEST_IS_THREADSAFE
12289struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012290 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012291 VkEvent event;
12292 bool bailout;
12293};
12294
Karl Schultz6addd812016-02-02 17:17:23 -070012295extern "C" void *AddToCommandBuffer(void *arg) {
12296 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012297
Mike Stroyana6d14942016-07-13 15:10:05 -060012298 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012299 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012300 if (data->bailout) {
12301 break;
12302 }
12303 }
12304 return NULL;
12305}
12306
Karl Schultz6addd812016-02-02 17:17:23 -070012307TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012308 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012309
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012311
Mike Stroyanaccf7692015-05-12 16:00:45 -060012312 ASSERT_NO_FATAL_FAILURE(InitState());
12313 ASSERT_NO_FATAL_FAILURE(InitViewport());
12314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12315
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012316 // Calls AllocateCommandBuffers
12317 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012318
12319 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012320 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012321
12322 VkEventCreateInfo event_info;
12323 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012324 VkResult err;
12325
12326 memset(&event_info, 0, sizeof(event_info));
12327 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12328
Chia-I Wuf7458c52015-10-26 21:10:41 +080012329 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012330 ASSERT_VK_SUCCESS(err);
12331
Mike Stroyanaccf7692015-05-12 16:00:45 -060012332 err = vkResetEvent(device(), event);
12333 ASSERT_VK_SUCCESS(err);
12334
12335 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012336 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012337 data.event = event;
12338 data.bailout = false;
12339 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012340
12341 // First do some correct operations using multiple threads.
12342 // Add many entries to command buffer from another thread.
12343 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12344 // Make non-conflicting calls from this thread at the same time.
12345 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012346 uint32_t count;
12347 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012348 }
12349 test_platform_thread_join(thread, NULL);
12350
12351 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012352 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012353 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012354 // Add many entries to command buffer from this thread at the same time.
12355 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012356
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012357 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012358 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012359
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012360 m_errorMonitor->SetBailout(NULL);
12361
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012362 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012363
Chia-I Wuf7458c52015-10-26 21:10:41 +080012364 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012365}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012366#endif // GTEST_IS_THREADSAFE
12367#endif // THREADING_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012368
Chris Forbes9f7ff632015-05-25 11:13:08 +120012369#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012370TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012371 TEST_DESCRIPTION(
12372 "Test that an error is produced for a spirv module "
12373 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120012374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012376
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012377 ASSERT_NO_FATAL_FAILURE(InitState());
12378 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12379
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012380 VkShaderModule module;
12381 VkShaderModuleCreateInfo moduleCreateInfo;
12382 struct icd_spv_header spv;
12383
12384 spv.magic = ICD_SPV_MAGIC;
12385 spv.version = ICD_SPV_VERSION;
12386 spv.gen_magic = 0;
12387
12388 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12389 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012390 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012391 moduleCreateInfo.codeSize = 4;
12392 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012393 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012394
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012395 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012396}
12397
Karl Schultz6addd812016-02-02 17:17:23 -070012398TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012399 TEST_DESCRIPTION(
12400 "Test that an error is produced for a spirv module "
12401 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120012402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012404
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012405 ASSERT_NO_FATAL_FAILURE(InitState());
12406 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12407
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012408 VkShaderModule module;
12409 VkShaderModuleCreateInfo moduleCreateInfo;
12410 struct icd_spv_header spv;
12411
12412 spv.magic = ~ICD_SPV_MAGIC;
12413 spv.version = ICD_SPV_VERSION;
12414 spv.gen_magic = 0;
12415
12416 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12417 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012418 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012419 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12420 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012421 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012422
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012423 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012424}
12425
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012426#if 0
12427// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012428TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012430 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012431
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012432 ASSERT_NO_FATAL_FAILURE(InitState());
12433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12434
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012435 VkShaderModule module;
12436 VkShaderModuleCreateInfo moduleCreateInfo;
12437 struct icd_spv_header spv;
12438
12439 spv.magic = ICD_SPV_MAGIC;
12440 spv.version = ~ICD_SPV_VERSION;
12441 spv.gen_magic = 0;
12442
12443 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12444 moduleCreateInfo.pNext = NULL;
12445
Karl Schultz6addd812016-02-02 17:17:23 -070012446 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012447 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12448 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012449 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012450
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012451 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012452}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012453#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012454
Karl Schultz6addd812016-02-02 17:17:23 -070012455TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012456 TEST_DESCRIPTION(
12457 "Test that a warning is produced for a vertex output that "
12458 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012460
Chris Forbes9f7ff632015-05-25 11:13:08 +120012461 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012462 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012463
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012464 char const *vsSource =
12465 "#version 450\n"
12466 "\n"
12467 "layout(location=0) out float x;\n"
12468 "out gl_PerVertex {\n"
12469 " vec4 gl_Position;\n"
12470 "};\n"
12471 "void main(){\n"
12472 " gl_Position = vec4(1);\n"
12473 " x = 0;\n"
12474 "}\n";
12475 char const *fsSource =
12476 "#version 450\n"
12477 "\n"
12478 "layout(location=0) out vec4 color;\n"
12479 "void main(){\n"
12480 " color = vec4(1);\n"
12481 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012482
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012483 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12484 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012485
12486 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012487 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012488 pipe.AddShader(&vs);
12489 pipe.AddShader(&fs);
12490
Chris Forbes9f7ff632015-05-25 11:13:08 +120012491 VkDescriptorSetObj descriptorSet(m_device);
12492 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012493 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012494
Tony Barbour5781e8f2015-08-04 16:23:11 -060012495 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012496
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012497 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012498}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012499
Mark Mueller098c9cb2016-09-08 09:01:57 -060012500TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12501 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12502
12503 ASSERT_NO_FATAL_FAILURE(InitState());
12504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12505
12506 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012507 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012508
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012509 char const *vsSource =
12510 "#version 450\n"
12511 "\n"
12512 "out gl_PerVertex {\n"
12513 " vec4 gl_Position;\n"
12514 "};\n"
12515 "void main(){\n"
12516 " gl_Position = vec4(1);\n"
12517 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012518
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012519 char const *fsSource =
12520 "#version 450\n"
12521 "\n"
12522 "layout (constant_id = 0) const float r = 0.0f;\n"
12523 "layout(location = 0) out vec4 uFragColor;\n"
12524 "void main(){\n"
12525 " uFragColor = vec4(r,1,0,1);\n"
12526 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012527
12528 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12529 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12530
12531 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12532 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12533
12534 VkPipelineLayout pipeline_layout;
12535 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12536
12537 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12538 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12539 vp_state_create_info.viewportCount = 1;
12540 VkViewport viewport = {};
12541 vp_state_create_info.pViewports = &viewport;
12542 vp_state_create_info.scissorCount = 1;
12543 VkRect2D scissors = {};
12544 vp_state_create_info.pScissors = &scissors;
12545
12546 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12547
12548 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12549 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12550 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12551 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12552
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012553 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060012554
12555 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12556 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12557
12558 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12559 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12560 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12561
12562 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12563 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12564 rasterization_state_create_info.pNext = nullptr;
12565 rasterization_state_create_info.lineWidth = 1.0f;
12566 rasterization_state_create_info.rasterizerDiscardEnable = true;
12567
12568 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12569 color_blend_attachment_state.blendEnable = VK_FALSE;
12570 color_blend_attachment_state.colorWriteMask = 0xf;
12571
12572 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12573 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12574 color_blend_state_create_info.attachmentCount = 1;
12575 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12576
12577 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12578 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12579 graphicspipe_create_info.stageCount = 2;
12580 graphicspipe_create_info.pStages = shader_stage_create_info;
12581 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12582 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12583 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12584 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12585 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12586 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12587 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12588 graphicspipe_create_info.layout = pipeline_layout;
12589 graphicspipe_create_info.renderPass = renderPass();
12590
12591 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12592 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12593
12594 VkPipelineCache pipelineCache;
12595 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12596
12597 // This structure maps constant ids to data locations.
12598 const VkSpecializationMapEntry entry =
12599 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012600 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060012601
12602 uint32_t data = 1;
12603
12604 // Set up the info describing spec map and data
12605 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012606 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060012607 };
12608 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12609
12610 VkPipeline pipeline;
12611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12612 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12613 m_errorMonitor->VerifyFound();
12614
12615 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12616 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12617}
12618
12619TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12620 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12621
12622 ASSERT_NO_FATAL_FAILURE(InitState());
12623 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12624
12625 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12626
12627 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12628 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12629 descriptor_pool_type_count[0].descriptorCount = 1;
12630 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12631 descriptor_pool_type_count[1].descriptorCount = 1;
12632
12633 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12634 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12635 descriptor_pool_create_info.maxSets = 1;
12636 descriptor_pool_create_info.poolSizeCount = 2;
12637 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12638 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12639
12640 VkDescriptorPool descriptorset_pool;
12641 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12642
12643 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12644 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12645 descriptorset_layout_binding.descriptorCount = 1;
12646 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12647
12648 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12649 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12650 descriptorset_layout_create_info.bindingCount = 1;
12651 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12652
12653 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012654 ASSERT_VK_SUCCESS(
12655 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012656
12657 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12658 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12659 descriptorset_allocate_info.descriptorSetCount = 1;
12660 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12661 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12662 VkDescriptorSet descriptorset;
12663 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12664
12665 // Challenge core_validation with a non uniform buffer type.
12666 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12667
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012668 char const *vsSource =
12669 "#version 450\n"
12670 "\n"
12671 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12672 " mat4 mvp;\n"
12673 "} ubuf;\n"
12674 "out gl_PerVertex {\n"
12675 " vec4 gl_Position;\n"
12676 "};\n"
12677 "void main(){\n"
12678 " gl_Position = ubuf.mvp * vec4(1);\n"
12679 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012680
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012681 char const *fsSource =
12682 "#version 450\n"
12683 "\n"
12684 "layout(location = 0) out vec4 uFragColor;\n"
12685 "void main(){\n"
12686 " uFragColor = vec4(0,1,0,1);\n"
12687 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012688
12689 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12690 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12691
12692 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12693 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12694 pipeline_layout_create_info.setLayoutCount = 1;
12695 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12696
12697 VkPipelineLayout pipeline_layout;
12698 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12699
12700 VkPipelineObj pipe(m_device);
12701 pipe.AddColorAttachment();
12702 pipe.AddShader(&vs);
12703 pipe.AddShader(&fs);
12704
12705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12706 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12707 m_errorMonitor->VerifyFound();
12708
12709 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12710 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12711 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12712}
12713
12714TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12715 TEST_DESCRIPTION(
12716 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12717
12718 ASSERT_NO_FATAL_FAILURE(InitState());
12719 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12720
12721 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12722
12723 VkDescriptorPoolSize descriptor_pool_type_count = {};
12724 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12725 descriptor_pool_type_count.descriptorCount = 1;
12726
12727 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12728 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12729 descriptor_pool_create_info.maxSets = 1;
12730 descriptor_pool_create_info.poolSizeCount = 1;
12731 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12732 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12733
12734 VkDescriptorPool descriptorset_pool;
12735 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12736
12737 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12738 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12739 descriptorset_layout_binding.descriptorCount = 1;
12740 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12741 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12742
12743 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12744 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12745 descriptorset_layout_create_info.bindingCount = 1;
12746 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12747
12748 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012749 ASSERT_VK_SUCCESS(
12750 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012751
12752 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12753 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12754 descriptorset_allocate_info.descriptorSetCount = 1;
12755 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12756 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12757 VkDescriptorSet descriptorset;
12758 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12759
12760 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12761
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012762 char const *vsSource =
12763 "#version 450\n"
12764 "\n"
12765 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12766 " mat4 mvp;\n"
12767 "} ubuf;\n"
12768 "out gl_PerVertex {\n"
12769 " vec4 gl_Position;\n"
12770 "};\n"
12771 "void main(){\n"
12772 " gl_Position = ubuf.mvp * vec4(1);\n"
12773 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012774
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012775 char const *fsSource =
12776 "#version 450\n"
12777 "\n"
12778 "layout(location = 0) out vec4 uFragColor;\n"
12779 "void main(){\n"
12780 " uFragColor = vec4(0,1,0,1);\n"
12781 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012782
12783 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12784 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12785
12786 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12787 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12788 pipeline_layout_create_info.setLayoutCount = 1;
12789 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12790
12791 VkPipelineLayout pipeline_layout;
12792 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12793
12794 VkPipelineObj pipe(m_device);
12795 pipe.AddColorAttachment();
12796 pipe.AddShader(&vs);
12797 pipe.AddShader(&fs);
12798
12799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12800 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12801 m_errorMonitor->VerifyFound();
12802
12803 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12804 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12805 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12806}
12807
12808TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012809 TEST_DESCRIPTION(
12810 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12811 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060012812
12813 ASSERT_NO_FATAL_FAILURE(InitState());
12814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12815
12816 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012817 "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 -060012818
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012819 char const *vsSource =
12820 "#version 450\n"
12821 "\n"
12822 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12823 "out gl_PerVertex {\n"
12824 " vec4 gl_Position;\n"
12825 "};\n"
12826 "void main(){\n"
12827 " gl_Position = vec4(consts.x);\n"
12828 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012829
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012830 char const *fsSource =
12831 "#version 450\n"
12832 "\n"
12833 "layout(location = 0) out vec4 uFragColor;\n"
12834 "void main(){\n"
12835 " uFragColor = vec4(0,1,0,1);\n"
12836 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012837
12838 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12839 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12840
12841 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12842 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12843
12844 // Set up a push constant range
12845 VkPushConstantRange push_constant_ranges = {};
12846 // Set to the wrong stage to challenge core_validation
12847 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12848 push_constant_ranges.size = 4;
12849
12850 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12851 pipeline_layout_create_info.pushConstantRangeCount = 1;
12852
12853 VkPipelineLayout pipeline_layout;
12854 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12855
12856 VkPipelineObj pipe(m_device);
12857 pipe.AddColorAttachment();
12858 pipe.AddShader(&vs);
12859 pipe.AddShader(&fs);
12860
12861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12862 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12863 m_errorMonitor->VerifyFound();
12864
12865 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12866}
12867
12868TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12869 TEST_DESCRIPTION(
12870 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12871
12872 ASSERT_NO_FATAL_FAILURE(InitState());
12873 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12874
12875 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012876 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012877
12878 // Some awkward steps are required to test with custom device features.
12879 std::vector<const char *> device_extension_names;
12880 auto features = m_device->phy().features();
12881 // Disable support for 64 bit floats
12882 features.shaderFloat64 = false;
12883 // The sacrificial device object
12884 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12885
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012886 char const *vsSource =
12887 "#version 450\n"
12888 "\n"
12889 "out gl_PerVertex {\n"
12890 " vec4 gl_Position;\n"
12891 "};\n"
12892 "void main(){\n"
12893 " gl_Position = vec4(1);\n"
12894 "}\n";
12895 char const *fsSource =
12896 "#version 450\n"
12897 "\n"
12898 "layout(location=0) out vec4 color;\n"
12899 "void main(){\n"
12900 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12901 " color = vec4(green);\n"
12902 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012903
12904 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12905 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12906
12907 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012908
12909 VkPipelineObj pipe(&test_device);
12910 pipe.AddColorAttachment();
12911 pipe.AddShader(&vs);
12912 pipe.AddShader(&fs);
12913
12914 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12915 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12916 VkPipelineLayout pipeline_layout;
12917 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12918
12919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12920 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12921 m_errorMonitor->VerifyFound();
12922
12923 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12924}
12925
12926TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12927 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12928
12929 ASSERT_NO_FATAL_FAILURE(InitState());
12930 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12931
12932 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12933
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012934 char const *vsSource =
12935 "#version 450\n"
12936 "\n"
12937 "out gl_PerVertex {\n"
12938 " vec4 gl_Position;\n"
12939 "};\n"
12940 "layout(xfb_buffer = 1) out;"
12941 "void main(){\n"
12942 " gl_Position = vec4(1);\n"
12943 "}\n";
12944 char const *fsSource =
12945 "#version 450\n"
12946 "\n"
12947 "layout(location=0) out vec4 color;\n"
12948 "void main(){\n"
12949 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12950 " color = vec4(green);\n"
12951 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012952
12953 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12954 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12955
12956 VkPipelineObj pipe(m_device);
12957 pipe.AddColorAttachment();
12958 pipe.AddShader(&vs);
12959 pipe.AddShader(&fs);
12960
12961 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12962 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12963 VkPipelineLayout pipeline_layout;
12964 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12965
12966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12967 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12968 m_errorMonitor->VerifyFound();
12969
12970 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12971}
12972
Karl Schultz6addd812016-02-02 17:17:23 -070012973TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012974 TEST_DESCRIPTION(
12975 "Test that an error is produced for a fragment shader input "
12976 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120012977
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012979
Chris Forbes59cb88d2015-05-25 11:13:13 +120012980 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012981 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012982
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012983 char const *vsSource =
12984 "#version 450\n"
12985 "\n"
12986 "out gl_PerVertex {\n"
12987 " vec4 gl_Position;\n"
12988 "};\n"
12989 "void main(){\n"
12990 " gl_Position = vec4(1);\n"
12991 "}\n";
12992 char const *fsSource =
12993 "#version 450\n"
12994 "\n"
12995 "layout(location=0) in float x;\n"
12996 "layout(location=0) out vec4 color;\n"
12997 "void main(){\n"
12998 " color = vec4(x);\n"
12999 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013000
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013001 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13002 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013003
13004 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013005 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013006 pipe.AddShader(&vs);
13007 pipe.AddShader(&fs);
13008
Chris Forbes59cb88d2015-05-25 11:13:13 +120013009 VkDescriptorSetObj descriptorSet(m_device);
13010 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013011 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013012
Tony Barbour5781e8f2015-08-04 16:23:11 -060013013 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013014
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013015 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013016}
13017
Karl Schultz6addd812016-02-02 17:17:23 -070013018TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013019 TEST_DESCRIPTION(
13020 "Test that an error is produced for a fragment shader input "
13021 "within an interace block, which is not present in the outputs "
13022 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013024
13025 ASSERT_NO_FATAL_FAILURE(InitState());
13026 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13027
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013028 char const *vsSource =
13029 "#version 450\n"
13030 "\n"
13031 "out gl_PerVertex {\n"
13032 " vec4 gl_Position;\n"
13033 "};\n"
13034 "void main(){\n"
13035 " gl_Position = vec4(1);\n"
13036 "}\n";
13037 char const *fsSource =
13038 "#version 450\n"
13039 "\n"
13040 "in block { layout(location=0) float x; } ins;\n"
13041 "layout(location=0) out vec4 color;\n"
13042 "void main(){\n"
13043 " color = vec4(ins.x);\n"
13044 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013045
13046 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13047 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13048
13049 VkPipelineObj pipe(m_device);
13050 pipe.AddColorAttachment();
13051 pipe.AddShader(&vs);
13052 pipe.AddShader(&fs);
13053
13054 VkDescriptorSetObj descriptorSet(m_device);
13055 descriptorSet.AppendDummy();
13056 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13057
13058 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13059
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013060 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013061}
13062
Karl Schultz6addd812016-02-02 17:17:23 -070013063TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013064 TEST_DESCRIPTION(
13065 "Test that an error is produced for mismatched array sizes "
13066 "across the vertex->fragment shader interface");
13067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13068 "Type mismatch on location 0.0: 'ptr to "
13069 "output arr[2] of float32' vs 'ptr to "
13070 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013071
13072 ASSERT_NO_FATAL_FAILURE(InitState());
13073 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13074
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013075 char const *vsSource =
13076 "#version 450\n"
13077 "\n"
13078 "layout(location=0) out float x[2];\n"
13079 "out gl_PerVertex {\n"
13080 " vec4 gl_Position;\n"
13081 "};\n"
13082 "void main(){\n"
13083 " x[0] = 0; x[1] = 0;\n"
13084 " gl_Position = vec4(1);\n"
13085 "}\n";
13086 char const *fsSource =
13087 "#version 450\n"
13088 "\n"
13089 "layout(location=0) in float x[1];\n"
13090 "layout(location=0) out vec4 color;\n"
13091 "void main(){\n"
13092 " color = vec4(x[0]);\n"
13093 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013094
13095 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13096 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13097
13098 VkPipelineObj pipe(m_device);
13099 pipe.AddColorAttachment();
13100 pipe.AddShader(&vs);
13101 pipe.AddShader(&fs);
13102
13103 VkDescriptorSetObj descriptorSet(m_device);
13104 descriptorSet.AppendDummy();
13105 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13106
13107 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13108
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013109 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013110}
13111
Karl Schultz6addd812016-02-02 17:17:23 -070013112TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013113 TEST_DESCRIPTION(
13114 "Test that an error is produced for mismatched types across "
13115 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013117
Chris Forbesb56af562015-05-25 11:13:17 +120013118 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013120
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013121 char const *vsSource =
13122 "#version 450\n"
13123 "\n"
13124 "layout(location=0) out int x;\n"
13125 "out gl_PerVertex {\n"
13126 " vec4 gl_Position;\n"
13127 "};\n"
13128 "void main(){\n"
13129 " x = 0;\n"
13130 " gl_Position = vec4(1);\n"
13131 "}\n";
13132 char const *fsSource =
13133 "#version 450\n"
13134 "\n"
13135 "layout(location=0) in float x;\n" /* VS writes int */
13136 "layout(location=0) out vec4 color;\n"
13137 "void main(){\n"
13138 " color = vec4(x);\n"
13139 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013140
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013141 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13142 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013143
13144 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013145 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013146 pipe.AddShader(&vs);
13147 pipe.AddShader(&fs);
13148
Chris Forbesb56af562015-05-25 11:13:17 +120013149 VkDescriptorSetObj descriptorSet(m_device);
13150 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013151 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013152
Tony Barbour5781e8f2015-08-04 16:23:11 -060013153 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013154
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013155 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013156}
13157
Karl Schultz6addd812016-02-02 17:17:23 -070013158TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013159 TEST_DESCRIPTION(
13160 "Test that an error is produced for mismatched types across "
13161 "the vertex->fragment shader interface, when the variable is contained within "
13162 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013164
13165 ASSERT_NO_FATAL_FAILURE(InitState());
13166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13167
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013168 char const *vsSource =
13169 "#version 450\n"
13170 "\n"
13171 "out block { layout(location=0) int x; } outs;\n"
13172 "out gl_PerVertex {\n"
13173 " vec4 gl_Position;\n"
13174 "};\n"
13175 "void main(){\n"
13176 " outs.x = 0;\n"
13177 " gl_Position = vec4(1);\n"
13178 "}\n";
13179 char const *fsSource =
13180 "#version 450\n"
13181 "\n"
13182 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13183 "layout(location=0) out vec4 color;\n"
13184 "void main(){\n"
13185 " color = vec4(ins.x);\n"
13186 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013187
13188 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13189 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13190
13191 VkPipelineObj pipe(m_device);
13192 pipe.AddColorAttachment();
13193 pipe.AddShader(&vs);
13194 pipe.AddShader(&fs);
13195
13196 VkDescriptorSetObj descriptorSet(m_device);
13197 descriptorSet.AppendDummy();
13198 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13199
13200 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13201
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013202 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013203}
13204
13205TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013206 TEST_DESCRIPTION(
13207 "Test that an error is produced for location mismatches across "
13208 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
13209 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013210 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 +130013211
13212 ASSERT_NO_FATAL_FAILURE(InitState());
13213 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13214
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013215 char const *vsSource =
13216 "#version 450\n"
13217 "\n"
13218 "out block { layout(location=1) float x; } outs;\n"
13219 "out gl_PerVertex {\n"
13220 " vec4 gl_Position;\n"
13221 "};\n"
13222 "void main(){\n"
13223 " outs.x = 0;\n"
13224 " gl_Position = vec4(1);\n"
13225 "}\n";
13226 char const *fsSource =
13227 "#version 450\n"
13228 "\n"
13229 "in block { layout(location=0) float x; } ins;\n"
13230 "layout(location=0) out vec4 color;\n"
13231 "void main(){\n"
13232 " color = vec4(ins.x);\n"
13233 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013234
13235 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13236 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13237
13238 VkPipelineObj pipe(m_device);
13239 pipe.AddColorAttachment();
13240 pipe.AddShader(&vs);
13241 pipe.AddShader(&fs);
13242
13243 VkDescriptorSetObj descriptorSet(m_device);
13244 descriptorSet.AppendDummy();
13245 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13246
13247 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13248
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013249 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013250}
13251
13252TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013253 TEST_DESCRIPTION(
13254 "Test that an error is produced for component mismatches across the "
13255 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
13256 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013257 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 +130013258
13259 ASSERT_NO_FATAL_FAILURE(InitState());
13260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13261
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013262 char const *vsSource =
13263 "#version 450\n"
13264 "\n"
13265 "out block { layout(location=0, component=0) float x; } outs;\n"
13266 "out gl_PerVertex {\n"
13267 " vec4 gl_Position;\n"
13268 "};\n"
13269 "void main(){\n"
13270 " outs.x = 0;\n"
13271 " gl_Position = vec4(1);\n"
13272 "}\n";
13273 char const *fsSource =
13274 "#version 450\n"
13275 "\n"
13276 "in block { layout(location=0, component=1) float x; } ins;\n"
13277 "layout(location=0) out vec4 color;\n"
13278 "void main(){\n"
13279 " color = vec4(ins.x);\n"
13280 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013281
13282 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13283 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13284
13285 VkPipelineObj pipe(m_device);
13286 pipe.AddColorAttachment();
13287 pipe.AddShader(&vs);
13288 pipe.AddShader(&fs);
13289
13290 VkDescriptorSetObj descriptorSet(m_device);
13291 descriptorSet.AppendDummy();
13292 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13293
13294 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13295
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013296 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013297}
13298
Chris Forbes1f3b0152016-11-30 12:48:40 +130013299TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13300 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13301
13302 ASSERT_NO_FATAL_FAILURE(InitState());
13303 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13304
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013305 char const *vsSource =
13306 "#version 450\n"
13307 "layout(location=0) out mediump float x;\n"
13308 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13309 char const *fsSource =
13310 "#version 450\n"
13311 "layout(location=0) in highp float x;\n"
13312 "layout(location=0) out vec4 color;\n"
13313 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130013314
13315 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13316 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13317
13318 VkPipelineObj pipe(m_device);
13319 pipe.AddColorAttachment();
13320 pipe.AddShader(&vs);
13321 pipe.AddShader(&fs);
13322
13323 VkDescriptorSetObj descriptorSet(m_device);
13324 descriptorSet.AppendDummy();
13325 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13326
13327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13328
13329 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13330
13331 m_errorMonitor->VerifyFound();
13332}
13333
Chris Forbes870a39e2016-11-30 12:55:56 +130013334TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13335 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13336
13337 ASSERT_NO_FATAL_FAILURE(InitState());
13338 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13339
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013340 char const *vsSource =
13341 "#version 450\n"
13342 "out block { layout(location=0) mediump float x; };\n"
13343 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13344 char const *fsSource =
13345 "#version 450\n"
13346 "in block { layout(location=0) highp float x; };\n"
13347 "layout(location=0) out vec4 color;\n"
13348 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130013349
13350 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13351 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13352
13353 VkPipelineObj pipe(m_device);
13354 pipe.AddColorAttachment();
13355 pipe.AddShader(&vs);
13356 pipe.AddShader(&fs);
13357
13358 VkDescriptorSetObj descriptorSet(m_device);
13359 descriptorSet.AppendDummy();
13360 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13361
13362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13363
13364 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13365
13366 m_errorMonitor->VerifyFound();
13367}
13368
Karl Schultz6addd812016-02-02 17:17:23 -070013369TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013370 TEST_DESCRIPTION(
13371 "Test that a warning is produced for a vertex attribute which is "
13372 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013374
Chris Forbesde136e02015-05-25 11:13:28 +120013375 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013376 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013377
13378 VkVertexInputBindingDescription input_binding;
13379 memset(&input_binding, 0, sizeof(input_binding));
13380
13381 VkVertexInputAttributeDescription input_attrib;
13382 memset(&input_attrib, 0, sizeof(input_attrib));
13383 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13384
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013385 char const *vsSource =
13386 "#version 450\n"
13387 "\n"
13388 "out gl_PerVertex {\n"
13389 " vec4 gl_Position;\n"
13390 "};\n"
13391 "void main(){\n"
13392 " gl_Position = vec4(1);\n"
13393 "}\n";
13394 char const *fsSource =
13395 "#version 450\n"
13396 "\n"
13397 "layout(location=0) out vec4 color;\n"
13398 "void main(){\n"
13399 " color = vec4(1);\n"
13400 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013401
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013402 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13403 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013404
13405 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013406 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013407 pipe.AddShader(&vs);
13408 pipe.AddShader(&fs);
13409
13410 pipe.AddVertexInputBindings(&input_binding, 1);
13411 pipe.AddVertexInputAttribs(&input_attrib, 1);
13412
Chris Forbesde136e02015-05-25 11:13:28 +120013413 VkDescriptorSetObj descriptorSet(m_device);
13414 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013415 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013416
Tony Barbour5781e8f2015-08-04 16:23:11 -060013417 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013418
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013419 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013420}
13421
Karl Schultz6addd812016-02-02 17:17:23 -070013422TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013423 TEST_DESCRIPTION(
13424 "Test that a warning is produced for a location mismatch on "
13425 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013427
13428 ASSERT_NO_FATAL_FAILURE(InitState());
13429 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13430
13431 VkVertexInputBindingDescription input_binding;
13432 memset(&input_binding, 0, sizeof(input_binding));
13433
13434 VkVertexInputAttributeDescription input_attrib;
13435 memset(&input_attrib, 0, sizeof(input_attrib));
13436 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13437
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013438 char const *vsSource =
13439 "#version 450\n"
13440 "\n"
13441 "layout(location=1) in float x;\n"
13442 "out gl_PerVertex {\n"
13443 " vec4 gl_Position;\n"
13444 "};\n"
13445 "void main(){\n"
13446 " gl_Position = vec4(x);\n"
13447 "}\n";
13448 char const *fsSource =
13449 "#version 450\n"
13450 "\n"
13451 "layout(location=0) out vec4 color;\n"
13452 "void main(){\n"
13453 " color = vec4(1);\n"
13454 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013455
13456 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13457 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13458
13459 VkPipelineObj pipe(m_device);
13460 pipe.AddColorAttachment();
13461 pipe.AddShader(&vs);
13462 pipe.AddShader(&fs);
13463
13464 pipe.AddVertexInputBindings(&input_binding, 1);
13465 pipe.AddVertexInputAttribs(&input_attrib, 1);
13466
13467 VkDescriptorSetObj descriptorSet(m_device);
13468 descriptorSet.AppendDummy();
13469 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13470
13471 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13472
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013473 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013474}
13475
Karl Schultz6addd812016-02-02 17:17:23 -070013476TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013477 TEST_DESCRIPTION(
13478 "Test that an error is produced for a vertex shader input which is not "
13479 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13481 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013482
Chris Forbes62e8e502015-05-25 11:13:29 +120013483 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013484 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013485
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013486 char const *vsSource =
13487 "#version 450\n"
13488 "\n"
13489 "layout(location=0) in vec4 x;\n" /* not provided */
13490 "out gl_PerVertex {\n"
13491 " vec4 gl_Position;\n"
13492 "};\n"
13493 "void main(){\n"
13494 " gl_Position = x;\n"
13495 "}\n";
13496 char const *fsSource =
13497 "#version 450\n"
13498 "\n"
13499 "layout(location=0) out vec4 color;\n"
13500 "void main(){\n"
13501 " color = vec4(1);\n"
13502 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013503
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013504 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13505 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013506
13507 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013508 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013509 pipe.AddShader(&vs);
13510 pipe.AddShader(&fs);
13511
Chris Forbes62e8e502015-05-25 11:13:29 +120013512 VkDescriptorSetObj descriptorSet(m_device);
13513 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013514 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013515
Tony Barbour5781e8f2015-08-04 16:23:11 -060013516 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013517
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013518 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013519}
13520
Karl Schultz6addd812016-02-02 17:17:23 -070013521TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013522 TEST_DESCRIPTION(
13523 "Test that an error is produced for a mismatch between the "
13524 "fundamental type (float/int/uint) of an attribute and the "
13525 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013526 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 -060013527
Chris Forbesc97d98e2015-05-25 11:13:31 +120013528 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013529 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013530
13531 VkVertexInputBindingDescription input_binding;
13532 memset(&input_binding, 0, sizeof(input_binding));
13533
13534 VkVertexInputAttributeDescription input_attrib;
13535 memset(&input_attrib, 0, sizeof(input_attrib));
13536 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13537
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013538 char const *vsSource =
13539 "#version 450\n"
13540 "\n"
13541 "layout(location=0) in int x;\n" /* attrib provided float */
13542 "out gl_PerVertex {\n"
13543 " vec4 gl_Position;\n"
13544 "};\n"
13545 "void main(){\n"
13546 " gl_Position = vec4(x);\n"
13547 "}\n";
13548 char const *fsSource =
13549 "#version 450\n"
13550 "\n"
13551 "layout(location=0) out vec4 color;\n"
13552 "void main(){\n"
13553 " color = vec4(1);\n"
13554 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013555
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013556 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13557 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013558
13559 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013560 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013561 pipe.AddShader(&vs);
13562 pipe.AddShader(&fs);
13563
13564 pipe.AddVertexInputBindings(&input_binding, 1);
13565 pipe.AddVertexInputAttribs(&input_attrib, 1);
13566
Chris Forbesc97d98e2015-05-25 11:13:31 +120013567 VkDescriptorSetObj descriptorSet(m_device);
13568 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013569 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013570
Tony Barbour5781e8f2015-08-04 16:23:11 -060013571 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013572
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013573 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013574}
13575
Chris Forbesc68b43c2016-04-06 11:18:47 +120013576TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013577 TEST_DESCRIPTION(
13578 "Test that an error is produced for a pipeline containing multiple "
13579 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13581 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013582
13583 ASSERT_NO_FATAL_FAILURE(InitState());
13584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13585
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013586 char const *vsSource =
13587 "#version 450\n"
13588 "\n"
13589 "out gl_PerVertex {\n"
13590 " vec4 gl_Position;\n"
13591 "};\n"
13592 "void main(){\n"
13593 " gl_Position = vec4(1);\n"
13594 "}\n";
13595 char const *fsSource =
13596 "#version 450\n"
13597 "\n"
13598 "layout(location=0) out vec4 color;\n"
13599 "void main(){\n"
13600 " color = vec4(1);\n"
13601 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013602
13603 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13604 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13605
13606 VkPipelineObj pipe(m_device);
13607 pipe.AddColorAttachment();
13608 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013609 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013610 pipe.AddShader(&fs);
13611
13612 VkDescriptorSetObj descriptorSet(m_device);
13613 descriptorSet.AppendDummy();
13614 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13615
13616 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13617
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013618 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013619}
13620
Chris Forbes82ff92a2016-09-09 10:50:24 +120013621TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120013623
13624 ASSERT_NO_FATAL_FAILURE(InitState());
13625 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13626
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013627 char const *vsSource =
13628 "#version 450\n"
13629 "out gl_PerVertex {\n"
13630 " vec4 gl_Position;\n"
13631 "};\n"
13632 "void main(){\n"
13633 " gl_Position = vec4(0);\n"
13634 "}\n";
13635 char const *fsSource =
13636 "#version 450\n"
13637 "\n"
13638 "layout(location=0) out vec4 color;\n"
13639 "void main(){\n"
13640 " color = vec4(1);\n"
13641 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120013642
13643 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13644 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13645
13646 VkPipelineObj pipe(m_device);
13647 pipe.AddColorAttachment();
13648 pipe.AddShader(&vs);
13649 pipe.AddShader(&fs);
13650
13651 VkDescriptorSetObj descriptorSet(m_device);
13652 descriptorSet.AppendDummy();
13653 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13654
13655 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13656
13657 m_errorMonitor->VerifyFound();
13658}
13659
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013660TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13662 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13663 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013664
13665 ASSERT_NO_FATAL_FAILURE(InitState());
13666 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13667
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013668 char const *vsSource =
13669 "#version 450\n"
13670 "void main(){ gl_Position = vec4(0); }\n";
13671 char const *fsSource =
13672 "#version 450\n"
13673 "\n"
13674 "layout(location=0) out vec4 color;\n"
13675 "void main(){\n"
13676 " color = vec4(1);\n"
13677 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013678
13679 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13680 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13681
13682 VkPipelineObj pipe(m_device);
13683 pipe.AddColorAttachment();
13684 pipe.AddShader(&vs);
13685 pipe.AddShader(&fs);
13686
13687 VkDescriptorSetObj descriptorSet(m_device);
13688 descriptorSet.AppendDummy();
13689 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13690
13691 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013692 {
13693 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13694 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13695 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013696 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013697 {
13698 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13699 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13700 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013701 },
13702 };
13703 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013704 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013705 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013706 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
13707 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013708 VkRenderPass rp;
13709 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13710 ASSERT_VK_SUCCESS(err);
13711
13712 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13713
13714 m_errorMonitor->VerifyFound();
13715
13716 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13717}
13718
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013719TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013720 TEST_DESCRIPTION(
13721 "Test that an error is produced for a variable output from "
13722 "the TCS without the patch decoration, but consumed in the TES "
13723 "with the decoration.");
13724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13725 "is per-vertex in tessellation control shader stage "
13726 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013727
13728 ASSERT_NO_FATAL_FAILURE(InitState());
13729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13730
Chris Forbesc1e852d2016-04-04 19:26:42 +120013731 if (!m_device->phy().features().tessellationShader) {
13732 printf("Device does not support tessellation shaders; skipped.\n");
13733 return;
13734 }
13735
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013736 char const *vsSource =
13737 "#version 450\n"
13738 "void main(){}\n";
13739 char const *tcsSource =
13740 "#version 450\n"
13741 "layout(location=0) out int x[];\n"
13742 "layout(vertices=3) out;\n"
13743 "void main(){\n"
13744 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13745 " gl_TessLevelInner[0] = 1;\n"
13746 " x[gl_InvocationID] = gl_InvocationID;\n"
13747 "}\n";
13748 char const *tesSource =
13749 "#version 450\n"
13750 "layout(triangles, equal_spacing, cw) in;\n"
13751 "layout(location=0) patch in int x;\n"
13752 "out gl_PerVertex { vec4 gl_Position; };\n"
13753 "void main(){\n"
13754 " gl_Position.xyz = gl_TessCoord;\n"
13755 " gl_Position.w = x;\n"
13756 "}\n";
13757 char const *fsSource =
13758 "#version 450\n"
13759 "layout(location=0) out vec4 color;\n"
13760 "void main(){\n"
13761 " color = vec4(1);\n"
13762 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013763
13764 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13765 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13766 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13767 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013769 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13770 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013771
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013772 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013773
13774 VkPipelineObj pipe(m_device);
13775 pipe.SetInputAssembly(&iasci);
13776 pipe.SetTessellation(&tsci);
13777 pipe.AddColorAttachment();
13778 pipe.AddShader(&vs);
13779 pipe.AddShader(&tcs);
13780 pipe.AddShader(&tes);
13781 pipe.AddShader(&fs);
13782
13783 VkDescriptorSetObj descriptorSet(m_device);
13784 descriptorSet.AppendDummy();
13785 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13786
13787 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13788
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013789 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013790}
13791
Karl Schultz6addd812016-02-02 17:17:23 -070013792TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013793 TEST_DESCRIPTION(
13794 "Test that an error is produced for a vertex attribute setup where multiple "
13795 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13797 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013798
Chris Forbes280ba2c2015-06-12 11:16:41 +120013799 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013801
13802 /* Two binding descriptions for binding 0 */
13803 VkVertexInputBindingDescription input_bindings[2];
13804 memset(input_bindings, 0, sizeof(input_bindings));
13805
13806 VkVertexInputAttributeDescription input_attrib;
13807 memset(&input_attrib, 0, sizeof(input_attrib));
13808 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13809
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013810 char const *vsSource =
13811 "#version 450\n"
13812 "\n"
13813 "layout(location=0) in float x;\n" /* attrib provided float */
13814 "out gl_PerVertex {\n"
13815 " vec4 gl_Position;\n"
13816 "};\n"
13817 "void main(){\n"
13818 " gl_Position = vec4(x);\n"
13819 "}\n";
13820 char const *fsSource =
13821 "#version 450\n"
13822 "\n"
13823 "layout(location=0) out vec4 color;\n"
13824 "void main(){\n"
13825 " color = vec4(1);\n"
13826 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013827
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013828 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13829 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013830
13831 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013832 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013833 pipe.AddShader(&vs);
13834 pipe.AddShader(&fs);
13835
13836 pipe.AddVertexInputBindings(input_bindings, 2);
13837 pipe.AddVertexInputAttribs(&input_attrib, 1);
13838
Chris Forbes280ba2c2015-06-12 11:16:41 +120013839 VkDescriptorSetObj descriptorSet(m_device);
13840 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013841 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013842
Tony Barbour5781e8f2015-08-04 16:23:11 -060013843 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013844
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013845 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013846}
Chris Forbes8f68b562015-05-25 11:13:32 +120013847
Karl Schultz6addd812016-02-02 17:17:23 -070013848TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013849 TEST_DESCRIPTION(
13850 "Test that an error is produced for a fragment shader which does not "
13851 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013853
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013854 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013855
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013856 char const *vsSource =
13857 "#version 450\n"
13858 "\n"
13859 "out gl_PerVertex {\n"
13860 " vec4 gl_Position;\n"
13861 "};\n"
13862 "void main(){\n"
13863 " gl_Position = vec4(1);\n"
13864 "}\n";
13865 char const *fsSource =
13866 "#version 450\n"
13867 "\n"
13868 "void main(){\n"
13869 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013870
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013871 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13872 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013873
13874 VkPipelineObj pipe(m_device);
13875 pipe.AddShader(&vs);
13876 pipe.AddShader(&fs);
13877
Chia-I Wu08accc62015-07-07 11:50:03 +080013878 /* set up CB 0, not written */
13879 pipe.AddColorAttachment();
13880 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013881
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013882 VkDescriptorSetObj descriptorSet(m_device);
13883 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013884 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013885
Tony Barbour5781e8f2015-08-04 16:23:11 -060013886 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013887
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013888 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013889}
13890
Karl Schultz6addd812016-02-02 17:17:23 -070013891TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013892 TEST_DESCRIPTION(
13893 "Test that a warning is produced for a fragment shader which provides a spurious "
13894 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013896 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013897
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013898 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013899
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013900 char const *vsSource =
13901 "#version 450\n"
13902 "\n"
13903 "out gl_PerVertex {\n"
13904 " vec4 gl_Position;\n"
13905 "};\n"
13906 "void main(){\n"
13907 " gl_Position = vec4(1);\n"
13908 "}\n";
13909 char const *fsSource =
13910 "#version 450\n"
13911 "\n"
13912 "layout(location=0) out vec4 x;\n"
13913 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13914 "void main(){\n"
13915 " x = vec4(1);\n"
13916 " y = vec4(1);\n"
13917 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013918
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013919 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13920 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013921
13922 VkPipelineObj pipe(m_device);
13923 pipe.AddShader(&vs);
13924 pipe.AddShader(&fs);
13925
Chia-I Wu08accc62015-07-07 11:50:03 +080013926 /* set up CB 0, not written */
13927 pipe.AddColorAttachment();
13928 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013929 /* FS writes CB 1, but we don't configure it */
13930
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013931 VkDescriptorSetObj descriptorSet(m_device);
13932 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013933 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013934
Tony Barbour5781e8f2015-08-04 16:23:11 -060013935 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013936
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013937 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013938}
13939
Karl Schultz6addd812016-02-02 17:17:23 -070013940TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013941 TEST_DESCRIPTION(
13942 "Test that an error is produced for a mismatch between the fundamental "
13943 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013945
Chris Forbesa36d69e2015-05-25 11:13:44 +120013946 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013947
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013948 char const *vsSource =
13949 "#version 450\n"
13950 "\n"
13951 "out gl_PerVertex {\n"
13952 " vec4 gl_Position;\n"
13953 "};\n"
13954 "void main(){\n"
13955 " gl_Position = vec4(1);\n"
13956 "}\n";
13957 char const *fsSource =
13958 "#version 450\n"
13959 "\n"
13960 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13961 "void main(){\n"
13962 " x = ivec4(1);\n"
13963 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013964
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013965 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13966 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013967
13968 VkPipelineObj pipe(m_device);
13969 pipe.AddShader(&vs);
13970 pipe.AddShader(&fs);
13971
Chia-I Wu08accc62015-07-07 11:50:03 +080013972 /* set up CB 0; type is UNORM by default */
13973 pipe.AddColorAttachment();
13974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013975
Chris Forbesa36d69e2015-05-25 11:13:44 +120013976 VkDescriptorSetObj descriptorSet(m_device);
13977 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013978 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013979
Tony Barbour5781e8f2015-08-04 16:23:11 -060013980 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013981
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013982 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013983}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013984
Karl Schultz6addd812016-02-02 17:17:23 -070013985TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013986 TEST_DESCRIPTION(
13987 "Test that an error is produced for a shader consuming a uniform "
13988 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013990
Chris Forbes556c76c2015-08-14 12:04:59 +120013991 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013992
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013993 char const *vsSource =
13994 "#version 450\n"
13995 "\n"
13996 "out gl_PerVertex {\n"
13997 " vec4 gl_Position;\n"
13998 "};\n"
13999 "void main(){\n"
14000 " gl_Position = vec4(1);\n"
14001 "}\n";
14002 char const *fsSource =
14003 "#version 450\n"
14004 "\n"
14005 "layout(location=0) out vec4 x;\n"
14006 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14007 "void main(){\n"
14008 " x = vec4(bar.y);\n"
14009 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014010
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014011 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14012 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014013
Chris Forbes556c76c2015-08-14 12:04:59 +120014014 VkPipelineObj pipe(m_device);
14015 pipe.AddShader(&vs);
14016 pipe.AddShader(&fs);
14017
14018 /* set up CB 0; type is UNORM by default */
14019 pipe.AddColorAttachment();
14020 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14021
14022 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014023 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014024
14025 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14026
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014027 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014028}
14029
Chris Forbes5c59e902016-02-26 16:56:09 +130014030TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014031 TEST_DESCRIPTION(
14032 "Test that an error is produced for a shader consuming push constants "
14033 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014035
14036 ASSERT_NO_FATAL_FAILURE(InitState());
14037
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014038 char const *vsSource =
14039 "#version 450\n"
14040 "\n"
14041 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14042 "out gl_PerVertex {\n"
14043 " vec4 gl_Position;\n"
14044 "};\n"
14045 "void main(){\n"
14046 " gl_Position = vec4(consts.x);\n"
14047 "}\n";
14048 char const *fsSource =
14049 "#version 450\n"
14050 "\n"
14051 "layout(location=0) out vec4 x;\n"
14052 "void main(){\n"
14053 " x = vec4(1);\n"
14054 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014055
14056 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14057 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14058
14059 VkPipelineObj pipe(m_device);
14060 pipe.AddShader(&vs);
14061 pipe.AddShader(&fs);
14062
14063 /* set up CB 0; type is UNORM by default */
14064 pipe.AddColorAttachment();
14065 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14066
14067 VkDescriptorSetObj descriptorSet(m_device);
14068 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14069
14070 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14071
14072 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014073 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014074}
14075
Chris Forbes3fb17902016-08-22 14:57:55 +120014076TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014077 TEST_DESCRIPTION(
14078 "Test that an error is produced for a shader consuming an input attachment "
14079 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14081 "consumes input attachment index 0 but not provided in subpass");
14082
14083 ASSERT_NO_FATAL_FAILURE(InitState());
14084
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014085 char const *vsSource =
14086 "#version 450\n"
14087 "\n"
14088 "out gl_PerVertex {\n"
14089 " vec4 gl_Position;\n"
14090 "};\n"
14091 "void main(){\n"
14092 " gl_Position = vec4(1);\n"
14093 "}\n";
14094 char const *fsSource =
14095 "#version 450\n"
14096 "\n"
14097 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14098 "layout(location=0) out vec4 color;\n"
14099 "void main() {\n"
14100 " color = subpassLoad(x);\n"
14101 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014102
14103 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14104 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14105
14106 VkPipelineObj pipe(m_device);
14107 pipe.AddShader(&vs);
14108 pipe.AddShader(&fs);
14109 pipe.AddColorAttachment();
14110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14111
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014112 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14113 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014114 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014115 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014116 ASSERT_VK_SUCCESS(err);
14117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014118 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014119 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014120 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014121 ASSERT_VK_SUCCESS(err);
14122
14123 // error here.
14124 pipe.CreateVKPipeline(pl, renderPass());
14125
14126 m_errorMonitor->VerifyFound();
14127
14128 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14129 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14130}
14131
Chris Forbes5a9a0472016-08-22 16:02:09 +120014132TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014133 TEST_DESCRIPTION(
14134 "Test that an error is produced for a shader consuming an input attachment "
14135 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14137 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14138
14139 ASSERT_NO_FATAL_FAILURE(InitState());
14140
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014141 char const *vsSource =
14142 "#version 450\n"
14143 "\n"
14144 "out gl_PerVertex {\n"
14145 " vec4 gl_Position;\n"
14146 "};\n"
14147 "void main(){\n"
14148 " gl_Position = vec4(1);\n"
14149 "}\n";
14150 char const *fsSource =
14151 "#version 450\n"
14152 "\n"
14153 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14154 "layout(location=0) out vec4 color;\n"
14155 "void main() {\n"
14156 " color = subpassLoad(x);\n"
14157 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014158
14159 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14160 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14161
14162 VkPipelineObj pipe(m_device);
14163 pipe.AddShader(&vs);
14164 pipe.AddShader(&fs);
14165 pipe.AddColorAttachment();
14166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14167
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014168 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14169 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014170 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014171 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014172 ASSERT_VK_SUCCESS(err);
14173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014174 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014175 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014176 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014177 ASSERT_VK_SUCCESS(err);
14178
14179 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014180 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14181 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14182 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14183 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14184 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 +120014185 };
14186 VkAttachmentReference color = {
14187 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14188 };
14189 VkAttachmentReference input = {
14190 1, VK_IMAGE_LAYOUT_GENERAL,
14191 };
14192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014193 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014195 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014196 VkRenderPass rp;
14197 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14198 ASSERT_VK_SUCCESS(err);
14199
14200 // error here.
14201 pipe.CreateVKPipeline(pl, rp);
14202
14203 m_errorMonitor->VerifyFound();
14204
14205 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14206 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14207 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14208}
14209
Chris Forbes541f7b02016-08-22 15:30:27 +120014210TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014211 TEST_DESCRIPTION(
14212 "Test that an error is produced for a shader consuming an input attachment "
14213 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120014214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014215 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014216
14217 ASSERT_NO_FATAL_FAILURE(InitState());
14218
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014219 char const *vsSource =
14220 "#version 450\n"
14221 "\n"
14222 "out gl_PerVertex {\n"
14223 " vec4 gl_Position;\n"
14224 "};\n"
14225 "void main(){\n"
14226 " gl_Position = vec4(1);\n"
14227 "}\n";
14228 char const *fsSource =
14229 "#version 450\n"
14230 "\n"
14231 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
14232 "layout(location=0) out vec4 color;\n"
14233 "void main() {\n"
14234 " color = subpassLoad(xs[0]);\n"
14235 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014236
14237 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14238 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14239
14240 VkPipelineObj pipe(m_device);
14241 pipe.AddShader(&vs);
14242 pipe.AddShader(&fs);
14243 pipe.AddColorAttachment();
14244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014246 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14247 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014248 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014249 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014250 ASSERT_VK_SUCCESS(err);
14251
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014252 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014253 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014254 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014255 ASSERT_VK_SUCCESS(err);
14256
14257 // error here.
14258 pipe.CreateVKPipeline(pl, renderPass());
14259
14260 m_errorMonitor->VerifyFound();
14261
14262 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14263 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14264}
14265
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014266TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014267 TEST_DESCRIPTION(
14268 "Test that an error is produced for a compute pipeline consuming a "
14269 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014271
14272 ASSERT_NO_FATAL_FAILURE(InitState());
14273
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014274 char const *csSource =
14275 "#version 450\n"
14276 "\n"
14277 "layout(local_size_x=1) in;\n"
14278 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14279 "void main(){\n"
14280 " x = vec4(1);\n"
14281 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014282
14283 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14284
14285 VkDescriptorSetObj descriptorSet(m_device);
14286 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14287
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014288 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14289 nullptr,
14290 0,
14291 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14292 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14293 descriptorSet.GetPipelineLayout(),
14294 VK_NULL_HANDLE,
14295 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014296
14297 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014298 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014299
14300 m_errorMonitor->VerifyFound();
14301
14302 if (err == VK_SUCCESS) {
14303 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14304 }
14305}
14306
Chris Forbes22a9b092016-07-19 14:34:05 +120014307TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014308 TEST_DESCRIPTION(
14309 "Test that an error is produced for a pipeline consuming a "
14310 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14312 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014313
14314 ASSERT_NO_FATAL_FAILURE(InitState());
14315
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014316 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14317 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014318 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014319 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014320 ASSERT_VK_SUCCESS(err);
14321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014322 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014323 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014324 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014325 ASSERT_VK_SUCCESS(err);
14326
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014327 char const *csSource =
14328 "#version 450\n"
14329 "\n"
14330 "layout(local_size_x=1) in;\n"
14331 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14332 "void main() {\n"
14333 " x.x = 1.0f;\n"
14334 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014335 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014337 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14338 nullptr,
14339 0,
14340 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14341 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14342 pl,
14343 VK_NULL_HANDLE,
14344 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014345
14346 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014347 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014348
14349 m_errorMonitor->VerifyFound();
14350
14351 if (err == VK_SUCCESS) {
14352 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14353 }
14354
14355 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14356 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14357}
14358
Chris Forbes50020592016-07-27 13:52:41 +120014359TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014360 TEST_DESCRIPTION(
14361 "Test that an error is produced when an image view type "
14362 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120014363
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014364 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 +120014365
14366 ASSERT_NO_FATAL_FAILURE(InitState());
14367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14368
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014369 char const *vsSource =
14370 "#version 450\n"
14371 "\n"
14372 "out gl_PerVertex { vec4 gl_Position; };\n"
14373 "void main() { gl_Position = vec4(0); }\n";
14374 char const *fsSource =
14375 "#version 450\n"
14376 "\n"
14377 "layout(set=0, binding=0) uniform sampler3D s;\n"
14378 "layout(location=0) out vec4 color;\n"
14379 "void main() {\n"
14380 " color = texture(s, vec3(0));\n"
14381 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014382 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14383 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14384
14385 VkPipelineObj pipe(m_device);
14386 pipe.AddShader(&vs);
14387 pipe.AddShader(&fs);
14388 pipe.AddColorAttachment();
14389
14390 VkTextureObj texture(m_device, nullptr);
14391 VkSamplerObj sampler(m_device);
14392
14393 VkDescriptorSetObj descriptorSet(m_device);
14394 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14395 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14396
14397 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14398 ASSERT_VK_SUCCESS(err);
14399
Tony Barbour552f6c02016-12-21 14:34:07 -070014400 m_commandBuffer->BeginCommandBuffer();
14401 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014402
14403 m_commandBuffer->BindPipeline(pipe);
14404 m_commandBuffer->BindDescriptorSet(descriptorSet);
14405
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014406 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014407 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014408 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014409 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14410
14411 // error produced here.
14412 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14413
14414 m_errorMonitor->VerifyFound();
14415
Tony Barbour552f6c02016-12-21 14:34:07 -070014416 m_commandBuffer->EndRenderPass();
14417 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014418}
14419
Chris Forbes5533bfc2016-07-27 14:12:34 +120014420TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014421 TEST_DESCRIPTION(
14422 "Test that an error is produced when a multisampled images "
14423 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014426
14427 ASSERT_NO_FATAL_FAILURE(InitState());
14428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14429
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014430 char const *vsSource =
14431 "#version 450\n"
14432 "\n"
14433 "out gl_PerVertex { vec4 gl_Position; };\n"
14434 "void main() { gl_Position = vec4(0); }\n";
14435 char const *fsSource =
14436 "#version 450\n"
14437 "\n"
14438 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14439 "layout(location=0) out vec4 color;\n"
14440 "void main() {\n"
14441 " color = texelFetch(s, ivec2(0), 0);\n"
14442 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014443 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14444 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14445
14446 VkPipelineObj pipe(m_device);
14447 pipe.AddShader(&vs);
14448 pipe.AddShader(&fs);
14449 pipe.AddColorAttachment();
14450
14451 VkTextureObj texture(m_device, nullptr);
14452 VkSamplerObj sampler(m_device);
14453
14454 VkDescriptorSetObj descriptorSet(m_device);
14455 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14456 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14457
14458 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14459 ASSERT_VK_SUCCESS(err);
14460
Tony Barbour552f6c02016-12-21 14:34:07 -070014461 m_commandBuffer->BeginCommandBuffer();
14462 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014463
14464 m_commandBuffer->BindPipeline(pipe);
14465 m_commandBuffer->BindDescriptorSet(descriptorSet);
14466
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014467 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014468 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014469 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014470 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14471
14472 // error produced here.
14473 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14474
14475 m_errorMonitor->VerifyFound();
14476
Tony Barbour552f6c02016-12-21 14:34:07 -070014477 m_commandBuffer->EndRenderPass();
14478 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014479}
14480
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014481#endif // SHADER_CHECKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014482
14483#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014484TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014486
14487 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014488
14489 // Create an image
14490 VkImage image;
14491
Karl Schultz6addd812016-02-02 17:17:23 -070014492 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14493 const int32_t tex_width = 32;
14494 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014495
14496 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014497 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14498 image_create_info.pNext = NULL;
14499 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14500 image_create_info.format = tex_format;
14501 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014502 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014503 image_create_info.extent.depth = 1;
14504 image_create_info.mipLevels = 1;
14505 image_create_info.arrayLayers = 1;
14506 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14507 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14508 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14509 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014510
14511 // Introduce error by sending down a bogus width extent
14512 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014513 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014514
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014515 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014516}
14517
Mark Youngc48c4c12016-04-11 14:26:49 -060014518TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14520 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014521
14522 ASSERT_NO_FATAL_FAILURE(InitState());
14523
14524 // Create an image
14525 VkImage image;
14526
14527 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14528 const int32_t tex_width = 32;
14529 const int32_t tex_height = 32;
14530
14531 VkImageCreateInfo image_create_info = {};
14532 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14533 image_create_info.pNext = NULL;
14534 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14535 image_create_info.format = tex_format;
14536 image_create_info.extent.width = tex_width;
14537 image_create_info.extent.height = tex_height;
14538 image_create_info.extent.depth = 1;
14539 image_create_info.mipLevels = 1;
14540 image_create_info.arrayLayers = 1;
14541 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14542 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14543 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14544 image_create_info.flags = 0;
14545
14546 // Introduce error by sending down a bogus width extent
14547 image_create_info.extent.width = 0;
14548 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14549
14550 m_errorMonitor->VerifyFound();
14551}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014552#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014553
Tobin Ehliscde08892015-09-22 10:11:37 -060014554#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014555
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014556TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014557 TEST_DESCRIPTION(
14558 "Create a render pass with an attachment description "
14559 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014560
14561 ASSERT_NO_FATAL_FAILURE(InitState());
14562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014565
14566 VkAttachmentReference color_attach = {};
14567 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14568 color_attach.attachment = 0;
14569 VkSubpassDescription subpass = {};
14570 subpass.colorAttachmentCount = 1;
14571 subpass.pColorAttachments = &color_attach;
14572
14573 VkRenderPassCreateInfo rpci = {};
14574 rpci.subpassCount = 1;
14575 rpci.pSubpasses = &subpass;
14576 rpci.attachmentCount = 1;
14577 VkAttachmentDescription attach_desc = {};
14578 attach_desc.format = VK_FORMAT_UNDEFINED;
14579 rpci.pAttachments = &attach_desc;
14580 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14581 VkRenderPass rp;
14582 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14583
14584 m_errorMonitor->VerifyFound();
14585
14586 if (result == VK_SUCCESS) {
14587 vkDestroyRenderPass(m_device->device(), rp, NULL);
14588 }
14589}
14590
Karl Schultz6addd812016-02-02 17:17:23 -070014591TEST_F(VkLayerTest, InvalidImageView) {
14592 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014593
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014595
Tobin Ehliscde08892015-09-22 10:11:37 -060014596 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014597
Mike Stroyana3082432015-09-25 13:39:21 -060014598 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014599 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014600
Karl Schultz6addd812016-02-02 17:17:23 -070014601 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14602 const int32_t tex_width = 32;
14603 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014604
14605 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014606 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14607 image_create_info.pNext = NULL;
14608 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14609 image_create_info.format = tex_format;
14610 image_create_info.extent.width = tex_width;
14611 image_create_info.extent.height = tex_height;
14612 image_create_info.extent.depth = 1;
14613 image_create_info.mipLevels = 1;
14614 image_create_info.arrayLayers = 1;
14615 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14616 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14617 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14618 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014619
Chia-I Wuf7458c52015-10-26 21:10:41 +080014620 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014621 ASSERT_VK_SUCCESS(err);
14622
14623 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014624 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014625 image_view_create_info.image = image;
14626 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14627 image_view_create_info.format = tex_format;
14628 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014629 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070014630 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014631 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014632
14633 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014634 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014635
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014636 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014637 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014638}
Mike Stroyana3082432015-09-25 13:39:21 -060014639
Mark Youngd339ba32016-05-30 13:28:35 -060014640TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14641 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014643 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014644
14645 ASSERT_NO_FATAL_FAILURE(InitState());
14646
14647 // Create an image and try to create a view with no memory backing the image
14648 VkImage image;
14649
14650 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14651 const int32_t tex_width = 32;
14652 const int32_t tex_height = 32;
14653
14654 VkImageCreateInfo image_create_info = {};
14655 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14656 image_create_info.pNext = NULL;
14657 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14658 image_create_info.format = tex_format;
14659 image_create_info.extent.width = tex_width;
14660 image_create_info.extent.height = tex_height;
14661 image_create_info.extent.depth = 1;
14662 image_create_info.mipLevels = 1;
14663 image_create_info.arrayLayers = 1;
14664 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14665 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14666 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14667 image_create_info.flags = 0;
14668
14669 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14670 ASSERT_VK_SUCCESS(err);
14671
14672 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014673 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014674 image_view_create_info.image = image;
14675 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14676 image_view_create_info.format = tex_format;
14677 image_view_create_info.subresourceRange.layerCount = 1;
14678 image_view_create_info.subresourceRange.baseMipLevel = 0;
14679 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014680 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014681
14682 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014683 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014684
14685 m_errorMonitor->VerifyFound();
14686 vkDestroyImage(m_device->device(), image, NULL);
14687 // If last error is success, it still created the view, so delete it.
14688 if (err == VK_SUCCESS) {
14689 vkDestroyImageView(m_device->device(), view, NULL);
14690 }
Mark Youngd339ba32016-05-30 13:28:35 -060014691}
14692
Karl Schultz6addd812016-02-02 17:17:23 -070014693TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014694 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014696
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014697 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014698
Karl Schultz6addd812016-02-02 17:17:23 -070014699 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014700 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014701 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014702 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014703
14704 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014705 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014706 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014707 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14708 image_view_create_info.format = tex_format;
14709 image_view_create_info.subresourceRange.baseMipLevel = 0;
14710 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014711 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014712 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014713 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014714
14715 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014716 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014717
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014718 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014719}
14720
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014721TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014722 VkResult err;
14723 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014724
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014726
Mike Stroyana3082432015-09-25 13:39:21 -060014727 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014728
14729 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014730 VkImage srcImage;
14731 VkImage dstImage;
14732 VkDeviceMemory srcMem;
14733 VkDeviceMemory destMem;
14734 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014735
14736 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014737 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14738 image_create_info.pNext = NULL;
14739 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14740 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14741 image_create_info.extent.width = 32;
14742 image_create_info.extent.height = 32;
14743 image_create_info.extent.depth = 1;
14744 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014745 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014746 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14747 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14748 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14749 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014751 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014752 ASSERT_VK_SUCCESS(err);
14753
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014754 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014755 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014756 ASSERT_VK_SUCCESS(err);
14757
14758 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014759 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014760 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14761 memAlloc.pNext = NULL;
14762 memAlloc.allocationSize = 0;
14763 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014764
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014765 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014766 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014767 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014768 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014769 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014770 ASSERT_VK_SUCCESS(err);
14771
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014772 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014773 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014774 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014775 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014776 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014777 ASSERT_VK_SUCCESS(err);
14778
14779 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14780 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014781 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014782 ASSERT_VK_SUCCESS(err);
14783
Tony Barbour552f6c02016-12-21 14:34:07 -070014784 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014785 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014786 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014787 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014788 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014789 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014790 copyRegion.srcOffset.x = 0;
14791 copyRegion.srcOffset.y = 0;
14792 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014793 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014794 copyRegion.dstSubresource.mipLevel = 0;
14795 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014796 // Introduce failure by forcing the dst layerCount to differ from src
14797 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014798 copyRegion.dstOffset.x = 0;
14799 copyRegion.dstOffset.y = 0;
14800 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014801 copyRegion.extent.width = 1;
14802 copyRegion.extent.height = 1;
14803 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014804 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070014805 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014806
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014807 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014808
Chia-I Wuf7458c52015-10-26 21:10:41 +080014809 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014810 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014811 vkFreeMemory(m_device->device(), srcMem, NULL);
14812 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014813}
14814
Tony Barbourd6673642016-05-05 14:46:39 -060014815TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060014816 TEST_DESCRIPTION("Creating images with unsuported formats ");
14817
14818 ASSERT_NO_FATAL_FAILURE(InitState());
14819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14820 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014821 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 -060014822 VK_IMAGE_TILING_OPTIMAL, 0);
14823 ASSERT_TRUE(image.initialized());
14824
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014825 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014826 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014827 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014828 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14829 image_create_info.format = VK_FORMAT_UNDEFINED;
14830 image_create_info.extent.width = 32;
14831 image_create_info.extent.height = 32;
14832 image_create_info.extent.depth = 1;
14833 image_create_info.mipLevels = 1;
14834 image_create_info.arrayLayers = 1;
14835 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14836 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14837 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14840 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014841
14842 VkImage localImage;
14843 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14844 m_errorMonitor->VerifyFound();
14845
Tony Barbourd6673642016-05-05 14:46:39 -060014846 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014847 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014848 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14849 VkFormat format = static_cast<VkFormat>(f);
14850 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014851 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014852 unsupported = format;
14853 break;
14854 }
14855 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014856
Tony Barbourd6673642016-05-05 14:46:39 -060014857 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014858 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014860
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014861 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014862 m_errorMonitor->VerifyFound();
14863 }
14864}
14865
14866TEST_F(VkLayerTest, ImageLayerViewTests) {
14867 VkResult ret;
14868 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14869
14870 ASSERT_NO_FATAL_FAILURE(InitState());
14871
14872 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014873 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 -060014874 VK_IMAGE_TILING_OPTIMAL, 0);
14875 ASSERT_TRUE(image.initialized());
14876
14877 VkImageView imgView;
14878 VkImageViewCreateInfo imgViewInfo = {};
14879 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14880 imgViewInfo.image = image.handle();
14881 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14882 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14883 imgViewInfo.subresourceRange.layerCount = 1;
14884 imgViewInfo.subresourceRange.baseMipLevel = 0;
14885 imgViewInfo.subresourceRange.levelCount = 1;
14886 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14887
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014889 // View can't have baseMipLevel >= image's mipLevels - Expect
14890 // VIEW_CREATE_ERROR
14891 imgViewInfo.subresourceRange.baseMipLevel = 1;
14892 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14893 m_errorMonitor->VerifyFound();
14894 imgViewInfo.subresourceRange.baseMipLevel = 0;
14895
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060014897 // View can't have baseArrayLayer >= image's arraySize - Expect
14898 // VIEW_CREATE_ERROR
14899 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14900 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14901 m_errorMonitor->VerifyFound();
14902 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14903
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14905 "vkCreateImageView called with 0 in "
14906 "pCreateInfo->subresourceRange."
14907 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014908 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14909 imgViewInfo.subresourceRange.levelCount = 0;
14910 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14911 m_errorMonitor->VerifyFound();
14912 imgViewInfo.subresourceRange.levelCount = 1;
14913
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014914 m_errorMonitor->SetDesiredFailureMsg(
14915 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14916 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014917 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14918 imgViewInfo.subresourceRange.layerCount = 0;
14919 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14920 m_errorMonitor->VerifyFound();
14921 imgViewInfo.subresourceRange.layerCount = 1;
14922
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14924 "Formats MUST be IDENTICAL unless "
14925 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14926 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014927 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14928 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14929 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14930 m_errorMonitor->VerifyFound();
14931 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14932
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060014934 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14935 // VIEW_CREATE_ERROR
14936 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14937 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14938 m_errorMonitor->VerifyFound();
14939 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14940
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014942 // TODO: Update framework to easily passing mutable flag into ImageObj init
14943 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070014944 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
14945 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14946 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014947 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14948 // VIEW_CREATE_ERROR
14949 VkImageCreateInfo mutImgInfo = image.create_info();
14950 VkImage mutImage;
14951 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014952 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014953 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14954 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14955 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14956 ASSERT_VK_SUCCESS(ret);
14957 imgViewInfo.image = mutImage;
14958 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14959 m_errorMonitor->VerifyFound();
14960 imgViewInfo.image = image.handle();
14961 vkDestroyImage(m_device->handle(), mutImage, NULL);
14962}
14963
14964TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060014965 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14966
14967 ASSERT_NO_FATAL_FAILURE(InitState());
14968
Rene Lindsay135204f2016-12-22 17:11:09 -070014969 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060014970 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070014971 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 -070014972 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060014973 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060014974 vk_testing::Buffer buffer;
14975 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070014976 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060014977 VkBufferImageCopy region = {};
14978 region.bufferRowLength = 128;
14979 region.bufferImageHeight = 128;
14980 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14981 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014982 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014983 region.imageExtent.height = 4;
14984 region.imageExtent.width = 4;
14985 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070014986
14987 VkImageObj image2(m_device);
14988 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 -070014989 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070014990 ASSERT_TRUE(image2.initialized());
14991 vk_testing::Buffer buffer2;
14992 VkMemoryPropertyFlags reqs2 = 0;
14993 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
14994 VkBufferImageCopy region2 = {};
14995 region2.bufferRowLength = 128;
14996 region2.bufferImageHeight = 128;
14997 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14998 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14999 region2.imageSubresource.layerCount = 1;
15000 region2.imageExtent.height = 4;
15001 region2.imageExtent.width = 4;
15002 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015003 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060015004
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015005 // Image must have offset.z of 0 and extent.depth of 1
15006 // Introduce failure by setting imageExtent.depth to 0
15007 region.imageExtent.depth = 0;
15008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15009 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015010 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015011 m_errorMonitor->VerifyFound();
15012
15013 region.imageExtent.depth = 1;
15014
15015 // Image must have offset.z of 0 and extent.depth of 1
15016 // Introduce failure by setting imageOffset.z to 4
15017 region.imageOffset.z = 4;
15018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15019 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015020 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015021 m_errorMonitor->VerifyFound();
15022
15023 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015024 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15025 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070015026 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015028 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15029 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015030 m_errorMonitor->VerifyFound();
15031
15032 // BufferOffset must be a multiple of 4
15033 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070015034 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070015036 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
15037 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015038 m_errorMonitor->VerifyFound();
15039
15040 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15041 region.bufferOffset = 0;
15042 region.imageExtent.height = 128;
15043 region.imageExtent.width = 128;
15044 // Introduce failure by setting bufferRowLength > 0 but less than width
15045 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15048 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015049 m_errorMonitor->VerifyFound();
15050
15051 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15052 region.bufferRowLength = 128;
15053 // Introduce failure by setting bufferRowHeight > 0 but less than height
15054 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015056 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15057 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015058 m_errorMonitor->VerifyFound();
15059
15060 region.bufferImageHeight = 128;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15062 "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015063 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015064 // Expect INVALID_FILTER
15065 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015066 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
15067 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015068 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015069 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15070 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015071 VkImageBlit blitRegion = {};
15072 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15073 blitRegion.srcSubresource.baseArrayLayer = 0;
15074 blitRegion.srcSubresource.layerCount = 1;
15075 blitRegion.srcSubresource.mipLevel = 0;
15076 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15077 blitRegion.dstSubresource.baseArrayLayer = 0;
15078 blitRegion.dstSubresource.layerCount = 1;
15079 blitRegion.dstSubresource.mipLevel = 0;
15080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015081 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015082 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060015083 m_errorMonitor->VerifyFound();
15084
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015085 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
15087 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15088 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015089 m_errorMonitor->VerifyFound();
15090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060015092 VkImageMemoryBarrier img_barrier;
15093 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15094 img_barrier.pNext = NULL;
15095 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15096 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15097 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15098 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15099 img_barrier.image = image.handle();
15100 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15101 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15102 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15103 img_barrier.subresourceRange.baseArrayLayer = 0;
15104 img_barrier.subresourceRange.baseMipLevel = 0;
15105 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15106 img_barrier.subresourceRange.layerCount = 0;
15107 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015108 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15109 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015110 m_errorMonitor->VerifyFound();
15111 img_barrier.subresourceRange.layerCount = 1;
15112}
15113
15114TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060015115 TEST_DESCRIPTION("Exceed the limits of image format ");
15116
Cody Northropc31a84f2016-08-22 10:41:47 -060015117 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015119 VkImageCreateInfo image_create_info = {};
15120 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15121 image_create_info.pNext = NULL;
15122 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15123 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15124 image_create_info.extent.width = 32;
15125 image_create_info.extent.height = 32;
15126 image_create_info.extent.depth = 1;
15127 image_create_info.mipLevels = 1;
15128 image_create_info.arrayLayers = 1;
15129 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15130 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15131 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15132 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15133 image_create_info.flags = 0;
15134
15135 VkImage nullImg;
15136 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015137 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15138 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015139 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015140 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15141 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15142 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015143 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015144
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015146 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15147 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15148 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15149 m_errorMonitor->VerifyFound();
15150 image_create_info.mipLevels = 1;
15151
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015153 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15154 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15155 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15156 m_errorMonitor->VerifyFound();
15157 image_create_info.arrayLayers = 1;
15158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015160 int samples = imgFmtProps.sampleCounts >> 1;
15161 image_create_info.samples = (VkSampleCountFlagBits)samples;
15162 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15163 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15164 m_errorMonitor->VerifyFound();
15165 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15166
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15168 "pCreateInfo->initialLayout, must be "
15169 "VK_IMAGE_LAYOUT_UNDEFINED or "
15170 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015171 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15172 // Expect INVALID_LAYOUT
15173 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15174 m_errorMonitor->VerifyFound();
15175 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15176}
15177
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015178TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015179 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015181
15182 ASSERT_NO_FATAL_FAILURE(InitState());
15183
15184 VkImageObj src_image(m_device);
15185 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15186 VkImageObj dst_image(m_device);
15187 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15188
Tony Barbour552f6c02016-12-21 14:34:07 -070015189 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015190 VkImageCopy copy_region;
15191 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15192 copy_region.srcSubresource.mipLevel = 0;
15193 copy_region.srcSubresource.baseArrayLayer = 0;
15194 copy_region.srcSubresource.layerCount = 0;
15195 copy_region.srcOffset.x = 0;
15196 copy_region.srcOffset.y = 0;
15197 copy_region.srcOffset.z = 0;
15198 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15199 copy_region.dstSubresource.mipLevel = 0;
15200 copy_region.dstSubresource.baseArrayLayer = 0;
15201 copy_region.dstSubresource.layerCount = 0;
15202 copy_region.dstOffset.x = 0;
15203 copy_region.dstOffset.y = 0;
15204 copy_region.dstOffset.z = 0;
15205 copy_region.extent.width = 64;
15206 copy_region.extent.height = 64;
15207 copy_region.extent.depth = 1;
15208 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15209 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015210 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015211
15212 m_errorMonitor->VerifyFound();
15213}
15214
15215TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015216 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015218
15219 ASSERT_NO_FATAL_FAILURE(InitState());
15220
15221 VkImageObj src_image(m_device);
15222 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15223 VkImageObj dst_image(m_device);
15224 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15225
Tony Barbour552f6c02016-12-21 14:34:07 -070015226 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015227 VkImageCopy copy_region;
15228 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15229 copy_region.srcSubresource.mipLevel = 0;
15230 copy_region.srcSubresource.baseArrayLayer = 0;
15231 copy_region.srcSubresource.layerCount = 0;
15232 copy_region.srcOffset.x = 0;
15233 copy_region.srcOffset.y = 0;
15234 copy_region.srcOffset.z = 0;
15235 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15236 copy_region.dstSubresource.mipLevel = 0;
15237 copy_region.dstSubresource.baseArrayLayer = 0;
15238 copy_region.dstSubresource.layerCount = 0;
15239 copy_region.dstOffset.x = 0;
15240 copy_region.dstOffset.y = 0;
15241 copy_region.dstOffset.z = 0;
15242 copy_region.extent.width = 64;
15243 copy_region.extent.height = 64;
15244 copy_region.extent.depth = 1;
15245 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15246 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015247 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015248
15249 m_errorMonitor->VerifyFound();
15250}
15251
Karl Schultz6addd812016-02-02 17:17:23 -070015252TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015253 VkResult err;
15254 bool pass;
15255
15256 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015258
15259 ASSERT_NO_FATAL_FAILURE(InitState());
15260
15261 // Create two images of different types and try to copy between them
15262 VkImage srcImage;
15263 VkImage dstImage;
15264 VkDeviceMemory srcMem;
15265 VkDeviceMemory destMem;
15266 VkMemoryRequirements memReqs;
15267
15268 VkImageCreateInfo image_create_info = {};
15269 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15270 image_create_info.pNext = NULL;
15271 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15272 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15273 image_create_info.extent.width = 32;
15274 image_create_info.extent.height = 32;
15275 image_create_info.extent.depth = 1;
15276 image_create_info.mipLevels = 1;
15277 image_create_info.arrayLayers = 1;
15278 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15279 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15280 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15281 image_create_info.flags = 0;
15282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015283 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015284 ASSERT_VK_SUCCESS(err);
15285
15286 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15287 // Introduce failure by creating second image with a different-sized format.
15288 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015290 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015291 ASSERT_VK_SUCCESS(err);
15292
15293 // Allocate memory
15294 VkMemoryAllocateInfo memAlloc = {};
15295 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15296 memAlloc.pNext = NULL;
15297 memAlloc.allocationSize = 0;
15298 memAlloc.memoryTypeIndex = 0;
15299
15300 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15301 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015302 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015303 ASSERT_TRUE(pass);
15304 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15305 ASSERT_VK_SUCCESS(err);
15306
15307 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15308 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015309 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015310 ASSERT_TRUE(pass);
15311 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15312 ASSERT_VK_SUCCESS(err);
15313
15314 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15315 ASSERT_VK_SUCCESS(err);
15316 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15317 ASSERT_VK_SUCCESS(err);
15318
Tony Barbour552f6c02016-12-21 14:34:07 -070015319 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015320 VkImageCopy copyRegion;
15321 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15322 copyRegion.srcSubresource.mipLevel = 0;
15323 copyRegion.srcSubresource.baseArrayLayer = 0;
15324 copyRegion.srcSubresource.layerCount = 0;
15325 copyRegion.srcOffset.x = 0;
15326 copyRegion.srcOffset.y = 0;
15327 copyRegion.srcOffset.z = 0;
15328 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15329 copyRegion.dstSubresource.mipLevel = 0;
15330 copyRegion.dstSubresource.baseArrayLayer = 0;
15331 copyRegion.dstSubresource.layerCount = 0;
15332 copyRegion.dstOffset.x = 0;
15333 copyRegion.dstOffset.y = 0;
15334 copyRegion.dstOffset.z = 0;
15335 copyRegion.extent.width = 1;
15336 copyRegion.extent.height = 1;
15337 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015338 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015339 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015340
15341 m_errorMonitor->VerifyFound();
15342
15343 vkDestroyImage(m_device->device(), srcImage, NULL);
15344 vkDestroyImage(m_device->device(), dstImage, NULL);
15345 vkFreeMemory(m_device->device(), srcMem, NULL);
15346 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015347}
15348
Karl Schultz6addd812016-02-02 17:17:23 -070015349TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15350 VkResult err;
15351 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015352
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015353 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15355 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015356
Mike Stroyana3082432015-09-25 13:39:21 -060015357 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015358
15359 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015360 VkImage srcImage;
15361 VkImage dstImage;
15362 VkDeviceMemory srcMem;
15363 VkDeviceMemory destMem;
15364 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015365
15366 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015367 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15368 image_create_info.pNext = NULL;
15369 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15370 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15371 image_create_info.extent.width = 32;
15372 image_create_info.extent.height = 32;
15373 image_create_info.extent.depth = 1;
15374 image_create_info.mipLevels = 1;
15375 image_create_info.arrayLayers = 1;
15376 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15377 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15378 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15379 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015381 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015382 ASSERT_VK_SUCCESS(err);
15383
Karl Schultzbdb75952016-04-19 11:36:49 -060015384 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15385
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015386 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015387 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015388 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015389 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015391 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015392 ASSERT_VK_SUCCESS(err);
15393
15394 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015395 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015396 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15397 memAlloc.pNext = NULL;
15398 memAlloc.allocationSize = 0;
15399 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015400
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015401 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015402 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015403 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015404 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015405 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015406 ASSERT_VK_SUCCESS(err);
15407
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015408 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015409 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015410 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015411 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015412 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015413 ASSERT_VK_SUCCESS(err);
15414
15415 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15416 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015417 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015418 ASSERT_VK_SUCCESS(err);
15419
Tony Barbour552f6c02016-12-21 14:34:07 -070015420 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015421 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015422 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015423 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015424 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015425 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015426 copyRegion.srcOffset.x = 0;
15427 copyRegion.srcOffset.y = 0;
15428 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015429 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015430 copyRegion.dstSubresource.mipLevel = 0;
15431 copyRegion.dstSubresource.baseArrayLayer = 0;
15432 copyRegion.dstSubresource.layerCount = 0;
15433 copyRegion.dstOffset.x = 0;
15434 copyRegion.dstOffset.y = 0;
15435 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015436 copyRegion.extent.width = 1;
15437 copyRegion.extent.height = 1;
15438 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015439 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015440 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015441
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015442 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015443
Chia-I Wuf7458c52015-10-26 21:10:41 +080015444 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015445 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015446 vkFreeMemory(m_device->device(), srcMem, NULL);
15447 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015448}
15449
Karl Schultz6addd812016-02-02 17:17:23 -070015450TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15451 VkResult err;
15452 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015453
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15455 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015456
Mike Stroyana3082432015-09-25 13:39:21 -060015457 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015458
15459 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015460 VkImage srcImage;
15461 VkImage dstImage;
15462 VkDeviceMemory srcMem;
15463 VkDeviceMemory destMem;
15464 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015465
15466 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015467 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15468 image_create_info.pNext = NULL;
15469 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15470 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15471 image_create_info.extent.width = 32;
15472 image_create_info.extent.height = 1;
15473 image_create_info.extent.depth = 1;
15474 image_create_info.mipLevels = 1;
15475 image_create_info.arrayLayers = 1;
15476 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15477 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15478 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15479 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015480
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015481 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015482 ASSERT_VK_SUCCESS(err);
15483
Karl Schultz6addd812016-02-02 17:17:23 -070015484 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015486 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015487 ASSERT_VK_SUCCESS(err);
15488
15489 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015490 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015491 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15492 memAlloc.pNext = NULL;
15493 memAlloc.allocationSize = 0;
15494 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015495
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015496 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015497 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015498 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015499 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015500 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015501 ASSERT_VK_SUCCESS(err);
15502
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015503 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015504 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015505 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015506 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015507 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015508 ASSERT_VK_SUCCESS(err);
15509
15510 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15511 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015512 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015513 ASSERT_VK_SUCCESS(err);
15514
Tony Barbour552f6c02016-12-21 14:34:07 -070015515 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015516 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015517 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15518 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015519 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015520 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015521 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015522 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015523 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015524 resolveRegion.srcOffset.x = 0;
15525 resolveRegion.srcOffset.y = 0;
15526 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015527 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015528 resolveRegion.dstSubresource.mipLevel = 0;
15529 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015530 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015531 resolveRegion.dstOffset.x = 0;
15532 resolveRegion.dstOffset.y = 0;
15533 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015534 resolveRegion.extent.width = 1;
15535 resolveRegion.extent.height = 1;
15536 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015537 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015538 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015539
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015540 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015541
Chia-I Wuf7458c52015-10-26 21:10:41 +080015542 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015543 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015544 vkFreeMemory(m_device->device(), srcMem, NULL);
15545 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015546}
15547
Karl Schultz6addd812016-02-02 17:17:23 -070015548TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15549 VkResult err;
15550 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015551
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15553 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015554
Mike Stroyana3082432015-09-25 13:39:21 -060015555 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015556
Chris Forbesa7530692016-05-08 12:35:39 +120015557 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015558 VkImage srcImage;
15559 VkImage dstImage;
15560 VkDeviceMemory srcMem;
15561 VkDeviceMemory destMem;
15562 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015563
15564 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015565 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15566 image_create_info.pNext = NULL;
15567 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15568 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15569 image_create_info.extent.width = 32;
15570 image_create_info.extent.height = 1;
15571 image_create_info.extent.depth = 1;
15572 image_create_info.mipLevels = 1;
15573 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015574 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015575 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15576 // Note: Some implementations expect color attachment usage for any
15577 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015578 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015579 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015581 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015582 ASSERT_VK_SUCCESS(err);
15583
Karl Schultz6addd812016-02-02 17:17:23 -070015584 // Note: Some implementations expect color attachment usage for any
15585 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015586 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015588 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015589 ASSERT_VK_SUCCESS(err);
15590
15591 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015592 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015593 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15594 memAlloc.pNext = NULL;
15595 memAlloc.allocationSize = 0;
15596 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015597
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015598 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015599 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015600 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015601 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015602 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015603 ASSERT_VK_SUCCESS(err);
15604
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015605 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015606 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015607 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015608 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015609 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015610 ASSERT_VK_SUCCESS(err);
15611
15612 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15613 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015614 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015615 ASSERT_VK_SUCCESS(err);
15616
Tony Barbour552f6c02016-12-21 14:34:07 -070015617 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015618 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015619 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15620 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015621 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015622 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015623 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015624 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015625 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015626 resolveRegion.srcOffset.x = 0;
15627 resolveRegion.srcOffset.y = 0;
15628 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015629 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015630 resolveRegion.dstSubresource.mipLevel = 0;
15631 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015632 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015633 resolveRegion.dstOffset.x = 0;
15634 resolveRegion.dstOffset.y = 0;
15635 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015636 resolveRegion.extent.width = 1;
15637 resolveRegion.extent.height = 1;
15638 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015639 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015640 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015641
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015642 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015643
Chia-I Wuf7458c52015-10-26 21:10:41 +080015644 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015645 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015646 vkFreeMemory(m_device->device(), srcMem, NULL);
15647 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015648}
15649
Karl Schultz6addd812016-02-02 17:17:23 -070015650TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15651 VkResult err;
15652 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015653
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15655 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015656
Mike Stroyana3082432015-09-25 13:39:21 -060015657 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015658
15659 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015660 VkImage srcImage;
15661 VkImage dstImage;
15662 VkDeviceMemory srcMem;
15663 VkDeviceMemory destMem;
15664 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015665
15666 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015667 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15668 image_create_info.pNext = NULL;
15669 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15670 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15671 image_create_info.extent.width = 32;
15672 image_create_info.extent.height = 1;
15673 image_create_info.extent.depth = 1;
15674 image_create_info.mipLevels = 1;
15675 image_create_info.arrayLayers = 1;
15676 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15677 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15678 // Note: Some implementations expect color attachment usage for any
15679 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015680 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015681 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015683 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015684 ASSERT_VK_SUCCESS(err);
15685
Karl Schultz6addd812016-02-02 17:17:23 -070015686 // Set format to something other than source image
15687 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15688 // Note: Some implementations expect color attachment usage for any
15689 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015690 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015691 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015693 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015694 ASSERT_VK_SUCCESS(err);
15695
15696 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015697 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015698 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15699 memAlloc.pNext = NULL;
15700 memAlloc.allocationSize = 0;
15701 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015702
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015703 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015704 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015705 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015706 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015707 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015708 ASSERT_VK_SUCCESS(err);
15709
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015710 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015711 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015712 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015713 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015714 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015715 ASSERT_VK_SUCCESS(err);
15716
15717 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15718 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015719 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015720 ASSERT_VK_SUCCESS(err);
15721
Tony Barbour552f6c02016-12-21 14:34:07 -070015722 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015723 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015724 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15725 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015726 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015727 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015728 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015729 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015730 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015731 resolveRegion.srcOffset.x = 0;
15732 resolveRegion.srcOffset.y = 0;
15733 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015734 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015735 resolveRegion.dstSubresource.mipLevel = 0;
15736 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015737 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015738 resolveRegion.dstOffset.x = 0;
15739 resolveRegion.dstOffset.y = 0;
15740 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015741 resolveRegion.extent.width = 1;
15742 resolveRegion.extent.height = 1;
15743 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015744 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015745 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015746
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015747 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015748
Chia-I Wuf7458c52015-10-26 21:10:41 +080015749 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015750 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015751 vkFreeMemory(m_device->device(), srcMem, NULL);
15752 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015753}
15754
Karl Schultz6addd812016-02-02 17:17:23 -070015755TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15756 VkResult err;
15757 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15760 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015761
Mike Stroyana3082432015-09-25 13:39:21 -060015762 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015763
15764 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015765 VkImage srcImage;
15766 VkImage dstImage;
15767 VkDeviceMemory srcMem;
15768 VkDeviceMemory destMem;
15769 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015770
15771 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015772 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15773 image_create_info.pNext = NULL;
15774 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15775 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15776 image_create_info.extent.width = 32;
15777 image_create_info.extent.height = 1;
15778 image_create_info.extent.depth = 1;
15779 image_create_info.mipLevels = 1;
15780 image_create_info.arrayLayers = 1;
15781 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15782 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15783 // Note: Some implementations expect color attachment usage for any
15784 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015785 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015786 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015788 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015789 ASSERT_VK_SUCCESS(err);
15790
Karl Schultz6addd812016-02-02 17:17:23 -070015791 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15792 // Note: Some implementations expect color attachment usage for any
15793 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015794 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015795 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015797 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015798 ASSERT_VK_SUCCESS(err);
15799
15800 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015801 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015802 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15803 memAlloc.pNext = NULL;
15804 memAlloc.allocationSize = 0;
15805 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015806
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015807 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015808 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015809 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015810 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015811 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015812 ASSERT_VK_SUCCESS(err);
15813
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015814 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015815 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015816 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015817 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015818 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015819 ASSERT_VK_SUCCESS(err);
15820
15821 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15822 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015823 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015824 ASSERT_VK_SUCCESS(err);
15825
Tony Barbour552f6c02016-12-21 14:34:07 -070015826 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015827 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015828 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15829 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015830 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015831 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015832 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015833 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015834 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015835 resolveRegion.srcOffset.x = 0;
15836 resolveRegion.srcOffset.y = 0;
15837 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015838 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015839 resolveRegion.dstSubresource.mipLevel = 0;
15840 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015841 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015842 resolveRegion.dstOffset.x = 0;
15843 resolveRegion.dstOffset.y = 0;
15844 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015845 resolveRegion.extent.width = 1;
15846 resolveRegion.extent.height = 1;
15847 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015848 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015849 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015850
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015851 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015852
Chia-I Wuf7458c52015-10-26 21:10:41 +080015853 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015854 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015855 vkFreeMemory(m_device->device(), srcMem, NULL);
15856 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015857}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015858
Karl Schultz6addd812016-02-02 17:17:23 -070015859TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015860 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015861 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15862 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015863 // The image format check comes 2nd in validation so we trigger it first,
15864 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015865 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015866
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15868 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015869
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015870 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015871
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015872 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015873 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15874 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015875
15876 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015877 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15878 ds_pool_ci.pNext = NULL;
15879 ds_pool_ci.maxSets = 1;
15880 ds_pool_ci.poolSizeCount = 1;
15881 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015882
15883 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015884 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015885 ASSERT_VK_SUCCESS(err);
15886
15887 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015888 dsl_binding.binding = 0;
15889 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15890 dsl_binding.descriptorCount = 1;
15891 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15892 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015893
15894 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015895 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15896 ds_layout_ci.pNext = NULL;
15897 ds_layout_ci.bindingCount = 1;
15898 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015899 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015900 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015901 ASSERT_VK_SUCCESS(err);
15902
15903 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015904 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015905 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015906 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015907 alloc_info.descriptorPool = ds_pool;
15908 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015909 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015910 ASSERT_VK_SUCCESS(err);
15911
Karl Schultz6addd812016-02-02 17:17:23 -070015912 VkImage image_bad;
15913 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015914 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015915 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015916 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015917 const int32_t tex_width = 32;
15918 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015919
15920 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015921 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15922 image_create_info.pNext = NULL;
15923 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15924 image_create_info.format = tex_format_bad;
15925 image_create_info.extent.width = tex_width;
15926 image_create_info.extent.height = tex_height;
15927 image_create_info.extent.depth = 1;
15928 image_create_info.mipLevels = 1;
15929 image_create_info.arrayLayers = 1;
15930 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15931 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015932 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015933 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015935 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015936 ASSERT_VK_SUCCESS(err);
15937 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015938 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15939 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015940 ASSERT_VK_SUCCESS(err);
15941
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015942 // ---Bind image memory---
15943 VkMemoryRequirements img_mem_reqs;
15944 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15945 VkMemoryAllocateInfo image_alloc_info = {};
15946 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15947 image_alloc_info.pNext = NULL;
15948 image_alloc_info.memoryTypeIndex = 0;
15949 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015950 bool pass =
15951 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 -070015952 ASSERT_TRUE(pass);
15953 VkDeviceMemory mem;
15954 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15955 ASSERT_VK_SUCCESS(err);
15956 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15957 ASSERT_VK_SUCCESS(err);
15958 // -----------------------
15959
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015960 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015961 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015962 image_view_create_info.image = image_bad;
15963 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15964 image_view_create_info.format = tex_format_bad;
15965 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15966 image_view_create_info.subresourceRange.baseMipLevel = 0;
15967 image_view_create_info.subresourceRange.layerCount = 1;
15968 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015969 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015970
15971 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015972 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015973
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015974 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015975
Chia-I Wuf7458c52015-10-26 21:10:41 +080015976 vkDestroyImage(m_device->device(), image_bad, NULL);
15977 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015980
15981 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015982}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015983
15984TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015985 TEST_DESCRIPTION(
15986 "Call ClearColorImage w/ a depth|stencil image and "
15987 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015988
15989 ASSERT_NO_FATAL_FAILURE(InitState());
15990 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15991
Tony Barbour552f6c02016-12-21 14:34:07 -070015992 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015993
15994 // Color image
15995 VkClearColorValue clear_color;
15996 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15997 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15998 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15999 const int32_t img_width = 32;
16000 const int32_t img_height = 32;
16001 VkImageCreateInfo image_create_info = {};
16002 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16003 image_create_info.pNext = NULL;
16004 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16005 image_create_info.format = color_format;
16006 image_create_info.extent.width = img_width;
16007 image_create_info.extent.height = img_height;
16008 image_create_info.extent.depth = 1;
16009 image_create_info.mipLevels = 1;
16010 image_create_info.arrayLayers = 1;
16011 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16012 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16013 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16014
16015 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016016 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016018 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016019
16020 // Depth/Stencil image
16021 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016022 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016023 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16024 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16025 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16026 ds_image_create_info.extent.width = 64;
16027 ds_image_create_info.extent.height = 64;
16028 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016029 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 -060016030
16031 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016032 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016033
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016034 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 -060016035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016038 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016039 &color_range);
16040
16041 m_errorMonitor->VerifyFound();
16042
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16044 "vkCmdClearColorImage called with "
16045 "image created without "
16046 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016047
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016048 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016049 &color_range);
16050
16051 m_errorMonitor->VerifyFound();
16052
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016053 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16055 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016056
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016057 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
16058 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016059
16060 m_errorMonitor->VerifyFound();
16061}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016062#endif // IMAGE_TESTS
Tobin Ehliscde08892015-09-22 10:11:37 -060016063
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016064// WSI Enabled Tests
16065//
Chris Forbes09368e42016-10-13 11:59:22 +130016066#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016067TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
16068
16069#if defined(VK_USE_PLATFORM_XCB_KHR)
16070 VkSurfaceKHR surface = VK_NULL_HANDLE;
16071
16072 VkResult err;
16073 bool pass;
16074 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
16075 VkSwapchainCreateInfoKHR swapchain_create_info = {};
16076 // uint32_t swapchain_image_count = 0;
16077 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
16078 // uint32_t image_index = 0;
16079 // VkPresentInfoKHR present_info = {};
16080
16081 ASSERT_NO_FATAL_FAILURE(InitState());
16082
16083 // Use the create function from one of the VK_KHR_*_surface extension in
16084 // order to create a surface, testing all known errors in the process,
16085 // before successfully creating a surface:
16086 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
16087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
16088 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
16089 pass = (err != VK_SUCCESS);
16090 ASSERT_TRUE(pass);
16091 m_errorMonitor->VerifyFound();
16092
16093 // Next, try to create a surface with the wrong
16094 // VkXcbSurfaceCreateInfoKHR::sType:
16095 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
16096 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16098 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16099 pass = (err != VK_SUCCESS);
16100 ASSERT_TRUE(pass);
16101 m_errorMonitor->VerifyFound();
16102
16103 // Create a native window, and then correctly create a surface:
16104 xcb_connection_t *connection;
16105 xcb_screen_t *screen;
16106 xcb_window_t xcb_window;
16107 xcb_intern_atom_reply_t *atom_wm_delete_window;
16108
16109 const xcb_setup_t *setup;
16110 xcb_screen_iterator_t iter;
16111 int scr;
16112 uint32_t value_mask, value_list[32];
16113 int width = 1;
16114 int height = 1;
16115
16116 connection = xcb_connect(NULL, &scr);
16117 ASSERT_TRUE(connection != NULL);
16118 setup = xcb_get_setup(connection);
16119 iter = xcb_setup_roots_iterator(setup);
16120 while (scr-- > 0)
16121 xcb_screen_next(&iter);
16122 screen = iter.data;
16123
16124 xcb_window = xcb_generate_id(connection);
16125
16126 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16127 value_list[0] = screen->black_pixel;
16128 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16129
16130 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16131 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16132
16133 /* Magic code that will send notification when window is destroyed */
16134 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16135 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16136
16137 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16138 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16139 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16140 free(reply);
16141
16142 xcb_map_window(connection, xcb_window);
16143
16144 // Force the x/y coordinates to 100,100 results are identical in consecutive
16145 // runs
16146 const uint32_t coords[] = { 100, 100 };
16147 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16148
16149 // Finally, try to correctly create a surface:
16150 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16151 xcb_create_info.pNext = NULL;
16152 xcb_create_info.flags = 0;
16153 xcb_create_info.connection = connection;
16154 xcb_create_info.window = xcb_window;
16155 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16156 pass = (err == VK_SUCCESS);
16157 ASSERT_TRUE(pass);
16158
16159 // Check if surface supports presentation:
16160
16161 // 1st, do so without having queried the queue families:
16162 VkBool32 supported = false;
16163 // TODO: Get the following error to come out:
16164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16165 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16166 "function");
16167 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16168 pass = (err != VK_SUCCESS);
16169 // ASSERT_TRUE(pass);
16170 // m_errorMonitor->VerifyFound();
16171
16172 // Next, query a queue family index that's too large:
16173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16174 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16175 pass = (err != VK_SUCCESS);
16176 ASSERT_TRUE(pass);
16177 m_errorMonitor->VerifyFound();
16178
16179 // Finally, do so correctly:
16180 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16181 // SUPPORTED
16182 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16183 pass = (err == VK_SUCCESS);
16184 ASSERT_TRUE(pass);
16185
16186 // Before proceeding, try to create a swapchain without having called
16187 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16188 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16189 swapchain_create_info.pNext = NULL;
16190 swapchain_create_info.flags = 0;
16191 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16192 swapchain_create_info.surface = surface;
16193 swapchain_create_info.imageArrayLayers = 1;
16194 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16195 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16197 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16198 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16199 pass = (err != VK_SUCCESS);
16200 ASSERT_TRUE(pass);
16201 m_errorMonitor->VerifyFound();
16202
16203 // Get the surface capabilities:
16204 VkSurfaceCapabilitiesKHR surface_capabilities;
16205
16206 // Do so correctly (only error logged by this entrypoint is if the
16207 // extension isn't enabled):
16208 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16209 pass = (err == VK_SUCCESS);
16210 ASSERT_TRUE(pass);
16211
16212 // Get the surface formats:
16213 uint32_t surface_format_count;
16214
16215 // First, try without a pointer to surface_format_count:
16216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16217 "specified as NULL");
16218 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16219 pass = (err == VK_SUCCESS);
16220 ASSERT_TRUE(pass);
16221 m_errorMonitor->VerifyFound();
16222
16223 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16224 // correctly done a 1st try (to get the count):
16225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16226 surface_format_count = 0;
16227 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16228 pass = (err == VK_SUCCESS);
16229 ASSERT_TRUE(pass);
16230 m_errorMonitor->VerifyFound();
16231
16232 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16233 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16234 pass = (err == VK_SUCCESS);
16235 ASSERT_TRUE(pass);
16236
16237 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16238 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16239
16240 // Next, do a 2nd try with surface_format_count being set too high:
16241 surface_format_count += 5;
16242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16243 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16244 pass = (err == VK_SUCCESS);
16245 ASSERT_TRUE(pass);
16246 m_errorMonitor->VerifyFound();
16247
16248 // Finally, do a correct 1st and 2nd try:
16249 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16250 pass = (err == VK_SUCCESS);
16251 ASSERT_TRUE(pass);
16252 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16253 pass = (err == VK_SUCCESS);
16254 ASSERT_TRUE(pass);
16255
16256 // Get the surface present modes:
16257 uint32_t surface_present_mode_count;
16258
16259 // First, try without a pointer to surface_format_count:
16260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16261 "specified as NULL");
16262
16263 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16264 pass = (err == VK_SUCCESS);
16265 ASSERT_TRUE(pass);
16266 m_errorMonitor->VerifyFound();
16267
16268 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16269 // correctly done a 1st try (to get the count):
16270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16271 surface_present_mode_count = 0;
16272 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16273 (VkPresentModeKHR *)&surface_present_mode_count);
16274 pass = (err == VK_SUCCESS);
16275 ASSERT_TRUE(pass);
16276 m_errorMonitor->VerifyFound();
16277
16278 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16279 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16280 pass = (err == VK_SUCCESS);
16281 ASSERT_TRUE(pass);
16282
16283 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16284 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16285
16286 // Next, do a 2nd try with surface_format_count being set too high:
16287 surface_present_mode_count += 5;
16288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16289 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16290 pass = (err == VK_SUCCESS);
16291 ASSERT_TRUE(pass);
16292 m_errorMonitor->VerifyFound();
16293
16294 // Finally, do a correct 1st and 2nd try:
16295 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16296 pass = (err == VK_SUCCESS);
16297 ASSERT_TRUE(pass);
16298 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16299 pass = (err == VK_SUCCESS);
16300 ASSERT_TRUE(pass);
16301
16302 // Create a swapchain:
16303
16304 // First, try without a pointer to swapchain_create_info:
16305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16306 "specified as NULL");
16307
16308 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16309 pass = (err != VK_SUCCESS);
16310 ASSERT_TRUE(pass);
16311 m_errorMonitor->VerifyFound();
16312
16313 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16314 // sType:
16315 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16317
16318 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16319 pass = (err != VK_SUCCESS);
16320 ASSERT_TRUE(pass);
16321 m_errorMonitor->VerifyFound();
16322
16323 // Next, call with a NULL swapchain pointer:
16324 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16325 swapchain_create_info.pNext = NULL;
16326 swapchain_create_info.flags = 0;
16327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16328 "specified as NULL");
16329
16330 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16331 pass = (err != VK_SUCCESS);
16332 ASSERT_TRUE(pass);
16333 m_errorMonitor->VerifyFound();
16334
16335 // TODO: Enhance swapchain layer so that
16336 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16337
16338 // Next, call with a queue family index that's too large:
16339 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16340 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16341 swapchain_create_info.queueFamilyIndexCount = 2;
16342 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16344 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16345 pass = (err != VK_SUCCESS);
16346 ASSERT_TRUE(pass);
16347 m_errorMonitor->VerifyFound();
16348
16349 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16350 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16351 swapchain_create_info.queueFamilyIndexCount = 1;
16352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16353 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16354 "pCreateInfo->pQueueFamilyIndices).");
16355 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16356 pass = (err != VK_SUCCESS);
16357 ASSERT_TRUE(pass);
16358 m_errorMonitor->VerifyFound();
16359
16360 // Next, call with an invalid imageSharingMode:
16361 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16362 swapchain_create_info.queueFamilyIndexCount = 1;
16363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16364 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16365 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16366 pass = (err != VK_SUCCESS);
16367 ASSERT_TRUE(pass);
16368 m_errorMonitor->VerifyFound();
16369 // Fix for the future:
16370 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16371 // SUPPORTED
16372 swapchain_create_info.queueFamilyIndexCount = 0;
16373 queueFamilyIndex[0] = 0;
16374 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16375
16376 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16377 // Get the images from a swapchain:
16378 // Acquire an image from a swapchain:
16379 // Present an image to a swapchain:
16380 // Destroy the swapchain:
16381
16382 // TODOs:
16383 //
16384 // - Try destroying the device without first destroying the swapchain
16385 //
16386 // - Try destroying the device without first destroying the surface
16387 //
16388 // - Try destroying the surface without first destroying the swapchain
16389
16390 // Destroy the surface:
16391 vkDestroySurfaceKHR(instance(), surface, NULL);
16392
16393 // Tear down the window:
16394 xcb_destroy_window(connection, xcb_window);
16395 xcb_disconnect(connection);
16396
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016397#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016398 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016399#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016400}
Chris Forbes09368e42016-10-13 11:59:22 +130016401#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016402
16403//
16404// POSITIVE VALIDATION TESTS
16405//
16406// These tests do not expect to encounter ANY validation errors pass only if this is true
16407
Tobin Ehlise0006882016-11-03 10:14:28 -060016408TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016409 TEST_DESCRIPTION(
16410 "Perform an image layout transition in a secondary command buffer followed "
16411 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060016412 VkResult err;
16413 m_errorMonitor->ExpectSuccess();
16414 ASSERT_NO_FATAL_FAILURE(InitState());
16415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16416 // Allocate a secondary and primary cmd buffer
16417 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16418 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16419 command_buffer_allocate_info.commandPool = m_commandPool;
16420 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16421 command_buffer_allocate_info.commandBufferCount = 1;
16422
16423 VkCommandBuffer secondary_command_buffer;
16424 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16425 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16426 VkCommandBuffer primary_command_buffer;
16427 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16428 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16429 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16430 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16431 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16432 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16433 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16434
16435 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16436 ASSERT_VK_SUCCESS(err);
16437 VkImageObj image(m_device);
16438 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16439 ASSERT_TRUE(image.initialized());
16440 VkImageMemoryBarrier img_barrier = {};
16441 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16442 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16443 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16444 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16445 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16446 img_barrier.image = image.handle();
16447 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16448 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16449 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16450 img_barrier.subresourceRange.baseArrayLayer = 0;
16451 img_barrier.subresourceRange.baseMipLevel = 0;
16452 img_barrier.subresourceRange.layerCount = 1;
16453 img_barrier.subresourceRange.levelCount = 1;
16454 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16455 0, nullptr, 1, &img_barrier);
16456 err = vkEndCommandBuffer(secondary_command_buffer);
16457 ASSERT_VK_SUCCESS(err);
16458
16459 // Now update primary cmd buffer to execute secondary and transitions image
16460 command_buffer_begin_info.pInheritanceInfo = nullptr;
16461 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16462 ASSERT_VK_SUCCESS(err);
16463 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16464 VkImageMemoryBarrier img_barrier2 = {};
16465 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16466 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16467 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16468 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16469 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16470 img_barrier2.image = image.handle();
16471 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16472 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16473 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16474 img_barrier2.subresourceRange.baseArrayLayer = 0;
16475 img_barrier2.subresourceRange.baseMipLevel = 0;
16476 img_barrier2.subresourceRange.layerCount = 1;
16477 img_barrier2.subresourceRange.levelCount = 1;
16478 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16479 nullptr, 1, &img_barrier2);
16480 err = vkEndCommandBuffer(primary_command_buffer);
16481 ASSERT_VK_SUCCESS(err);
16482 VkSubmitInfo submit_info = {};
16483 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16484 submit_info.commandBufferCount = 1;
16485 submit_info.pCommandBuffers = &primary_command_buffer;
16486 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16487 ASSERT_VK_SUCCESS(err);
16488 m_errorMonitor->VerifyNotFound();
16489 err = vkDeviceWaitIdle(m_device->device());
16490 ASSERT_VK_SUCCESS(err);
16491 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16492 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16493}
16494
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016495// This is a positive test. No failures are expected.
16496TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016497 TEST_DESCRIPTION(
16498 "Ensure that the vkUpdateDescriptorSets validation code "
16499 "is ignoring VkWriteDescriptorSet members that are not "
16500 "related to the descriptor type specified by "
16501 "VkWriteDescriptorSet::descriptorType. Correct "
16502 "validation behavior will result in the test running to "
16503 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016504
16505 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16506
16507 ASSERT_NO_FATAL_FAILURE(InitState());
16508
16509 // Image Case
16510 {
16511 m_errorMonitor->ExpectSuccess();
16512
16513 VkImage image;
16514 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16515 const int32_t tex_width = 32;
16516 const int32_t tex_height = 32;
16517 VkImageCreateInfo image_create_info = {};
16518 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16519 image_create_info.pNext = NULL;
16520 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16521 image_create_info.format = tex_format;
16522 image_create_info.extent.width = tex_width;
16523 image_create_info.extent.height = tex_height;
16524 image_create_info.extent.depth = 1;
16525 image_create_info.mipLevels = 1;
16526 image_create_info.arrayLayers = 1;
16527 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16528 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16529 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16530 image_create_info.flags = 0;
16531 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16532 ASSERT_VK_SUCCESS(err);
16533
16534 VkMemoryRequirements memory_reqs;
16535 VkDeviceMemory image_memory;
16536 bool pass;
16537 VkMemoryAllocateInfo memory_info = {};
16538 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16539 memory_info.pNext = NULL;
16540 memory_info.allocationSize = 0;
16541 memory_info.memoryTypeIndex = 0;
16542 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16543 memory_info.allocationSize = memory_reqs.size;
16544 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16545 ASSERT_TRUE(pass);
16546 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16547 ASSERT_VK_SUCCESS(err);
16548 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16549 ASSERT_VK_SUCCESS(err);
16550
16551 VkImageViewCreateInfo image_view_create_info = {};
16552 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16553 image_view_create_info.image = image;
16554 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16555 image_view_create_info.format = tex_format;
16556 image_view_create_info.subresourceRange.layerCount = 1;
16557 image_view_create_info.subresourceRange.baseMipLevel = 0;
16558 image_view_create_info.subresourceRange.levelCount = 1;
16559 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16560
16561 VkImageView view;
16562 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16563 ASSERT_VK_SUCCESS(err);
16564
16565 VkDescriptorPoolSize ds_type_count = {};
16566 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16567 ds_type_count.descriptorCount = 1;
16568
16569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16571 ds_pool_ci.pNext = NULL;
16572 ds_pool_ci.maxSets = 1;
16573 ds_pool_ci.poolSizeCount = 1;
16574 ds_pool_ci.pPoolSizes = &ds_type_count;
16575
16576 VkDescriptorPool ds_pool;
16577 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16578 ASSERT_VK_SUCCESS(err);
16579
16580 VkDescriptorSetLayoutBinding dsl_binding = {};
16581 dsl_binding.binding = 0;
16582 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16583 dsl_binding.descriptorCount = 1;
16584 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16585 dsl_binding.pImmutableSamplers = NULL;
16586
16587 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16588 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16589 ds_layout_ci.pNext = NULL;
16590 ds_layout_ci.bindingCount = 1;
16591 ds_layout_ci.pBindings = &dsl_binding;
16592 VkDescriptorSetLayout ds_layout;
16593 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16594 ASSERT_VK_SUCCESS(err);
16595
16596 VkDescriptorSet descriptor_set;
16597 VkDescriptorSetAllocateInfo alloc_info = {};
16598 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16599 alloc_info.descriptorSetCount = 1;
16600 alloc_info.descriptorPool = ds_pool;
16601 alloc_info.pSetLayouts = &ds_layout;
16602 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16603 ASSERT_VK_SUCCESS(err);
16604
16605 VkDescriptorImageInfo image_info = {};
16606 image_info.imageView = view;
16607 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16608
16609 VkWriteDescriptorSet descriptor_write;
16610 memset(&descriptor_write, 0, sizeof(descriptor_write));
16611 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16612 descriptor_write.dstSet = descriptor_set;
16613 descriptor_write.dstBinding = 0;
16614 descriptor_write.descriptorCount = 1;
16615 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16616 descriptor_write.pImageInfo = &image_info;
16617
16618 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16619 // be
16620 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16621 // This will most likely produce a crash if the parameter_validation
16622 // layer
16623 // does not correctly ignore pBufferInfo.
16624 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16625 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16626
16627 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16628
16629 m_errorMonitor->VerifyNotFound();
16630
16631 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16632 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16633 vkDestroyImageView(m_device->device(), view, NULL);
16634 vkDestroyImage(m_device->device(), image, NULL);
16635 vkFreeMemory(m_device->device(), image_memory, NULL);
16636 }
16637
16638 // Buffer Case
16639 {
16640 m_errorMonitor->ExpectSuccess();
16641
16642 VkBuffer buffer;
16643 uint32_t queue_family_index = 0;
16644 VkBufferCreateInfo buffer_create_info = {};
16645 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16646 buffer_create_info.size = 1024;
16647 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16648 buffer_create_info.queueFamilyIndexCount = 1;
16649 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16650
16651 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16652 ASSERT_VK_SUCCESS(err);
16653
16654 VkMemoryRequirements memory_reqs;
16655 VkDeviceMemory buffer_memory;
16656 bool pass;
16657 VkMemoryAllocateInfo memory_info = {};
16658 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16659 memory_info.pNext = NULL;
16660 memory_info.allocationSize = 0;
16661 memory_info.memoryTypeIndex = 0;
16662
16663 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16664 memory_info.allocationSize = memory_reqs.size;
16665 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16666 ASSERT_TRUE(pass);
16667
16668 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16669 ASSERT_VK_SUCCESS(err);
16670 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16671 ASSERT_VK_SUCCESS(err);
16672
16673 VkDescriptorPoolSize ds_type_count = {};
16674 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16675 ds_type_count.descriptorCount = 1;
16676
16677 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16678 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16679 ds_pool_ci.pNext = NULL;
16680 ds_pool_ci.maxSets = 1;
16681 ds_pool_ci.poolSizeCount = 1;
16682 ds_pool_ci.pPoolSizes = &ds_type_count;
16683
16684 VkDescriptorPool ds_pool;
16685 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16686 ASSERT_VK_SUCCESS(err);
16687
16688 VkDescriptorSetLayoutBinding dsl_binding = {};
16689 dsl_binding.binding = 0;
16690 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16691 dsl_binding.descriptorCount = 1;
16692 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16693 dsl_binding.pImmutableSamplers = NULL;
16694
16695 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16696 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16697 ds_layout_ci.pNext = NULL;
16698 ds_layout_ci.bindingCount = 1;
16699 ds_layout_ci.pBindings = &dsl_binding;
16700 VkDescriptorSetLayout ds_layout;
16701 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16702 ASSERT_VK_SUCCESS(err);
16703
16704 VkDescriptorSet descriptor_set;
16705 VkDescriptorSetAllocateInfo alloc_info = {};
16706 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16707 alloc_info.descriptorSetCount = 1;
16708 alloc_info.descriptorPool = ds_pool;
16709 alloc_info.pSetLayouts = &ds_layout;
16710 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16711 ASSERT_VK_SUCCESS(err);
16712
16713 VkDescriptorBufferInfo buffer_info = {};
16714 buffer_info.buffer = buffer;
16715 buffer_info.offset = 0;
16716 buffer_info.range = 1024;
16717
16718 VkWriteDescriptorSet descriptor_write;
16719 memset(&descriptor_write, 0, sizeof(descriptor_write));
16720 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16721 descriptor_write.dstSet = descriptor_set;
16722 descriptor_write.dstBinding = 0;
16723 descriptor_write.descriptorCount = 1;
16724 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16725 descriptor_write.pBufferInfo = &buffer_info;
16726
16727 // Set pImageInfo and pTexelBufferView to invalid values, which should
16728 // be
16729 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16730 // This will most likely produce a crash if the parameter_validation
16731 // layer
16732 // does not correctly ignore pImageInfo.
16733 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16734 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16735
16736 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16737
16738 m_errorMonitor->VerifyNotFound();
16739
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016740 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16741 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16742 vkDestroyBuffer(m_device->device(), buffer, NULL);
16743 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16744 }
16745
16746 // Texel Buffer Case
16747 {
16748 m_errorMonitor->ExpectSuccess();
16749
16750 VkBuffer buffer;
16751 uint32_t queue_family_index = 0;
16752 VkBufferCreateInfo buffer_create_info = {};
16753 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16754 buffer_create_info.size = 1024;
16755 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16756 buffer_create_info.queueFamilyIndexCount = 1;
16757 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16758
16759 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16760 ASSERT_VK_SUCCESS(err);
16761
16762 VkMemoryRequirements memory_reqs;
16763 VkDeviceMemory buffer_memory;
16764 bool pass;
16765 VkMemoryAllocateInfo memory_info = {};
16766 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16767 memory_info.pNext = NULL;
16768 memory_info.allocationSize = 0;
16769 memory_info.memoryTypeIndex = 0;
16770
16771 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16772 memory_info.allocationSize = memory_reqs.size;
16773 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16774 ASSERT_TRUE(pass);
16775
16776 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16777 ASSERT_VK_SUCCESS(err);
16778 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16779 ASSERT_VK_SUCCESS(err);
16780
16781 VkBufferViewCreateInfo buff_view_ci = {};
16782 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16783 buff_view_ci.buffer = buffer;
16784 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16785 buff_view_ci.range = VK_WHOLE_SIZE;
16786 VkBufferView buffer_view;
16787 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16788
16789 VkDescriptorPoolSize ds_type_count = {};
16790 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16791 ds_type_count.descriptorCount = 1;
16792
16793 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16794 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16795 ds_pool_ci.pNext = NULL;
16796 ds_pool_ci.maxSets = 1;
16797 ds_pool_ci.poolSizeCount = 1;
16798 ds_pool_ci.pPoolSizes = &ds_type_count;
16799
16800 VkDescriptorPool ds_pool;
16801 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16802 ASSERT_VK_SUCCESS(err);
16803
16804 VkDescriptorSetLayoutBinding dsl_binding = {};
16805 dsl_binding.binding = 0;
16806 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16807 dsl_binding.descriptorCount = 1;
16808 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16809 dsl_binding.pImmutableSamplers = NULL;
16810
16811 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16812 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16813 ds_layout_ci.pNext = NULL;
16814 ds_layout_ci.bindingCount = 1;
16815 ds_layout_ci.pBindings = &dsl_binding;
16816 VkDescriptorSetLayout ds_layout;
16817 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16818 ASSERT_VK_SUCCESS(err);
16819
16820 VkDescriptorSet descriptor_set;
16821 VkDescriptorSetAllocateInfo alloc_info = {};
16822 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16823 alloc_info.descriptorSetCount = 1;
16824 alloc_info.descriptorPool = ds_pool;
16825 alloc_info.pSetLayouts = &ds_layout;
16826 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16827 ASSERT_VK_SUCCESS(err);
16828
16829 VkWriteDescriptorSet descriptor_write;
16830 memset(&descriptor_write, 0, sizeof(descriptor_write));
16831 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16832 descriptor_write.dstSet = descriptor_set;
16833 descriptor_write.dstBinding = 0;
16834 descriptor_write.descriptorCount = 1;
16835 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16836 descriptor_write.pTexelBufferView = &buffer_view;
16837
16838 // Set pImageInfo and pBufferInfo to invalid values, which should be
16839 // ignored for descriptorType ==
16840 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16841 // This will most likely produce a crash if the parameter_validation
16842 // layer
16843 // does not correctly ignore pImageInfo and pBufferInfo.
16844 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16845 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16846
16847 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16848
16849 m_errorMonitor->VerifyNotFound();
16850
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016851 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16852 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16853 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16854 vkDestroyBuffer(m_device->device(), buffer, NULL);
16855 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16856 }
16857}
16858
Tobin Ehlisf7428442016-10-25 07:58:24 -060016859TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16860 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16861
16862 ASSERT_NO_FATAL_FAILURE(InitState());
16863 // Create layout where two binding #s are "1"
16864 static const uint32_t NUM_BINDINGS = 3;
16865 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16866 dsl_binding[0].binding = 1;
16867 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16868 dsl_binding[0].descriptorCount = 1;
16869 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16870 dsl_binding[0].pImmutableSamplers = NULL;
16871 dsl_binding[1].binding = 0;
16872 dsl_binding[1].descriptorCount = 1;
16873 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16874 dsl_binding[1].descriptorCount = 1;
16875 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16876 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016877 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060016878 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16879 dsl_binding[2].descriptorCount = 1;
16880 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16881 dsl_binding[2].pImmutableSamplers = NULL;
16882
16883 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16884 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16885 ds_layout_ci.pNext = NULL;
16886 ds_layout_ci.bindingCount = NUM_BINDINGS;
16887 ds_layout_ci.pBindings = dsl_binding;
16888 VkDescriptorSetLayout ds_layout;
16889 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16890 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16891 m_errorMonitor->VerifyFound();
16892}
16893
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016894TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016895 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16896
16897 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016898
Tony Barbour552f6c02016-12-21 14:34:07 -070016899 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016900
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016901 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16902
16903 {
16904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16905 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16906 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16907 m_errorMonitor->VerifyFound();
16908 }
16909
16910 {
16911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16912 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16913 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16914 m_errorMonitor->VerifyFound();
16915 }
16916
16917 {
16918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16919 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16920 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16921 m_errorMonitor->VerifyFound();
16922 }
16923
16924 {
16925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16926 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16927 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16928 m_errorMonitor->VerifyFound();
16929 }
16930
16931 {
16932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16933 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16934 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16935 m_errorMonitor->VerifyFound();
16936 }
16937
16938 {
16939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16940 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16941 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16942 m_errorMonitor->VerifyFound();
16943 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016944
16945 {
16946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16947 VkRect2D scissor = {{-1, 0}, {16, 16}};
16948 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16949 m_errorMonitor->VerifyFound();
16950 }
16951
16952 {
16953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16954 VkRect2D scissor = {{0, -2}, {16, 16}};
16955 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16956 m_errorMonitor->VerifyFound();
16957 }
16958
16959 {
16960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16961 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16962 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16963 m_errorMonitor->VerifyFound();
16964 }
16965
16966 {
16967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16968 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16969 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16970 m_errorMonitor->VerifyFound();
16971 }
16972
Tony Barbour552f6c02016-12-21 14:34:07 -070016973 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016974}
16975
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016976// This is a positive test. No failures are expected.
16977TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16978 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16979 VkResult err;
16980
16981 ASSERT_NO_FATAL_FAILURE(InitState());
16982 m_errorMonitor->ExpectSuccess();
16983 VkDescriptorPoolSize ds_type_count = {};
16984 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16985 ds_type_count.descriptorCount = 2;
16986
16987 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16988 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16989 ds_pool_ci.pNext = NULL;
16990 ds_pool_ci.maxSets = 1;
16991 ds_pool_ci.poolSizeCount = 1;
16992 ds_pool_ci.pPoolSizes = &ds_type_count;
16993
16994 VkDescriptorPool ds_pool;
16995 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16996 ASSERT_VK_SUCCESS(err);
16997
16998 // Create layout with two uniform buffer descriptors w/ empty binding between them
16999 static const uint32_t NUM_BINDINGS = 3;
17000 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17001 dsl_binding[0].binding = 0;
17002 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17003 dsl_binding[0].descriptorCount = 1;
17004 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
17005 dsl_binding[0].pImmutableSamplers = NULL;
17006 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017007 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017008 dsl_binding[2].binding = 2;
17009 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17010 dsl_binding[2].descriptorCount = 1;
17011 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
17012 dsl_binding[2].pImmutableSamplers = NULL;
17013
17014 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17015 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17016 ds_layout_ci.pNext = NULL;
17017 ds_layout_ci.bindingCount = NUM_BINDINGS;
17018 ds_layout_ci.pBindings = dsl_binding;
17019 VkDescriptorSetLayout ds_layout;
17020 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17021 ASSERT_VK_SUCCESS(err);
17022
17023 VkDescriptorSet descriptor_set = {};
17024 VkDescriptorSetAllocateInfo alloc_info = {};
17025 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17026 alloc_info.descriptorSetCount = 1;
17027 alloc_info.descriptorPool = ds_pool;
17028 alloc_info.pSetLayouts = &ds_layout;
17029 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17030 ASSERT_VK_SUCCESS(err);
17031
17032 // Create a buffer to be used for update
17033 VkBufferCreateInfo buff_ci = {};
17034 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17035 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17036 buff_ci.size = 256;
17037 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17038 VkBuffer buffer;
17039 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
17040 ASSERT_VK_SUCCESS(err);
17041 // Have to bind memory to buffer before descriptor update
17042 VkMemoryAllocateInfo mem_alloc = {};
17043 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17044 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017045 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017046 mem_alloc.memoryTypeIndex = 0;
17047
17048 VkMemoryRequirements mem_reqs;
17049 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17050 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
17051 if (!pass) {
17052 vkDestroyBuffer(m_device->device(), buffer, NULL);
17053 return;
17054 }
17055
17056 VkDeviceMemory mem;
17057 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17058 ASSERT_VK_SUCCESS(err);
17059 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17060 ASSERT_VK_SUCCESS(err);
17061
17062 // Only update the descriptor at binding 2
17063 VkDescriptorBufferInfo buff_info = {};
17064 buff_info.buffer = buffer;
17065 buff_info.offset = 0;
17066 buff_info.range = VK_WHOLE_SIZE;
17067 VkWriteDescriptorSet descriptor_write = {};
17068 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17069 descriptor_write.dstBinding = 2;
17070 descriptor_write.descriptorCount = 1;
17071 descriptor_write.pTexelBufferView = nullptr;
17072 descriptor_write.pBufferInfo = &buff_info;
17073 descriptor_write.pImageInfo = nullptr;
17074 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17075 descriptor_write.dstSet = descriptor_set;
17076
17077 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17078
17079 m_errorMonitor->VerifyNotFound();
17080 // Cleanup
17081 vkFreeMemory(m_device->device(), mem, NULL);
17082 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17083 vkDestroyBuffer(m_device->device(), buffer, NULL);
17084 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17085}
17086
17087// This is a positive test. No failures are expected.
17088TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
17089 VkResult err;
17090 bool pass;
17091
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017092 TEST_DESCRIPTION(
17093 "Create a buffer, allocate memory, bind memory, destroy "
17094 "the buffer, create an image, and bind the same memory to "
17095 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017096
17097 m_errorMonitor->ExpectSuccess();
17098
17099 ASSERT_NO_FATAL_FAILURE(InitState());
17100
17101 VkBuffer buffer;
17102 VkImage image;
17103 VkDeviceMemory mem;
17104 VkMemoryRequirements mem_reqs;
17105
17106 VkBufferCreateInfo buf_info = {};
17107 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17108 buf_info.pNext = NULL;
17109 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17110 buf_info.size = 256;
17111 buf_info.queueFamilyIndexCount = 0;
17112 buf_info.pQueueFamilyIndices = NULL;
17113 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17114 buf_info.flags = 0;
17115 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17116 ASSERT_VK_SUCCESS(err);
17117
17118 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17119
17120 VkMemoryAllocateInfo alloc_info = {};
17121 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17122 alloc_info.pNext = NULL;
17123 alloc_info.memoryTypeIndex = 0;
17124
17125 // Ensure memory is big enough for both bindings
17126 alloc_info.allocationSize = 0x10000;
17127
17128 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17129 if (!pass) {
17130 vkDestroyBuffer(m_device->device(), buffer, NULL);
17131 return;
17132 }
17133
17134 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17135 ASSERT_VK_SUCCESS(err);
17136
17137 uint8_t *pData;
17138 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17139 ASSERT_VK_SUCCESS(err);
17140
17141 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17142
17143 vkUnmapMemory(m_device->device(), mem);
17144
17145 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17146 ASSERT_VK_SUCCESS(err);
17147
17148 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17149 // memory. In fact, it was never used by the GPU.
17150 // Just be be sure, wait for idle.
17151 vkDestroyBuffer(m_device->device(), buffer, NULL);
17152 vkDeviceWaitIdle(m_device->device());
17153
Tobin Ehlis6a005702016-12-28 15:25:56 -070017154 // Use optimal as some platforms report linear support but then fail image creation
17155 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17156 VkImageFormatProperties image_format_properties;
17157 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17158 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17159 if (image_format_properties.maxExtent.width == 0) {
17160 printf("Image format not supported; skipped.\n");
17161 vkFreeMemory(m_device->device(), mem, NULL);
17162 return;
17163 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017164 VkImageCreateInfo image_create_info = {};
17165 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17166 image_create_info.pNext = NULL;
17167 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17168 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17169 image_create_info.extent.width = 64;
17170 image_create_info.extent.height = 64;
17171 image_create_info.extent.depth = 1;
17172 image_create_info.mipLevels = 1;
17173 image_create_info.arrayLayers = 1;
17174 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017175 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017176 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17177 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17178 image_create_info.queueFamilyIndexCount = 0;
17179 image_create_info.pQueueFamilyIndices = NULL;
17180 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17181 image_create_info.flags = 0;
17182
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017183 /* Create a mappable image. It will be the texture if linear images are ok
17184 * to be textures or it will be the staging image if they are not.
17185 */
17186 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17187 ASSERT_VK_SUCCESS(err);
17188
17189 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17190
Tobin Ehlis6a005702016-12-28 15:25:56 -070017191 VkMemoryAllocateInfo mem_alloc = {};
17192 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17193 mem_alloc.pNext = NULL;
17194 mem_alloc.allocationSize = 0;
17195 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017196 mem_alloc.allocationSize = mem_reqs.size;
17197
17198 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17199 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017200 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017201 vkDestroyImage(m_device->device(), image, NULL);
17202 return;
17203 }
17204
17205 // VALIDATION FAILURE:
17206 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17207 ASSERT_VK_SUCCESS(err);
17208
17209 m_errorMonitor->VerifyNotFound();
17210
17211 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017212 vkDestroyImage(m_device->device(), image, NULL);
17213}
17214
Tobin Ehlis953e8392016-11-17 10:54:13 -070017215TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17216 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17217 // We previously had a bug where dynamic offset of inactive bindings was still being used
17218 VkResult err;
17219 m_errorMonitor->ExpectSuccess();
17220
17221 ASSERT_NO_FATAL_FAILURE(InitState());
17222 ASSERT_NO_FATAL_FAILURE(InitViewport());
17223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17224
17225 VkDescriptorPoolSize ds_type_count = {};
17226 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17227 ds_type_count.descriptorCount = 3;
17228
17229 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17230 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17231 ds_pool_ci.pNext = NULL;
17232 ds_pool_ci.maxSets = 1;
17233 ds_pool_ci.poolSizeCount = 1;
17234 ds_pool_ci.pPoolSizes = &ds_type_count;
17235
17236 VkDescriptorPool ds_pool;
17237 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17238 ASSERT_VK_SUCCESS(err);
17239
17240 const uint32_t BINDING_COUNT = 3;
17241 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017242 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017243 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17244 dsl_binding[0].descriptorCount = 1;
17245 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17246 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017247 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017248 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17249 dsl_binding[1].descriptorCount = 1;
17250 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17251 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017252 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017253 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17254 dsl_binding[2].descriptorCount = 1;
17255 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17256 dsl_binding[2].pImmutableSamplers = NULL;
17257
17258 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17259 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17260 ds_layout_ci.pNext = NULL;
17261 ds_layout_ci.bindingCount = BINDING_COUNT;
17262 ds_layout_ci.pBindings = dsl_binding;
17263 VkDescriptorSetLayout ds_layout;
17264 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17265 ASSERT_VK_SUCCESS(err);
17266
17267 VkDescriptorSet descriptor_set;
17268 VkDescriptorSetAllocateInfo alloc_info = {};
17269 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17270 alloc_info.descriptorSetCount = 1;
17271 alloc_info.descriptorPool = ds_pool;
17272 alloc_info.pSetLayouts = &ds_layout;
17273 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17274 ASSERT_VK_SUCCESS(err);
17275
17276 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17277 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17278 pipeline_layout_ci.pNext = NULL;
17279 pipeline_layout_ci.setLayoutCount = 1;
17280 pipeline_layout_ci.pSetLayouts = &ds_layout;
17281
17282 VkPipelineLayout pipeline_layout;
17283 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17284 ASSERT_VK_SUCCESS(err);
17285
17286 // Create two buffers to update the descriptors with
17287 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17288 uint32_t qfi = 0;
17289 VkBufferCreateInfo buffCI = {};
17290 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17291 buffCI.size = 2048;
17292 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17293 buffCI.queueFamilyIndexCount = 1;
17294 buffCI.pQueueFamilyIndices = &qfi;
17295
17296 VkBuffer dyub1;
17297 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17298 ASSERT_VK_SUCCESS(err);
17299 // buffer2
17300 buffCI.size = 1024;
17301 VkBuffer dyub2;
17302 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17303 ASSERT_VK_SUCCESS(err);
17304 // Allocate memory and bind to buffers
17305 VkMemoryAllocateInfo mem_alloc[2] = {};
17306 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17307 mem_alloc[0].pNext = NULL;
17308 mem_alloc[0].memoryTypeIndex = 0;
17309 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17310 mem_alloc[1].pNext = NULL;
17311 mem_alloc[1].memoryTypeIndex = 0;
17312
17313 VkMemoryRequirements mem_reqs1;
17314 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17315 VkMemoryRequirements mem_reqs2;
17316 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17317 mem_alloc[0].allocationSize = mem_reqs1.size;
17318 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17319 mem_alloc[1].allocationSize = mem_reqs2.size;
17320 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17321 if (!pass) {
17322 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17323 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17324 return;
17325 }
17326
17327 VkDeviceMemory mem1;
17328 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17329 ASSERT_VK_SUCCESS(err);
17330 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17331 ASSERT_VK_SUCCESS(err);
17332 VkDeviceMemory mem2;
17333 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17334 ASSERT_VK_SUCCESS(err);
17335 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17336 ASSERT_VK_SUCCESS(err);
17337 // Update descriptors
17338 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17339 buff_info[0].buffer = dyub1;
17340 buff_info[0].offset = 0;
17341 buff_info[0].range = 256;
17342 buff_info[1].buffer = dyub1;
17343 buff_info[1].offset = 256;
17344 buff_info[1].range = 512;
17345 buff_info[2].buffer = dyub2;
17346 buff_info[2].offset = 0;
17347 buff_info[2].range = 512;
17348
17349 VkWriteDescriptorSet descriptor_write;
17350 memset(&descriptor_write, 0, sizeof(descriptor_write));
17351 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17352 descriptor_write.dstSet = descriptor_set;
17353 descriptor_write.dstBinding = 0;
17354 descriptor_write.descriptorCount = BINDING_COUNT;
17355 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17356 descriptor_write.pBufferInfo = buff_info;
17357
17358 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17359
Tony Barbour552f6c02016-12-21 14:34:07 -070017360 m_commandBuffer->BeginCommandBuffer();
17361 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017362
17363 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017364 char const *vsSource =
17365 "#version 450\n"
17366 "\n"
17367 "out gl_PerVertex { \n"
17368 " vec4 gl_Position;\n"
17369 "};\n"
17370 "void main(){\n"
17371 " gl_Position = vec4(1);\n"
17372 "}\n";
17373 char const *fsSource =
17374 "#version 450\n"
17375 "\n"
17376 "layout(location=0) out vec4 x;\n"
17377 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17378 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17379 "void main(){\n"
17380 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17381 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070017382 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17383 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17384 VkPipelineObj pipe(m_device);
17385 pipe.SetViewport(m_viewports);
17386 pipe.SetScissor(m_scissors);
17387 pipe.AddShader(&vs);
17388 pipe.AddShader(&fs);
17389 pipe.AddColorAttachment();
17390 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17391
17392 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17393 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17394 // we used to have a bug in this case.
17395 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17396 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17397 &descriptor_set, BINDING_COUNT, dyn_off);
17398 Draw(1, 0, 0, 0);
17399 m_errorMonitor->VerifyNotFound();
17400
17401 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17402 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17403 vkFreeMemory(m_device->device(), mem1, NULL);
17404 vkFreeMemory(m_device->device(), mem2, NULL);
17405
17406 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17407 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17408 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17409}
17410
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017411TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017412 TEST_DESCRIPTION(
17413 "Ensure that validations handling of non-coherent memory "
17414 "mapping while using VK_WHOLE_SIZE does not cause access "
17415 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017416 VkResult err;
17417 uint8_t *pData;
17418 ASSERT_NO_FATAL_FAILURE(InitState());
17419
17420 VkDeviceMemory mem;
17421 VkMemoryRequirements mem_reqs;
17422 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017423 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017424 VkMemoryAllocateInfo alloc_info = {};
17425 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17426 alloc_info.pNext = NULL;
17427 alloc_info.memoryTypeIndex = 0;
17428
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017429 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017430 alloc_info.allocationSize = allocation_size;
17431
17432 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17433 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 -070017434 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017435 if (!pass) {
17436 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017437 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17438 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017439 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017440 pass = m_device->phy().set_memory_type(
17441 mem_reqs.memoryTypeBits, &alloc_info,
17442 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17443 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017444 if (!pass) {
17445 return;
17446 }
17447 }
17448 }
17449
17450 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17451 ASSERT_VK_SUCCESS(err);
17452
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017453 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017454 m_errorMonitor->ExpectSuccess();
17455 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17456 ASSERT_VK_SUCCESS(err);
17457 VkMappedMemoryRange mmr = {};
17458 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17459 mmr.memory = mem;
17460 mmr.offset = 0;
17461 mmr.size = VK_WHOLE_SIZE;
17462 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17463 ASSERT_VK_SUCCESS(err);
17464 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17465 ASSERT_VK_SUCCESS(err);
17466 m_errorMonitor->VerifyNotFound();
17467 vkUnmapMemory(m_device->device(), mem);
17468
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017469 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017470 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017471 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017472 ASSERT_VK_SUCCESS(err);
17473 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17474 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017475 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017476 mmr.size = VK_WHOLE_SIZE;
17477 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17478 ASSERT_VK_SUCCESS(err);
17479 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17480 ASSERT_VK_SUCCESS(err);
17481 m_errorMonitor->VerifyNotFound();
17482 vkUnmapMemory(m_device->device(), mem);
17483
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017484 // Map with offset and size
17485 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017486 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017487 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017488 ASSERT_VK_SUCCESS(err);
17489 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17490 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017491 mmr.offset = 4 * atom_size;
17492 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017493 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17494 ASSERT_VK_SUCCESS(err);
17495 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17496 ASSERT_VK_SUCCESS(err);
17497 m_errorMonitor->VerifyNotFound();
17498 vkUnmapMemory(m_device->device(), mem);
17499
17500 // Map without offset and flush WHOLE_SIZE with two separate offsets
17501 m_errorMonitor->ExpectSuccess();
17502 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17503 ASSERT_VK_SUCCESS(err);
17504 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17505 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017506 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017507 mmr.size = VK_WHOLE_SIZE;
17508 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17509 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017510 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017511 mmr.size = VK_WHOLE_SIZE;
17512 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17513 ASSERT_VK_SUCCESS(err);
17514 m_errorMonitor->VerifyNotFound();
17515 vkUnmapMemory(m_device->device(), mem);
17516
17517 vkFreeMemory(m_device->device(), mem, NULL);
17518}
17519
17520// This is a positive test. We used to expect error in this case but spec now allows it
17521TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17522 m_errorMonitor->ExpectSuccess();
17523 vk_testing::Fence testFence;
17524 VkFenceCreateInfo fenceInfo = {};
17525 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17526 fenceInfo.pNext = NULL;
17527
17528 ASSERT_NO_FATAL_FAILURE(InitState());
17529 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017530 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017531 VkResult result = vkResetFences(m_device->device(), 1, fences);
17532 ASSERT_VK_SUCCESS(result);
17533
17534 m_errorMonitor->VerifyNotFound();
17535}
17536
17537TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17538 m_errorMonitor->ExpectSuccess();
17539
17540 ASSERT_NO_FATAL_FAILURE(InitState());
17541 VkResult err;
17542
17543 // Record (empty!) command buffer that can be submitted multiple times
17544 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017545 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17546 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017547 m_commandBuffer->BeginCommandBuffer(&cbbi);
17548 m_commandBuffer->EndCommandBuffer();
17549
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017550 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017551 VkFence fence;
17552 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17553 ASSERT_VK_SUCCESS(err);
17554
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017555 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017556 VkSemaphore s1, s2;
17557 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17558 ASSERT_VK_SUCCESS(err);
17559 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17560 ASSERT_VK_SUCCESS(err);
17561
17562 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017563 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017564 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17565 ASSERT_VK_SUCCESS(err);
17566
17567 // Submit CB again, signaling s2.
17568 si.pSignalSemaphores = &s2;
17569 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17570 ASSERT_VK_SUCCESS(err);
17571
17572 // Wait for fence.
17573 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17574 ASSERT_VK_SUCCESS(err);
17575
17576 // CB is still in flight from second submission, but semaphore s1 is no
17577 // longer in flight. delete it.
17578 vkDestroySemaphore(m_device->device(), s1, nullptr);
17579
17580 m_errorMonitor->VerifyNotFound();
17581
17582 // Force device idle and clean up remaining objects
17583 vkDeviceWaitIdle(m_device->device());
17584 vkDestroySemaphore(m_device->device(), s2, nullptr);
17585 vkDestroyFence(m_device->device(), fence, nullptr);
17586}
17587
17588TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17589 m_errorMonitor->ExpectSuccess();
17590
17591 ASSERT_NO_FATAL_FAILURE(InitState());
17592 VkResult err;
17593
17594 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017595 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017596 VkFence f1;
17597 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17598 ASSERT_VK_SUCCESS(err);
17599
17600 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017601 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017602 VkFence f2;
17603 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17604 ASSERT_VK_SUCCESS(err);
17605
17606 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017607 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017608 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17609
17610 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017611 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017612 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17613
17614 // Should have both retired!
17615 vkDestroyFence(m_device->device(), f1, nullptr);
17616 vkDestroyFence(m_device->device(), f2, nullptr);
17617
17618 m_errorMonitor->VerifyNotFound();
17619}
17620
17621TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017622 TEST_DESCRIPTION(
17623 "Verify that creating an image view from an image with valid usage "
17624 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017625
17626 ASSERT_NO_FATAL_FAILURE(InitState());
17627
17628 m_errorMonitor->ExpectSuccess();
17629 // Verify that we can create a view with usage INPUT_ATTACHMENT
17630 VkImageObj image(m_device);
17631 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17632 ASSERT_TRUE(image.initialized());
17633 VkImageView imageView;
17634 VkImageViewCreateInfo ivci = {};
17635 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17636 ivci.image = image.handle();
17637 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17638 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17639 ivci.subresourceRange.layerCount = 1;
17640 ivci.subresourceRange.baseMipLevel = 0;
17641 ivci.subresourceRange.levelCount = 1;
17642 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17643
17644 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17645 m_errorMonitor->VerifyNotFound();
17646 vkDestroyImageView(m_device->device(), imageView, NULL);
17647}
17648
17649// This is a positive test. No failures are expected.
17650TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017651 TEST_DESCRIPTION(
17652 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17653 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017654
17655 ASSERT_NO_FATAL_FAILURE(InitState());
17656
17657 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017658 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017659
17660 m_errorMonitor->ExpectSuccess();
17661
17662 VkImage image;
17663 VkImageCreateInfo image_create_info = {};
17664 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17665 image_create_info.pNext = NULL;
17666 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17667 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17668 image_create_info.extent.width = 64;
17669 image_create_info.extent.height = 64;
17670 image_create_info.extent.depth = 1;
17671 image_create_info.mipLevels = 1;
17672 image_create_info.arrayLayers = 1;
17673 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17674 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17675 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17676 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17677 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17678 ASSERT_VK_SUCCESS(err);
17679
17680 VkMemoryRequirements memory_reqs;
17681 VkDeviceMemory memory_one, memory_two;
17682 bool pass;
17683 VkMemoryAllocateInfo memory_info = {};
17684 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17685 memory_info.pNext = NULL;
17686 memory_info.allocationSize = 0;
17687 memory_info.memoryTypeIndex = 0;
17688 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17689 // Find an image big enough to allow sparse mapping of 2 memory regions
17690 // Increase the image size until it is at least twice the
17691 // size of the required alignment, to ensure we can bind both
17692 // allocated memory blocks to the image on aligned offsets.
17693 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17694 vkDestroyImage(m_device->device(), image, nullptr);
17695 image_create_info.extent.width *= 2;
17696 image_create_info.extent.height *= 2;
17697 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17698 ASSERT_VK_SUCCESS(err);
17699 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17700 }
17701 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17702 // at the end of the first
17703 memory_info.allocationSize = memory_reqs.alignment;
17704 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17705 ASSERT_TRUE(pass);
17706 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17707 ASSERT_VK_SUCCESS(err);
17708 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17709 ASSERT_VK_SUCCESS(err);
17710 VkSparseMemoryBind binds[2];
17711 binds[0].flags = 0;
17712 binds[0].memory = memory_one;
17713 binds[0].memoryOffset = 0;
17714 binds[0].resourceOffset = 0;
17715 binds[0].size = memory_info.allocationSize;
17716 binds[1].flags = 0;
17717 binds[1].memory = memory_two;
17718 binds[1].memoryOffset = 0;
17719 binds[1].resourceOffset = memory_info.allocationSize;
17720 binds[1].size = memory_info.allocationSize;
17721
17722 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17723 opaqueBindInfo.image = image;
17724 opaqueBindInfo.bindCount = 2;
17725 opaqueBindInfo.pBinds = binds;
17726
17727 VkFence fence = VK_NULL_HANDLE;
17728 VkBindSparseInfo bindSparseInfo = {};
17729 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17730 bindSparseInfo.imageOpaqueBindCount = 1;
17731 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17732
17733 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17734 vkQueueWaitIdle(m_device->m_queue);
17735 vkDestroyImage(m_device->device(), image, NULL);
17736 vkFreeMemory(m_device->device(), memory_one, NULL);
17737 vkFreeMemory(m_device->device(), memory_two, NULL);
17738 m_errorMonitor->VerifyNotFound();
17739}
17740
17741TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017742 TEST_DESCRIPTION(
17743 "Ensure that CmdBeginRenderPass with an attachment's "
17744 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17745 "the command buffer has prior knowledge of that "
17746 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017747
17748 m_errorMonitor->ExpectSuccess();
17749
17750 ASSERT_NO_FATAL_FAILURE(InitState());
17751
17752 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017753 VkAttachmentDescription attachment = {0,
17754 VK_FORMAT_R8G8B8A8_UNORM,
17755 VK_SAMPLE_COUNT_1_BIT,
17756 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17757 VK_ATTACHMENT_STORE_OP_STORE,
17758 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17759 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17760 VK_IMAGE_LAYOUT_UNDEFINED,
17761 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017762
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017763 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017764
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017765 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017766
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017767 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017768
17769 VkRenderPass rp;
17770 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17771 ASSERT_VK_SUCCESS(err);
17772
17773 // A compatible framebuffer.
17774 VkImageObj image(m_device);
17775 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17776 ASSERT_TRUE(image.initialized());
17777
17778 VkImageViewCreateInfo ivci = {
17779 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17780 nullptr,
17781 0,
17782 image.handle(),
17783 VK_IMAGE_VIEW_TYPE_2D,
17784 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017785 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17786 VK_COMPONENT_SWIZZLE_IDENTITY},
17787 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017788 };
17789 VkImageView view;
17790 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17791 ASSERT_VK_SUCCESS(err);
17792
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017793 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017794 VkFramebuffer fb;
17795 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17796 ASSERT_VK_SUCCESS(err);
17797
17798 // Record a single command buffer which uses this renderpass twice. The
17799 // bug is triggered at the beginning of the second renderpass, when the
17800 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017801 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 -070017802 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017803 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17804 vkCmdEndRenderPass(m_commandBuffer->handle());
17805 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17806
17807 m_errorMonitor->VerifyNotFound();
17808
17809 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017810 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017811
17812 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17813 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17814 vkDestroyImageView(m_device->device(), view, nullptr);
17815}
17816
17817TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017818 TEST_DESCRIPTION(
17819 "This test should pass. Create a Framebuffer and "
17820 "command buffer, bind them together, then destroy "
17821 "command pool and framebuffer and verify there are no "
17822 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017823
17824 m_errorMonitor->ExpectSuccess();
17825
17826 ASSERT_NO_FATAL_FAILURE(InitState());
17827
17828 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017829 VkAttachmentDescription attachment = {0,
17830 VK_FORMAT_R8G8B8A8_UNORM,
17831 VK_SAMPLE_COUNT_1_BIT,
17832 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17833 VK_ATTACHMENT_STORE_OP_STORE,
17834 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17835 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17836 VK_IMAGE_LAYOUT_UNDEFINED,
17837 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017838
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017839 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017840
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017841 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017842
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017843 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017844
17845 VkRenderPass rp;
17846 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17847 ASSERT_VK_SUCCESS(err);
17848
17849 // A compatible framebuffer.
17850 VkImageObj image(m_device);
17851 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17852 ASSERT_TRUE(image.initialized());
17853
17854 VkImageViewCreateInfo ivci = {
17855 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17856 nullptr,
17857 0,
17858 image.handle(),
17859 VK_IMAGE_VIEW_TYPE_2D,
17860 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017861 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17862 VK_COMPONENT_SWIZZLE_IDENTITY},
17863 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017864 };
17865 VkImageView view;
17866 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17867 ASSERT_VK_SUCCESS(err);
17868
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017869 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017870 VkFramebuffer fb;
17871 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17872 ASSERT_VK_SUCCESS(err);
17873
17874 // Explicitly create a command buffer to bind the FB to so that we can then
17875 // destroy the command pool in order to implicitly free command buffer
17876 VkCommandPool command_pool;
17877 VkCommandPoolCreateInfo pool_create_info{};
17878 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17879 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17880 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17881 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17882
17883 VkCommandBuffer command_buffer;
17884 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17885 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17886 command_buffer_allocate_info.commandPool = command_pool;
17887 command_buffer_allocate_info.commandBufferCount = 1;
17888 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17889 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17890
17891 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017892 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 -060017893 VkCommandBufferBeginInfo begin_info{};
17894 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17895 vkBeginCommandBuffer(command_buffer, &begin_info);
17896
17897 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17898 vkCmdEndRenderPass(command_buffer);
17899 vkEndCommandBuffer(command_buffer);
17900 vkDestroyImageView(m_device->device(), view, nullptr);
17901 // Destroy command pool to implicitly free command buffer
17902 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17903 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17904 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17905 m_errorMonitor->VerifyNotFound();
17906}
17907
17908TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017909 TEST_DESCRIPTION(
17910 "Ensure that CmdBeginRenderPass applies the layout "
17911 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017912
17913 m_errorMonitor->ExpectSuccess();
17914
17915 ASSERT_NO_FATAL_FAILURE(InitState());
17916
17917 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017918 VkAttachmentDescription attachment = {0,
17919 VK_FORMAT_R8G8B8A8_UNORM,
17920 VK_SAMPLE_COUNT_1_BIT,
17921 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17922 VK_ATTACHMENT_STORE_OP_STORE,
17923 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17924 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17925 VK_IMAGE_LAYOUT_UNDEFINED,
17926 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017927
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017928 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017929
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017930 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017931
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017932 VkSubpassDependency dep = {0,
17933 0,
17934 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17935 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17936 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17937 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17938 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017939
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017940 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017941
17942 VkResult err;
17943 VkRenderPass rp;
17944 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17945 ASSERT_VK_SUCCESS(err);
17946
17947 // A compatible framebuffer.
17948 VkImageObj image(m_device);
17949 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17950 ASSERT_TRUE(image.initialized());
17951
17952 VkImageViewCreateInfo ivci = {
17953 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17954 nullptr,
17955 0,
17956 image.handle(),
17957 VK_IMAGE_VIEW_TYPE_2D,
17958 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017959 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17960 VK_COMPONENT_SWIZZLE_IDENTITY},
17961 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017962 };
17963 VkImageView view;
17964 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17965 ASSERT_VK_SUCCESS(err);
17966
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017967 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017968 VkFramebuffer fb;
17969 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17970 ASSERT_VK_SUCCESS(err);
17971
17972 // Record a single command buffer which issues a pipeline barrier w/
17973 // image memory barrier for the attachment. This detects the previously
17974 // missing tracking of the subpass layout by throwing a validation error
17975 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017976 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 -070017977 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017978 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17979
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017980 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17981 nullptr,
17982 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17983 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17984 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17985 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17986 VK_QUEUE_FAMILY_IGNORED,
17987 VK_QUEUE_FAMILY_IGNORED,
17988 image.handle(),
17989 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017990 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017991 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17992 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017993
17994 vkCmdEndRenderPass(m_commandBuffer->handle());
17995 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017996 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017997
17998 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17999 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18000 vkDestroyImageView(m_device->device(), view, nullptr);
18001}
18002
18003TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018004 TEST_DESCRIPTION(
18005 "Validate that when an imageView of a depth/stencil image "
18006 "is used as a depth/stencil framebuffer attachment, the "
18007 "aspectMask is ignored and both depth and stencil image "
18008 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018009
18010 VkFormatProperties format_properties;
18011 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
18012 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
18013 return;
18014 }
18015
18016 m_errorMonitor->ExpectSuccess();
18017
18018 ASSERT_NO_FATAL_FAILURE(InitState());
18019
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018020 VkAttachmentDescription attachment = {0,
18021 VK_FORMAT_D32_SFLOAT_S8_UINT,
18022 VK_SAMPLE_COUNT_1_BIT,
18023 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18024 VK_ATTACHMENT_STORE_OP_STORE,
18025 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18026 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18027 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
18028 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018029
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018030 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018031
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018032 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018033
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018034 VkSubpassDependency dep = {0,
18035 0,
18036 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18037 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18038 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18039 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18040 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018041
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018042 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018043
18044 VkResult err;
18045 VkRenderPass rp;
18046 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18047 ASSERT_VK_SUCCESS(err);
18048
18049 VkImageObj image(m_device);
18050 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018051 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018052 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018053 ASSERT_TRUE(image.initialized());
18054 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
18055
18056 VkImageViewCreateInfo ivci = {
18057 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18058 nullptr,
18059 0,
18060 image.handle(),
18061 VK_IMAGE_VIEW_TYPE_2D,
18062 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018063 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
18064 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018065 };
18066 VkImageView view;
18067 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18068 ASSERT_VK_SUCCESS(err);
18069
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018070 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018071 VkFramebuffer fb;
18072 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18073 ASSERT_VK_SUCCESS(err);
18074
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018075 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 -070018076 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018077 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18078
18079 VkImageMemoryBarrier imb = {};
18080 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18081 imb.pNext = nullptr;
18082 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18083 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18084 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18085 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18086 imb.srcQueueFamilyIndex = 0;
18087 imb.dstQueueFamilyIndex = 0;
18088 imb.image = image.handle();
18089 imb.subresourceRange.aspectMask = 0x6;
18090 imb.subresourceRange.baseMipLevel = 0;
18091 imb.subresourceRange.levelCount = 0x1;
18092 imb.subresourceRange.baseArrayLayer = 0;
18093 imb.subresourceRange.layerCount = 0x1;
18094
18095 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018096 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18097 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018098
18099 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018100 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018101 QueueCommandBuffer(false);
18102 m_errorMonitor->VerifyNotFound();
18103
18104 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18105 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18106 vkDestroyImageView(m_device->device(), view, nullptr);
18107}
18108
18109TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018110 TEST_DESCRIPTION(
18111 "Ensure that layout transitions work correctly without "
18112 "errors, when an attachment reference is "
18113 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018114
18115 m_errorMonitor->ExpectSuccess();
18116
18117 ASSERT_NO_FATAL_FAILURE(InitState());
18118
18119 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018120 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018121
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018122 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018123
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018124 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018125
18126 VkRenderPass rp;
18127 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18128 ASSERT_VK_SUCCESS(err);
18129
18130 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018131 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018132 VkFramebuffer fb;
18133 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18134 ASSERT_VK_SUCCESS(err);
18135
18136 // Record a command buffer which just begins and ends the renderpass. The
18137 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018138 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 -070018139 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018140 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18141 vkCmdEndRenderPass(m_commandBuffer->handle());
18142 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018143 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018144
18145 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18146 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18147}
18148
18149// This is a positive test. No errors are expected.
18150TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018151 TEST_DESCRIPTION(
18152 "Create a stencil-only attachment with a LOAD_OP set to "
18153 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018154 VkResult result = VK_SUCCESS;
18155 VkImageFormatProperties formatProps;
18156 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018157 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18158 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018159 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18160 return;
18161 }
18162
18163 ASSERT_NO_FATAL_FAILURE(InitState());
18164 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18165 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018166 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018167 VkAttachmentDescription att = {};
18168 VkAttachmentReference ref = {};
18169 att.format = depth_stencil_fmt;
18170 att.samples = VK_SAMPLE_COUNT_1_BIT;
18171 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18172 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18173 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18174 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18175 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18176 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18177
18178 VkClearValue clear;
18179 clear.depthStencil.depth = 1.0;
18180 clear.depthStencil.stencil = 0;
18181 ref.attachment = 0;
18182 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18183
18184 VkSubpassDescription subpass = {};
18185 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18186 subpass.flags = 0;
18187 subpass.inputAttachmentCount = 0;
18188 subpass.pInputAttachments = NULL;
18189 subpass.colorAttachmentCount = 0;
18190 subpass.pColorAttachments = NULL;
18191 subpass.pResolveAttachments = NULL;
18192 subpass.pDepthStencilAttachment = &ref;
18193 subpass.preserveAttachmentCount = 0;
18194 subpass.pPreserveAttachments = NULL;
18195
18196 VkRenderPass rp;
18197 VkRenderPassCreateInfo rp_info = {};
18198 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18199 rp_info.attachmentCount = 1;
18200 rp_info.pAttachments = &att;
18201 rp_info.subpassCount = 1;
18202 rp_info.pSubpasses = &subpass;
18203 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18204 ASSERT_VK_SUCCESS(result);
18205
18206 VkImageView *depthView = m_depthStencil->BindInfo();
18207 VkFramebufferCreateInfo fb_info = {};
18208 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18209 fb_info.pNext = NULL;
18210 fb_info.renderPass = rp;
18211 fb_info.attachmentCount = 1;
18212 fb_info.pAttachments = depthView;
18213 fb_info.width = 100;
18214 fb_info.height = 100;
18215 fb_info.layers = 1;
18216 VkFramebuffer fb;
18217 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18218 ASSERT_VK_SUCCESS(result);
18219
18220 VkRenderPassBeginInfo rpbinfo = {};
18221 rpbinfo.clearValueCount = 1;
18222 rpbinfo.pClearValues = &clear;
18223 rpbinfo.pNext = NULL;
18224 rpbinfo.renderPass = rp;
18225 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18226 rpbinfo.renderArea.extent.width = 100;
18227 rpbinfo.renderArea.extent.height = 100;
18228 rpbinfo.renderArea.offset.x = 0;
18229 rpbinfo.renderArea.offset.y = 0;
18230 rpbinfo.framebuffer = fb;
18231
18232 VkFence fence = {};
18233 VkFenceCreateInfo fence_ci = {};
18234 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18235 fence_ci.pNext = nullptr;
18236 fence_ci.flags = 0;
18237 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18238 ASSERT_VK_SUCCESS(result);
18239
18240 m_commandBuffer->BeginCommandBuffer();
18241 m_commandBuffer->BeginRenderPass(rpbinfo);
18242 m_commandBuffer->EndRenderPass();
18243 m_commandBuffer->EndCommandBuffer();
18244 m_commandBuffer->QueueCommandBuffer(fence);
18245
18246 VkImageObj destImage(m_device);
18247 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 -070018248 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018249 VkImageMemoryBarrier barrier = {};
18250 VkImageSubresourceRange range;
18251 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18252 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18253 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18254 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18255 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18256 barrier.image = m_depthStencil->handle();
18257 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18258 range.baseMipLevel = 0;
18259 range.levelCount = 1;
18260 range.baseArrayLayer = 0;
18261 range.layerCount = 1;
18262 barrier.subresourceRange = range;
18263 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18264 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18265 cmdbuf.BeginCommandBuffer();
18266 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 -070018267 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018268 barrier.srcAccessMask = 0;
18269 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18270 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18271 barrier.image = destImage.handle();
18272 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18273 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 -070018274 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018275 VkImageCopy cregion;
18276 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18277 cregion.srcSubresource.mipLevel = 0;
18278 cregion.srcSubresource.baseArrayLayer = 0;
18279 cregion.srcSubresource.layerCount = 1;
18280 cregion.srcOffset.x = 0;
18281 cregion.srcOffset.y = 0;
18282 cregion.srcOffset.z = 0;
18283 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18284 cregion.dstSubresource.mipLevel = 0;
18285 cregion.dstSubresource.baseArrayLayer = 0;
18286 cregion.dstSubresource.layerCount = 1;
18287 cregion.dstOffset.x = 0;
18288 cregion.dstOffset.y = 0;
18289 cregion.dstOffset.z = 0;
18290 cregion.extent.width = 100;
18291 cregion.extent.height = 100;
18292 cregion.extent.depth = 1;
18293 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018294 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018295 cmdbuf.EndCommandBuffer();
18296
18297 VkSubmitInfo submit_info;
18298 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18299 submit_info.pNext = NULL;
18300 submit_info.waitSemaphoreCount = 0;
18301 submit_info.pWaitSemaphores = NULL;
18302 submit_info.pWaitDstStageMask = NULL;
18303 submit_info.commandBufferCount = 1;
18304 submit_info.pCommandBuffers = &cmdbuf.handle();
18305 submit_info.signalSemaphoreCount = 0;
18306 submit_info.pSignalSemaphores = NULL;
18307
18308 m_errorMonitor->ExpectSuccess();
18309 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18310 m_errorMonitor->VerifyNotFound();
18311
18312 vkQueueWaitIdle(m_device->m_queue);
18313 vkDestroyFence(m_device->device(), fence, nullptr);
18314 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18315 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18316}
18317
18318// This is a positive test. No errors should be generated.
18319TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18320 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18321
18322 m_errorMonitor->ExpectSuccess();
18323 ASSERT_NO_FATAL_FAILURE(InitState());
18324
18325 VkEvent event;
18326 VkEventCreateInfo event_create_info{};
18327 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18328 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18329
18330 VkCommandPool command_pool;
18331 VkCommandPoolCreateInfo pool_create_info{};
18332 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18333 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18334 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18335 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18336
18337 VkCommandBuffer command_buffer;
18338 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18339 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18340 command_buffer_allocate_info.commandPool = command_pool;
18341 command_buffer_allocate_info.commandBufferCount = 1;
18342 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18343 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18344
18345 VkQueue queue = VK_NULL_HANDLE;
18346 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18347
18348 {
18349 VkCommandBufferBeginInfo begin_info{};
18350 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18351 vkBeginCommandBuffer(command_buffer, &begin_info);
18352
18353 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 -070018354 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018355 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18356 vkEndCommandBuffer(command_buffer);
18357 }
18358 {
18359 VkSubmitInfo submit_info{};
18360 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18361 submit_info.commandBufferCount = 1;
18362 submit_info.pCommandBuffers = &command_buffer;
18363 submit_info.signalSemaphoreCount = 0;
18364 submit_info.pSignalSemaphores = nullptr;
18365 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18366 }
18367 { vkSetEvent(m_device->device(), event); }
18368
18369 vkQueueWaitIdle(queue);
18370
18371 vkDestroyEvent(m_device->device(), event, nullptr);
18372 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18373 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18374
18375 m_errorMonitor->VerifyNotFound();
18376}
18377// This is a positive test. No errors should be generated.
18378TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18379 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18380
18381 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018382 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018383
18384 m_errorMonitor->ExpectSuccess();
18385
18386 VkQueryPool query_pool;
18387 VkQueryPoolCreateInfo query_pool_create_info{};
18388 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18389 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18390 query_pool_create_info.queryCount = 1;
18391 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18392
18393 VkCommandPool command_pool;
18394 VkCommandPoolCreateInfo pool_create_info{};
18395 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18396 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18397 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18398 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18399
18400 VkCommandBuffer command_buffer;
18401 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18402 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18403 command_buffer_allocate_info.commandPool = command_pool;
18404 command_buffer_allocate_info.commandBufferCount = 1;
18405 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18406 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18407
18408 VkCommandBuffer secondary_command_buffer;
18409 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18410 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18411
18412 VkQueue queue = VK_NULL_HANDLE;
18413 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18414
18415 uint32_t qfi = 0;
18416 VkBufferCreateInfo buff_create_info = {};
18417 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18418 buff_create_info.size = 1024;
18419 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18420 buff_create_info.queueFamilyIndexCount = 1;
18421 buff_create_info.pQueueFamilyIndices = &qfi;
18422
18423 VkResult err;
18424 VkBuffer buffer;
18425 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18426 ASSERT_VK_SUCCESS(err);
18427 VkMemoryAllocateInfo mem_alloc = {};
18428 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18429 mem_alloc.pNext = NULL;
18430 mem_alloc.allocationSize = 1024;
18431 mem_alloc.memoryTypeIndex = 0;
18432
18433 VkMemoryRequirements memReqs;
18434 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18435 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18436 if (!pass) {
18437 vkDestroyBuffer(m_device->device(), buffer, NULL);
18438 return;
18439 }
18440
18441 VkDeviceMemory mem;
18442 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18443 ASSERT_VK_SUCCESS(err);
18444 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18445 ASSERT_VK_SUCCESS(err);
18446
18447 VkCommandBufferInheritanceInfo hinfo = {};
18448 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18449 hinfo.renderPass = VK_NULL_HANDLE;
18450 hinfo.subpass = 0;
18451 hinfo.framebuffer = VK_NULL_HANDLE;
18452 hinfo.occlusionQueryEnable = VK_FALSE;
18453 hinfo.queryFlags = 0;
18454 hinfo.pipelineStatistics = 0;
18455
18456 {
18457 VkCommandBufferBeginInfo begin_info{};
18458 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18459 begin_info.pInheritanceInfo = &hinfo;
18460 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18461
18462 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18463 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18464
18465 vkEndCommandBuffer(secondary_command_buffer);
18466
18467 begin_info.pInheritanceInfo = nullptr;
18468 vkBeginCommandBuffer(command_buffer, &begin_info);
18469
18470 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18471 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18472
18473 vkEndCommandBuffer(command_buffer);
18474 }
18475 {
18476 VkSubmitInfo submit_info{};
18477 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18478 submit_info.commandBufferCount = 1;
18479 submit_info.pCommandBuffers = &command_buffer;
18480 submit_info.signalSemaphoreCount = 0;
18481 submit_info.pSignalSemaphores = nullptr;
18482 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18483 }
18484
18485 vkQueueWaitIdle(queue);
18486
18487 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18488 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18489 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18490 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18491 vkDestroyBuffer(m_device->device(), buffer, NULL);
18492 vkFreeMemory(m_device->device(), mem, NULL);
18493
18494 m_errorMonitor->VerifyNotFound();
18495}
18496
18497// This is a positive test. No errors should be generated.
18498TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18499 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18500
18501 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018502 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018503
18504 m_errorMonitor->ExpectSuccess();
18505
18506 VkQueryPool query_pool;
18507 VkQueryPoolCreateInfo query_pool_create_info{};
18508 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18509 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18510 query_pool_create_info.queryCount = 1;
18511 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18512
18513 VkCommandPool command_pool;
18514 VkCommandPoolCreateInfo pool_create_info{};
18515 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18516 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18517 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18518 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18519
18520 VkCommandBuffer command_buffer[2];
18521 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18522 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18523 command_buffer_allocate_info.commandPool = command_pool;
18524 command_buffer_allocate_info.commandBufferCount = 2;
18525 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18526 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18527
18528 VkQueue queue = VK_NULL_HANDLE;
18529 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18530
18531 uint32_t qfi = 0;
18532 VkBufferCreateInfo buff_create_info = {};
18533 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18534 buff_create_info.size = 1024;
18535 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18536 buff_create_info.queueFamilyIndexCount = 1;
18537 buff_create_info.pQueueFamilyIndices = &qfi;
18538
18539 VkResult err;
18540 VkBuffer buffer;
18541 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18542 ASSERT_VK_SUCCESS(err);
18543 VkMemoryAllocateInfo mem_alloc = {};
18544 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18545 mem_alloc.pNext = NULL;
18546 mem_alloc.allocationSize = 1024;
18547 mem_alloc.memoryTypeIndex = 0;
18548
18549 VkMemoryRequirements memReqs;
18550 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18551 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18552 if (!pass) {
18553 vkDestroyBuffer(m_device->device(), buffer, NULL);
18554 return;
18555 }
18556
18557 VkDeviceMemory mem;
18558 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18559 ASSERT_VK_SUCCESS(err);
18560 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18561 ASSERT_VK_SUCCESS(err);
18562
18563 {
18564 VkCommandBufferBeginInfo begin_info{};
18565 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18566 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18567
18568 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18569 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18570
18571 vkEndCommandBuffer(command_buffer[0]);
18572
18573 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18574
18575 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18576
18577 vkEndCommandBuffer(command_buffer[1]);
18578 }
18579 {
18580 VkSubmitInfo submit_info{};
18581 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18582 submit_info.commandBufferCount = 2;
18583 submit_info.pCommandBuffers = command_buffer;
18584 submit_info.signalSemaphoreCount = 0;
18585 submit_info.pSignalSemaphores = nullptr;
18586 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18587 }
18588
18589 vkQueueWaitIdle(queue);
18590
18591 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18592 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18593 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18594 vkDestroyBuffer(m_device->device(), buffer, NULL);
18595 vkFreeMemory(m_device->device(), mem, NULL);
18596
18597 m_errorMonitor->VerifyNotFound();
18598}
18599
Tony Barbourc46924f2016-11-04 11:49:52 -060018600TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018601 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18602
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018603 ASSERT_NO_FATAL_FAILURE(InitState());
18604 VkEvent event;
18605 VkEventCreateInfo event_create_info{};
18606 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18607 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18608
18609 VkCommandPool command_pool;
18610 VkCommandPoolCreateInfo pool_create_info{};
18611 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18612 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18613 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18614 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18615
18616 VkCommandBuffer command_buffer;
18617 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18618 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18619 command_buffer_allocate_info.commandPool = command_pool;
18620 command_buffer_allocate_info.commandBufferCount = 1;
18621 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18622 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18623
18624 VkQueue queue = VK_NULL_HANDLE;
18625 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18626
18627 {
18628 VkCommandBufferBeginInfo begin_info{};
18629 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18630 vkBeginCommandBuffer(command_buffer, &begin_info);
18631
18632 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018633 vkEndCommandBuffer(command_buffer);
18634 }
18635 {
18636 VkSubmitInfo submit_info{};
18637 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18638 submit_info.commandBufferCount = 1;
18639 submit_info.pCommandBuffers = &command_buffer;
18640 submit_info.signalSemaphoreCount = 0;
18641 submit_info.pSignalSemaphores = nullptr;
18642 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18643 }
18644 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18646 "that is already in use by a "
18647 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018648 vkSetEvent(m_device->device(), event);
18649 m_errorMonitor->VerifyFound();
18650 }
18651
18652 vkQueueWaitIdle(queue);
18653
18654 vkDestroyEvent(m_device->device(), event, nullptr);
18655 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18656 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18657}
18658
18659// This is a positive test. No errors should be generated.
18660TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018661 TEST_DESCRIPTION(
18662 "Two command buffers with two separate fences are each "
18663 "run through a Submit & WaitForFences cycle 3 times. This "
18664 "previously revealed a bug so running this positive test "
18665 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018666 m_errorMonitor->ExpectSuccess();
18667
18668 ASSERT_NO_FATAL_FAILURE(InitState());
18669 VkQueue queue = VK_NULL_HANDLE;
18670 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18671
18672 static const uint32_t NUM_OBJECTS = 2;
18673 static const uint32_t NUM_FRAMES = 3;
18674 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18675 VkFence fences[NUM_OBJECTS] = {};
18676
18677 VkCommandPool cmd_pool;
18678 VkCommandPoolCreateInfo cmd_pool_ci = {};
18679 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18680 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18681 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18682 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18683 ASSERT_VK_SUCCESS(err);
18684
18685 VkCommandBufferAllocateInfo cmd_buf_info = {};
18686 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18687 cmd_buf_info.commandPool = cmd_pool;
18688 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18689 cmd_buf_info.commandBufferCount = 1;
18690
18691 VkFenceCreateInfo fence_ci = {};
18692 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18693 fence_ci.pNext = nullptr;
18694 fence_ci.flags = 0;
18695
18696 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18697 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18698 ASSERT_VK_SUCCESS(err);
18699 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18700 ASSERT_VK_SUCCESS(err);
18701 }
18702
18703 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18704 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18705 // Create empty cmd buffer
18706 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18707 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18708
18709 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18710 ASSERT_VK_SUCCESS(err);
18711 err = vkEndCommandBuffer(cmd_buffers[obj]);
18712 ASSERT_VK_SUCCESS(err);
18713
18714 VkSubmitInfo submit_info = {};
18715 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18716 submit_info.commandBufferCount = 1;
18717 submit_info.pCommandBuffers = &cmd_buffers[obj];
18718 // Submit cmd buffer and wait for fence
18719 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18720 ASSERT_VK_SUCCESS(err);
18721 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18722 ASSERT_VK_SUCCESS(err);
18723 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18724 ASSERT_VK_SUCCESS(err);
18725 }
18726 }
18727 m_errorMonitor->VerifyNotFound();
18728 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18729 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18730 vkDestroyFence(m_device->device(), fences[i], nullptr);
18731 }
18732}
18733// This is a positive test. No errors should be generated.
18734TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018735 TEST_DESCRIPTION(
18736 "Two command buffers, each in a separate QueueSubmit call "
18737 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018738
18739 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018740 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018741
18742 m_errorMonitor->ExpectSuccess();
18743
18744 VkSemaphore semaphore;
18745 VkSemaphoreCreateInfo semaphore_create_info{};
18746 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18747 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18748
18749 VkCommandPool command_pool;
18750 VkCommandPoolCreateInfo pool_create_info{};
18751 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18752 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18753 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18754 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18755
18756 VkCommandBuffer command_buffer[2];
18757 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18758 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18759 command_buffer_allocate_info.commandPool = command_pool;
18760 command_buffer_allocate_info.commandBufferCount = 2;
18761 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18762 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18763
18764 VkQueue queue = VK_NULL_HANDLE;
18765 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18766
18767 {
18768 VkCommandBufferBeginInfo begin_info{};
18769 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18770 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18771
18772 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 -070018773 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018774
18775 VkViewport viewport{};
18776 viewport.maxDepth = 1.0f;
18777 viewport.minDepth = 0.0f;
18778 viewport.width = 512;
18779 viewport.height = 512;
18780 viewport.x = 0;
18781 viewport.y = 0;
18782 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18783 vkEndCommandBuffer(command_buffer[0]);
18784 }
18785 {
18786 VkCommandBufferBeginInfo begin_info{};
18787 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18788 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18789
18790 VkViewport viewport{};
18791 viewport.maxDepth = 1.0f;
18792 viewport.minDepth = 0.0f;
18793 viewport.width = 512;
18794 viewport.height = 512;
18795 viewport.x = 0;
18796 viewport.y = 0;
18797 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18798 vkEndCommandBuffer(command_buffer[1]);
18799 }
18800 {
18801 VkSubmitInfo submit_info{};
18802 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18803 submit_info.commandBufferCount = 1;
18804 submit_info.pCommandBuffers = &command_buffer[0];
18805 submit_info.signalSemaphoreCount = 1;
18806 submit_info.pSignalSemaphores = &semaphore;
18807 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18808 }
18809 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018810 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018811 VkSubmitInfo submit_info{};
18812 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18813 submit_info.commandBufferCount = 1;
18814 submit_info.pCommandBuffers = &command_buffer[1];
18815 submit_info.waitSemaphoreCount = 1;
18816 submit_info.pWaitSemaphores = &semaphore;
18817 submit_info.pWaitDstStageMask = flags;
18818 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18819 }
18820
18821 vkQueueWaitIdle(m_device->m_queue);
18822
18823 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18824 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18825 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18826
18827 m_errorMonitor->VerifyNotFound();
18828}
18829
18830// This is a positive test. No errors should be generated.
18831TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018832 TEST_DESCRIPTION(
18833 "Two command buffers, each in a separate QueueSubmit call "
18834 "submitted on separate queues, the second having a fence"
18835 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018836
18837 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018838 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018839
18840 m_errorMonitor->ExpectSuccess();
18841
18842 VkFence fence;
18843 VkFenceCreateInfo fence_create_info{};
18844 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18845 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18846
18847 VkSemaphore semaphore;
18848 VkSemaphoreCreateInfo semaphore_create_info{};
18849 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18850 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18851
18852 VkCommandPool command_pool;
18853 VkCommandPoolCreateInfo pool_create_info{};
18854 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18855 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18856 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18857 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18858
18859 VkCommandBuffer command_buffer[2];
18860 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18861 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18862 command_buffer_allocate_info.commandPool = command_pool;
18863 command_buffer_allocate_info.commandBufferCount = 2;
18864 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18865 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18866
18867 VkQueue queue = VK_NULL_HANDLE;
18868 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18869
18870 {
18871 VkCommandBufferBeginInfo begin_info{};
18872 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18873 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18874
18875 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 -070018876 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018877
18878 VkViewport viewport{};
18879 viewport.maxDepth = 1.0f;
18880 viewport.minDepth = 0.0f;
18881 viewport.width = 512;
18882 viewport.height = 512;
18883 viewport.x = 0;
18884 viewport.y = 0;
18885 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18886 vkEndCommandBuffer(command_buffer[0]);
18887 }
18888 {
18889 VkCommandBufferBeginInfo begin_info{};
18890 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18891 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18892
18893 VkViewport viewport{};
18894 viewport.maxDepth = 1.0f;
18895 viewport.minDepth = 0.0f;
18896 viewport.width = 512;
18897 viewport.height = 512;
18898 viewport.x = 0;
18899 viewport.y = 0;
18900 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18901 vkEndCommandBuffer(command_buffer[1]);
18902 }
18903 {
18904 VkSubmitInfo submit_info{};
18905 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18906 submit_info.commandBufferCount = 1;
18907 submit_info.pCommandBuffers = &command_buffer[0];
18908 submit_info.signalSemaphoreCount = 1;
18909 submit_info.pSignalSemaphores = &semaphore;
18910 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18911 }
18912 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018913 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018914 VkSubmitInfo submit_info{};
18915 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18916 submit_info.commandBufferCount = 1;
18917 submit_info.pCommandBuffers = &command_buffer[1];
18918 submit_info.waitSemaphoreCount = 1;
18919 submit_info.pWaitSemaphores = &semaphore;
18920 submit_info.pWaitDstStageMask = flags;
18921 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18922 }
18923
18924 vkQueueWaitIdle(m_device->m_queue);
18925
18926 vkDestroyFence(m_device->device(), fence, nullptr);
18927 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18928 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18929 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18930
18931 m_errorMonitor->VerifyNotFound();
18932}
18933
18934// This is a positive test. No errors should be generated.
18935TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018936 TEST_DESCRIPTION(
18937 "Two command buffers, each in a separate QueueSubmit call "
18938 "submitted on separate queues, the second having a fence"
18939 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018940
18941 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018942 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018943
18944 m_errorMonitor->ExpectSuccess();
18945
18946 VkFence fence;
18947 VkFenceCreateInfo fence_create_info{};
18948 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18949 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18950
18951 VkSemaphore semaphore;
18952 VkSemaphoreCreateInfo semaphore_create_info{};
18953 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18954 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18955
18956 VkCommandPool command_pool;
18957 VkCommandPoolCreateInfo pool_create_info{};
18958 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18959 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18960 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18961 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18962
18963 VkCommandBuffer command_buffer[2];
18964 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18965 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18966 command_buffer_allocate_info.commandPool = command_pool;
18967 command_buffer_allocate_info.commandBufferCount = 2;
18968 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18969 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18970
18971 VkQueue queue = VK_NULL_HANDLE;
18972 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18973
18974 {
18975 VkCommandBufferBeginInfo begin_info{};
18976 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18977 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18978
18979 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 -070018980 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018981
18982 VkViewport viewport{};
18983 viewport.maxDepth = 1.0f;
18984 viewport.minDepth = 0.0f;
18985 viewport.width = 512;
18986 viewport.height = 512;
18987 viewport.x = 0;
18988 viewport.y = 0;
18989 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18990 vkEndCommandBuffer(command_buffer[0]);
18991 }
18992 {
18993 VkCommandBufferBeginInfo begin_info{};
18994 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18995 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18996
18997 VkViewport viewport{};
18998 viewport.maxDepth = 1.0f;
18999 viewport.minDepth = 0.0f;
19000 viewport.width = 512;
19001 viewport.height = 512;
19002 viewport.x = 0;
19003 viewport.y = 0;
19004 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19005 vkEndCommandBuffer(command_buffer[1]);
19006 }
19007 {
19008 VkSubmitInfo submit_info{};
19009 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19010 submit_info.commandBufferCount = 1;
19011 submit_info.pCommandBuffers = &command_buffer[0];
19012 submit_info.signalSemaphoreCount = 1;
19013 submit_info.pSignalSemaphores = &semaphore;
19014 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19015 }
19016 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019017 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019018 VkSubmitInfo submit_info{};
19019 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19020 submit_info.commandBufferCount = 1;
19021 submit_info.pCommandBuffers = &command_buffer[1];
19022 submit_info.waitSemaphoreCount = 1;
19023 submit_info.pWaitSemaphores = &semaphore;
19024 submit_info.pWaitDstStageMask = flags;
19025 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19026 }
19027
19028 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19029 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19030
19031 vkDestroyFence(m_device->device(), fence, nullptr);
19032 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19033 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19034 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19035
19036 m_errorMonitor->VerifyNotFound();
19037}
19038
19039TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019040 ASSERT_NO_FATAL_FAILURE(InitState());
19041 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
19042 printf("Test requires two queues, skipping\n");
19043 return;
19044 }
19045
19046 VkResult err;
19047
19048 m_errorMonitor->ExpectSuccess();
19049
19050 VkQueue q0 = m_device->m_queue;
19051 VkQueue q1 = nullptr;
19052 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
19053 ASSERT_NE(q1, nullptr);
19054
19055 // An (empty) command buffer. We must have work in the first submission --
19056 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019057 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019058 VkCommandPool pool;
19059 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
19060 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019061 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
19062 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019063 VkCommandBuffer cb;
19064 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
19065 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019066 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019067 err = vkBeginCommandBuffer(cb, &cbbi);
19068 ASSERT_VK_SUCCESS(err);
19069 err = vkEndCommandBuffer(cb);
19070 ASSERT_VK_SUCCESS(err);
19071
19072 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019073 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019074 VkSemaphore s;
19075 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
19076 ASSERT_VK_SUCCESS(err);
19077
19078 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019079 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019080
19081 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
19082 ASSERT_VK_SUCCESS(err);
19083
19084 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019085 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019086 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019087
19088 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
19089 ASSERT_VK_SUCCESS(err);
19090
19091 // Wait for q0 idle
19092 err = vkQueueWaitIdle(q0);
19093 ASSERT_VK_SUCCESS(err);
19094
19095 // Command buffer should have been completed (it was on q0); reset the pool.
19096 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
19097
19098 m_errorMonitor->VerifyNotFound();
19099
19100 // Force device completely idle and clean up resources
19101 vkDeviceWaitIdle(m_device->device());
19102 vkDestroyCommandPool(m_device->device(), pool, nullptr);
19103 vkDestroySemaphore(m_device->device(), s, nullptr);
19104}
19105
19106// This is a positive test. No errors should be generated.
19107TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019108 TEST_DESCRIPTION(
19109 "Two command buffers, each in a separate QueueSubmit call "
19110 "submitted on separate queues, the second having a fence, "
19111 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019112
19113 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019114 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019115
19116 m_errorMonitor->ExpectSuccess();
19117
19118 ASSERT_NO_FATAL_FAILURE(InitState());
19119 VkFence fence;
19120 VkFenceCreateInfo fence_create_info{};
19121 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19122 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19123
19124 VkSemaphore semaphore;
19125 VkSemaphoreCreateInfo semaphore_create_info{};
19126 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19127 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19128
19129 VkCommandPool command_pool;
19130 VkCommandPoolCreateInfo pool_create_info{};
19131 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19132 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19133 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19134 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19135
19136 VkCommandBuffer command_buffer[2];
19137 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19138 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19139 command_buffer_allocate_info.commandPool = command_pool;
19140 command_buffer_allocate_info.commandBufferCount = 2;
19141 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19142 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19143
19144 VkQueue queue = VK_NULL_HANDLE;
19145 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19146
19147 {
19148 VkCommandBufferBeginInfo begin_info{};
19149 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19150 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19151
19152 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 -070019153 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019154
19155 VkViewport viewport{};
19156 viewport.maxDepth = 1.0f;
19157 viewport.minDepth = 0.0f;
19158 viewport.width = 512;
19159 viewport.height = 512;
19160 viewport.x = 0;
19161 viewport.y = 0;
19162 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19163 vkEndCommandBuffer(command_buffer[0]);
19164 }
19165 {
19166 VkCommandBufferBeginInfo begin_info{};
19167 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19168 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19169
19170 VkViewport viewport{};
19171 viewport.maxDepth = 1.0f;
19172 viewport.minDepth = 0.0f;
19173 viewport.width = 512;
19174 viewport.height = 512;
19175 viewport.x = 0;
19176 viewport.y = 0;
19177 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19178 vkEndCommandBuffer(command_buffer[1]);
19179 }
19180 {
19181 VkSubmitInfo submit_info{};
19182 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19183 submit_info.commandBufferCount = 1;
19184 submit_info.pCommandBuffers = &command_buffer[0];
19185 submit_info.signalSemaphoreCount = 1;
19186 submit_info.pSignalSemaphores = &semaphore;
19187 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19188 }
19189 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019190 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019191 VkSubmitInfo submit_info{};
19192 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19193 submit_info.commandBufferCount = 1;
19194 submit_info.pCommandBuffers = &command_buffer[1];
19195 submit_info.waitSemaphoreCount = 1;
19196 submit_info.pWaitSemaphores = &semaphore;
19197 submit_info.pWaitDstStageMask = flags;
19198 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19199 }
19200
19201 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19202
19203 vkDestroyFence(m_device->device(), fence, nullptr);
19204 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19205 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19206 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19207
19208 m_errorMonitor->VerifyNotFound();
19209}
19210
19211// This is a positive test. No errors should be generated.
19212TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019213 TEST_DESCRIPTION(
19214 "Two command buffers, each in a separate QueueSubmit call "
19215 "on the same queue, sharing a signal/wait semaphore, the "
19216 "second having a fence, "
19217 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019218
19219 m_errorMonitor->ExpectSuccess();
19220
19221 ASSERT_NO_FATAL_FAILURE(InitState());
19222 VkFence fence;
19223 VkFenceCreateInfo fence_create_info{};
19224 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19225 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19226
19227 VkSemaphore semaphore;
19228 VkSemaphoreCreateInfo semaphore_create_info{};
19229 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19230 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19231
19232 VkCommandPool command_pool;
19233 VkCommandPoolCreateInfo pool_create_info{};
19234 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19235 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19236 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19237 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19238
19239 VkCommandBuffer command_buffer[2];
19240 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19241 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19242 command_buffer_allocate_info.commandPool = command_pool;
19243 command_buffer_allocate_info.commandBufferCount = 2;
19244 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19245 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19246
19247 {
19248 VkCommandBufferBeginInfo begin_info{};
19249 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19250 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19251
19252 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 -070019253 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019254
19255 VkViewport viewport{};
19256 viewport.maxDepth = 1.0f;
19257 viewport.minDepth = 0.0f;
19258 viewport.width = 512;
19259 viewport.height = 512;
19260 viewport.x = 0;
19261 viewport.y = 0;
19262 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19263 vkEndCommandBuffer(command_buffer[0]);
19264 }
19265 {
19266 VkCommandBufferBeginInfo begin_info{};
19267 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19268 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19269
19270 VkViewport viewport{};
19271 viewport.maxDepth = 1.0f;
19272 viewport.minDepth = 0.0f;
19273 viewport.width = 512;
19274 viewport.height = 512;
19275 viewport.x = 0;
19276 viewport.y = 0;
19277 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19278 vkEndCommandBuffer(command_buffer[1]);
19279 }
19280 {
19281 VkSubmitInfo submit_info{};
19282 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19283 submit_info.commandBufferCount = 1;
19284 submit_info.pCommandBuffers = &command_buffer[0];
19285 submit_info.signalSemaphoreCount = 1;
19286 submit_info.pSignalSemaphores = &semaphore;
19287 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19288 }
19289 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019290 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019291 VkSubmitInfo submit_info{};
19292 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19293 submit_info.commandBufferCount = 1;
19294 submit_info.pCommandBuffers = &command_buffer[1];
19295 submit_info.waitSemaphoreCount = 1;
19296 submit_info.pWaitSemaphores = &semaphore;
19297 submit_info.pWaitDstStageMask = flags;
19298 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19299 }
19300
19301 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19302
19303 vkDestroyFence(m_device->device(), fence, nullptr);
19304 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19305 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19306 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19307
19308 m_errorMonitor->VerifyNotFound();
19309}
19310
19311// This is a positive test. No errors should be generated.
19312TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019313 TEST_DESCRIPTION(
19314 "Two command buffers, each in a separate QueueSubmit call "
19315 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19316 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019317
19318 m_errorMonitor->ExpectSuccess();
19319
19320 ASSERT_NO_FATAL_FAILURE(InitState());
19321 VkFence fence;
19322 VkFenceCreateInfo fence_create_info{};
19323 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19324 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19325
19326 VkCommandPool command_pool;
19327 VkCommandPoolCreateInfo pool_create_info{};
19328 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19329 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19330 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19331 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19332
19333 VkCommandBuffer command_buffer[2];
19334 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19335 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19336 command_buffer_allocate_info.commandPool = command_pool;
19337 command_buffer_allocate_info.commandBufferCount = 2;
19338 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19339 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19340
19341 {
19342 VkCommandBufferBeginInfo begin_info{};
19343 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19344 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19345
19346 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 -070019347 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019348
19349 VkViewport viewport{};
19350 viewport.maxDepth = 1.0f;
19351 viewport.minDepth = 0.0f;
19352 viewport.width = 512;
19353 viewport.height = 512;
19354 viewport.x = 0;
19355 viewport.y = 0;
19356 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19357 vkEndCommandBuffer(command_buffer[0]);
19358 }
19359 {
19360 VkCommandBufferBeginInfo begin_info{};
19361 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19362 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19363
19364 VkViewport viewport{};
19365 viewport.maxDepth = 1.0f;
19366 viewport.minDepth = 0.0f;
19367 viewport.width = 512;
19368 viewport.height = 512;
19369 viewport.x = 0;
19370 viewport.y = 0;
19371 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19372 vkEndCommandBuffer(command_buffer[1]);
19373 }
19374 {
19375 VkSubmitInfo submit_info{};
19376 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19377 submit_info.commandBufferCount = 1;
19378 submit_info.pCommandBuffers = &command_buffer[0];
19379 submit_info.signalSemaphoreCount = 0;
19380 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19381 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19382 }
19383 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019384 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019385 VkSubmitInfo submit_info{};
19386 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19387 submit_info.commandBufferCount = 1;
19388 submit_info.pCommandBuffers = &command_buffer[1];
19389 submit_info.waitSemaphoreCount = 0;
19390 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19391 submit_info.pWaitDstStageMask = flags;
19392 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19393 }
19394
19395 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19396
19397 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19398 ASSERT_VK_SUCCESS(err);
19399
19400 vkDestroyFence(m_device->device(), fence, nullptr);
19401 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19402 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19403
19404 m_errorMonitor->VerifyNotFound();
19405}
19406
19407// This is a positive test. No errors should be generated.
19408TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019409 TEST_DESCRIPTION(
19410 "Two command buffers, each in a separate QueueSubmit call "
19411 "on the same queue, the second having a fence, followed "
19412 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019413
19414 m_errorMonitor->ExpectSuccess();
19415
19416 ASSERT_NO_FATAL_FAILURE(InitState());
19417 VkFence fence;
19418 VkFenceCreateInfo fence_create_info{};
19419 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19420 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19421
19422 VkCommandPool command_pool;
19423 VkCommandPoolCreateInfo pool_create_info{};
19424 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19425 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19426 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19427 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19428
19429 VkCommandBuffer command_buffer[2];
19430 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19431 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19432 command_buffer_allocate_info.commandPool = command_pool;
19433 command_buffer_allocate_info.commandBufferCount = 2;
19434 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19435 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19436
19437 {
19438 VkCommandBufferBeginInfo begin_info{};
19439 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19440 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19441
19442 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 -070019443 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019444
19445 VkViewport viewport{};
19446 viewport.maxDepth = 1.0f;
19447 viewport.minDepth = 0.0f;
19448 viewport.width = 512;
19449 viewport.height = 512;
19450 viewport.x = 0;
19451 viewport.y = 0;
19452 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19453 vkEndCommandBuffer(command_buffer[0]);
19454 }
19455 {
19456 VkCommandBufferBeginInfo begin_info{};
19457 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19458 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19459
19460 VkViewport viewport{};
19461 viewport.maxDepth = 1.0f;
19462 viewport.minDepth = 0.0f;
19463 viewport.width = 512;
19464 viewport.height = 512;
19465 viewport.x = 0;
19466 viewport.y = 0;
19467 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19468 vkEndCommandBuffer(command_buffer[1]);
19469 }
19470 {
19471 VkSubmitInfo submit_info{};
19472 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19473 submit_info.commandBufferCount = 1;
19474 submit_info.pCommandBuffers = &command_buffer[0];
19475 submit_info.signalSemaphoreCount = 0;
19476 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19477 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19478 }
19479 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019480 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019481 VkSubmitInfo submit_info{};
19482 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19483 submit_info.commandBufferCount = 1;
19484 submit_info.pCommandBuffers = &command_buffer[1];
19485 submit_info.waitSemaphoreCount = 0;
19486 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19487 submit_info.pWaitDstStageMask = flags;
19488 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19489 }
19490
19491 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19492
19493 vkDestroyFence(m_device->device(), fence, nullptr);
19494 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19495 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19496
19497 m_errorMonitor->VerifyNotFound();
19498}
19499
19500// This is a positive test. No errors should be generated.
19501TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019502 TEST_DESCRIPTION(
19503 "Two command buffers each in a separate SubmitInfo sent in a single "
19504 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019505 ASSERT_NO_FATAL_FAILURE(InitState());
19506
19507 m_errorMonitor->ExpectSuccess();
19508
19509 VkFence fence;
19510 VkFenceCreateInfo fence_create_info{};
19511 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19512 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19513
19514 VkSemaphore semaphore;
19515 VkSemaphoreCreateInfo semaphore_create_info{};
19516 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19517 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19518
19519 VkCommandPool command_pool;
19520 VkCommandPoolCreateInfo pool_create_info{};
19521 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19522 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19523 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19524 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19525
19526 VkCommandBuffer command_buffer[2];
19527 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19528 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19529 command_buffer_allocate_info.commandPool = command_pool;
19530 command_buffer_allocate_info.commandBufferCount = 2;
19531 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19532 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19533
19534 {
19535 VkCommandBufferBeginInfo begin_info{};
19536 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19537 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19538
19539 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 -070019540 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019541
19542 VkViewport viewport{};
19543 viewport.maxDepth = 1.0f;
19544 viewport.minDepth = 0.0f;
19545 viewport.width = 512;
19546 viewport.height = 512;
19547 viewport.x = 0;
19548 viewport.y = 0;
19549 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19550 vkEndCommandBuffer(command_buffer[0]);
19551 }
19552 {
19553 VkCommandBufferBeginInfo begin_info{};
19554 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19555 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19556
19557 VkViewport viewport{};
19558 viewport.maxDepth = 1.0f;
19559 viewport.minDepth = 0.0f;
19560 viewport.width = 512;
19561 viewport.height = 512;
19562 viewport.x = 0;
19563 viewport.y = 0;
19564 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19565 vkEndCommandBuffer(command_buffer[1]);
19566 }
19567 {
19568 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019569 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019570
19571 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19572 submit_info[0].pNext = NULL;
19573 submit_info[0].commandBufferCount = 1;
19574 submit_info[0].pCommandBuffers = &command_buffer[0];
19575 submit_info[0].signalSemaphoreCount = 1;
19576 submit_info[0].pSignalSemaphores = &semaphore;
19577 submit_info[0].waitSemaphoreCount = 0;
19578 submit_info[0].pWaitSemaphores = NULL;
19579 submit_info[0].pWaitDstStageMask = 0;
19580
19581 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19582 submit_info[1].pNext = NULL;
19583 submit_info[1].commandBufferCount = 1;
19584 submit_info[1].pCommandBuffers = &command_buffer[1];
19585 submit_info[1].waitSemaphoreCount = 1;
19586 submit_info[1].pWaitSemaphores = &semaphore;
19587 submit_info[1].pWaitDstStageMask = flags;
19588 submit_info[1].signalSemaphoreCount = 0;
19589 submit_info[1].pSignalSemaphores = NULL;
19590 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19591 }
19592
19593 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19594
19595 vkDestroyFence(m_device->device(), fence, nullptr);
19596 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19597 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19598 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19599
19600 m_errorMonitor->VerifyNotFound();
19601}
19602
19603TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19604 m_errorMonitor->ExpectSuccess();
19605
19606 ASSERT_NO_FATAL_FAILURE(InitState());
19607 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19608
Tony Barbour552f6c02016-12-21 14:34:07 -070019609 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019610
19611 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19612 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19613 m_errorMonitor->VerifyNotFound();
19614 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19615 m_errorMonitor->VerifyNotFound();
19616 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19617 m_errorMonitor->VerifyNotFound();
19618
19619 m_commandBuffer->EndCommandBuffer();
19620 m_errorMonitor->VerifyNotFound();
19621}
19622
19623TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019624 TEST_DESCRIPTION(
19625 "Positive test where we create a renderpass with an "
19626 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19627 "has a valid layout, and a second subpass then uses a "
19628 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019629 m_errorMonitor->ExpectSuccess();
19630 ASSERT_NO_FATAL_FAILURE(InitState());
19631
19632 VkAttachmentReference attach[2] = {};
19633 attach[0].attachment = 0;
19634 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19635 attach[1].attachment = 0;
19636 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19637 VkSubpassDescription subpasses[2] = {};
19638 // First subpass clears DS attach on load
19639 subpasses[0].pDepthStencilAttachment = &attach[0];
19640 // 2nd subpass reads in DS as input attachment
19641 subpasses[1].inputAttachmentCount = 1;
19642 subpasses[1].pInputAttachments = &attach[1];
19643 VkAttachmentDescription attach_desc = {};
19644 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19645 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19646 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19647 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19648 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19649 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19650 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19651 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19652 VkRenderPassCreateInfo rpci = {};
19653 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19654 rpci.attachmentCount = 1;
19655 rpci.pAttachments = &attach_desc;
19656 rpci.subpassCount = 2;
19657 rpci.pSubpasses = subpasses;
19658
19659 // Now create RenderPass and verify no errors
19660 VkRenderPass rp;
19661 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19662 m_errorMonitor->VerifyNotFound();
19663
19664 vkDestroyRenderPass(m_device->device(), rp, NULL);
19665}
19666
19667TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019668 TEST_DESCRIPTION(
19669 "Test that pipeline validation accepts matrices passed "
19670 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019671 m_errorMonitor->ExpectSuccess();
19672
19673 ASSERT_NO_FATAL_FAILURE(InitState());
19674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19675
19676 VkVertexInputBindingDescription input_binding;
19677 memset(&input_binding, 0, sizeof(input_binding));
19678
19679 VkVertexInputAttributeDescription input_attribs[2];
19680 memset(input_attribs, 0, sizeof(input_attribs));
19681
19682 for (int i = 0; i < 2; i++) {
19683 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19684 input_attribs[i].location = i;
19685 }
19686
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019687 char const *vsSource =
19688 "#version 450\n"
19689 "\n"
19690 "layout(location=0) in mat2x4 x;\n"
19691 "out gl_PerVertex {\n"
19692 " vec4 gl_Position;\n"
19693 "};\n"
19694 "void main(){\n"
19695 " gl_Position = x[0] + x[1];\n"
19696 "}\n";
19697 char const *fsSource =
19698 "#version 450\n"
19699 "\n"
19700 "layout(location=0) out vec4 color;\n"
19701 "void main(){\n"
19702 " color = vec4(1);\n"
19703 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019704
19705 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19706 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19707
19708 VkPipelineObj pipe(m_device);
19709 pipe.AddColorAttachment();
19710 pipe.AddShader(&vs);
19711 pipe.AddShader(&fs);
19712
19713 pipe.AddVertexInputBindings(&input_binding, 1);
19714 pipe.AddVertexInputAttribs(input_attribs, 2);
19715
19716 VkDescriptorSetObj descriptorSet(m_device);
19717 descriptorSet.AppendDummy();
19718 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19719
19720 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19721
19722 /* expect success */
19723 m_errorMonitor->VerifyNotFound();
19724}
19725
19726TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19727 m_errorMonitor->ExpectSuccess();
19728
19729 ASSERT_NO_FATAL_FAILURE(InitState());
19730 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19731
19732 VkVertexInputBindingDescription input_binding;
19733 memset(&input_binding, 0, sizeof(input_binding));
19734
19735 VkVertexInputAttributeDescription input_attribs[2];
19736 memset(input_attribs, 0, sizeof(input_attribs));
19737
19738 for (int i = 0; i < 2; i++) {
19739 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19740 input_attribs[i].location = i;
19741 }
19742
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019743 char const *vsSource =
19744 "#version 450\n"
19745 "\n"
19746 "layout(location=0) in vec4 x[2];\n"
19747 "out gl_PerVertex {\n"
19748 " vec4 gl_Position;\n"
19749 "};\n"
19750 "void main(){\n"
19751 " gl_Position = x[0] + x[1];\n"
19752 "}\n";
19753 char const *fsSource =
19754 "#version 450\n"
19755 "\n"
19756 "layout(location=0) out vec4 color;\n"
19757 "void main(){\n"
19758 " color = vec4(1);\n"
19759 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019760
19761 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19762 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19763
19764 VkPipelineObj pipe(m_device);
19765 pipe.AddColorAttachment();
19766 pipe.AddShader(&vs);
19767 pipe.AddShader(&fs);
19768
19769 pipe.AddVertexInputBindings(&input_binding, 1);
19770 pipe.AddVertexInputAttribs(input_attribs, 2);
19771
19772 VkDescriptorSetObj descriptorSet(m_device);
19773 descriptorSet.AppendDummy();
19774 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19775
19776 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19777
19778 m_errorMonitor->VerifyNotFound();
19779}
19780
19781TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019782 TEST_DESCRIPTION(
19783 "Test that pipeline validation accepts consuming a vertex attribute "
19784 "through multiple vertex shader inputs, each consuming a different "
19785 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019786 m_errorMonitor->ExpectSuccess();
19787
19788 ASSERT_NO_FATAL_FAILURE(InitState());
19789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19790
19791 VkVertexInputBindingDescription input_binding;
19792 memset(&input_binding, 0, sizeof(input_binding));
19793
19794 VkVertexInputAttributeDescription input_attribs[3];
19795 memset(input_attribs, 0, sizeof(input_attribs));
19796
19797 for (int i = 0; i < 3; i++) {
19798 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19799 input_attribs[i].location = i;
19800 }
19801
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019802 char const *vsSource =
19803 "#version 450\n"
19804 "\n"
19805 "layout(location=0) in vec4 x;\n"
19806 "layout(location=1) in vec3 y1;\n"
19807 "layout(location=1, component=3) in float y2;\n"
19808 "layout(location=2) in vec4 z;\n"
19809 "out gl_PerVertex {\n"
19810 " vec4 gl_Position;\n"
19811 "};\n"
19812 "void main(){\n"
19813 " gl_Position = x + vec4(y1, y2) + z;\n"
19814 "}\n";
19815 char const *fsSource =
19816 "#version 450\n"
19817 "\n"
19818 "layout(location=0) out vec4 color;\n"
19819 "void main(){\n"
19820 " color = vec4(1);\n"
19821 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019822
19823 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19824 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19825
19826 VkPipelineObj pipe(m_device);
19827 pipe.AddColorAttachment();
19828 pipe.AddShader(&vs);
19829 pipe.AddShader(&fs);
19830
19831 pipe.AddVertexInputBindings(&input_binding, 1);
19832 pipe.AddVertexInputAttribs(input_attribs, 3);
19833
19834 VkDescriptorSetObj descriptorSet(m_device);
19835 descriptorSet.AppendDummy();
19836 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19837
19838 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19839
19840 m_errorMonitor->VerifyNotFound();
19841}
19842
19843TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19844 m_errorMonitor->ExpectSuccess();
19845
19846 ASSERT_NO_FATAL_FAILURE(InitState());
19847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19848
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019849 char const *vsSource =
19850 "#version 450\n"
19851 "out gl_PerVertex {\n"
19852 " vec4 gl_Position;\n"
19853 "};\n"
19854 "void main(){\n"
19855 " gl_Position = vec4(0);\n"
19856 "}\n";
19857 char const *fsSource =
19858 "#version 450\n"
19859 "\n"
19860 "layout(location=0) out vec4 color;\n"
19861 "void main(){\n"
19862 " color = vec4(1);\n"
19863 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019864
19865 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19866 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19867
19868 VkPipelineObj pipe(m_device);
19869 pipe.AddColorAttachment();
19870 pipe.AddShader(&vs);
19871 pipe.AddShader(&fs);
19872
19873 VkDescriptorSetObj descriptorSet(m_device);
19874 descriptorSet.AppendDummy();
19875 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19876
19877 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19878
19879 m_errorMonitor->VerifyNotFound();
19880}
19881
19882TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019883 TEST_DESCRIPTION(
19884 "Test that pipeline validation accepts the relaxed type matching rules "
19885 "set out in 14.1.3: fundamental type must match, and producer side must "
19886 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019887 m_errorMonitor->ExpectSuccess();
19888
19889 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19890
19891 ASSERT_NO_FATAL_FAILURE(InitState());
19892 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19893
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019894 char const *vsSource =
19895 "#version 450\n"
19896 "out gl_PerVertex {\n"
19897 " vec4 gl_Position;\n"
19898 "};\n"
19899 "layout(location=0) out vec3 x;\n"
19900 "layout(location=1) out ivec3 y;\n"
19901 "layout(location=2) out vec3 z;\n"
19902 "void main(){\n"
19903 " gl_Position = vec4(0);\n"
19904 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19905 "}\n";
19906 char const *fsSource =
19907 "#version 450\n"
19908 "\n"
19909 "layout(location=0) out vec4 color;\n"
19910 "layout(location=0) in float x;\n"
19911 "layout(location=1) flat in int y;\n"
19912 "layout(location=2) in vec2 z;\n"
19913 "void main(){\n"
19914 " color = vec4(1 + x + y + z.x);\n"
19915 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019916
19917 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19919
19920 VkPipelineObj pipe(m_device);
19921 pipe.AddColorAttachment();
19922 pipe.AddShader(&vs);
19923 pipe.AddShader(&fs);
19924
19925 VkDescriptorSetObj descriptorSet(m_device);
19926 descriptorSet.AppendDummy();
19927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19928
19929 VkResult err = VK_SUCCESS;
19930 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19931 ASSERT_VK_SUCCESS(err);
19932
19933 m_errorMonitor->VerifyNotFound();
19934}
19935
19936TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019937 TEST_DESCRIPTION(
19938 "Test that pipeline validation accepts per-vertex variables "
19939 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019940 m_errorMonitor->ExpectSuccess();
19941
19942 ASSERT_NO_FATAL_FAILURE(InitState());
19943 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19944
19945 if (!m_device->phy().features().tessellationShader) {
19946 printf("Device does not support tessellation shaders; skipped.\n");
19947 return;
19948 }
19949
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019950 char const *vsSource =
19951 "#version 450\n"
19952 "void main(){}\n";
19953 char const *tcsSource =
19954 "#version 450\n"
19955 "layout(location=0) out int x[];\n"
19956 "layout(vertices=3) out;\n"
19957 "void main(){\n"
19958 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19959 " gl_TessLevelInner[0] = 1;\n"
19960 " x[gl_InvocationID] = gl_InvocationID;\n"
19961 "}\n";
19962 char const *tesSource =
19963 "#version 450\n"
19964 "layout(triangles, equal_spacing, cw) in;\n"
19965 "layout(location=0) in int x[];\n"
19966 "out gl_PerVertex { vec4 gl_Position; };\n"
19967 "void main(){\n"
19968 " gl_Position.xyz = gl_TessCoord;\n"
19969 " gl_Position.w = x[0] + x[1] + x[2];\n"
19970 "}\n";
19971 char const *fsSource =
19972 "#version 450\n"
19973 "layout(location=0) out vec4 color;\n"
19974 "void main(){\n"
19975 " color = vec4(1);\n"
19976 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019977
19978 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19979 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19980 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19981 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19982
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019983 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19984 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019985
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019986 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019987
19988 VkPipelineObj pipe(m_device);
19989 pipe.SetInputAssembly(&iasci);
19990 pipe.SetTessellation(&tsci);
19991 pipe.AddColorAttachment();
19992 pipe.AddShader(&vs);
19993 pipe.AddShader(&tcs);
19994 pipe.AddShader(&tes);
19995 pipe.AddShader(&fs);
19996
19997 VkDescriptorSetObj descriptorSet(m_device);
19998 descriptorSet.AppendDummy();
19999 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20000
20001 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20002
20003 m_errorMonitor->VerifyNotFound();
20004}
20005
20006TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020007 TEST_DESCRIPTION(
20008 "Test that pipeline validation accepts a user-defined "
20009 "interface block passed into the geometry shader. This "
20010 "is interesting because the 'extra' array level is not "
20011 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020012 m_errorMonitor->ExpectSuccess();
20013
20014 ASSERT_NO_FATAL_FAILURE(InitState());
20015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20016
20017 if (!m_device->phy().features().geometryShader) {
20018 printf("Device does not support geometry shaders; skipped.\n");
20019 return;
20020 }
20021
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020022 char const *vsSource =
20023 "#version 450\n"
20024 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
20025 "void main(){\n"
20026 " vs_out.x = vec4(1);\n"
20027 "}\n";
20028 char const *gsSource =
20029 "#version 450\n"
20030 "layout(triangles) in;\n"
20031 "layout(triangle_strip, max_vertices=3) out;\n"
20032 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
20033 "out gl_PerVertex { vec4 gl_Position; };\n"
20034 "void main() {\n"
20035 " gl_Position = gs_in[0].x;\n"
20036 " EmitVertex();\n"
20037 "}\n";
20038 char const *fsSource =
20039 "#version 450\n"
20040 "layout(location=0) out vec4 color;\n"
20041 "void main(){\n"
20042 " color = vec4(1);\n"
20043 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020044
20045 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20046 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
20047 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20048
20049 VkPipelineObj pipe(m_device);
20050 pipe.AddColorAttachment();
20051 pipe.AddShader(&vs);
20052 pipe.AddShader(&gs);
20053 pipe.AddShader(&fs);
20054
20055 VkDescriptorSetObj descriptorSet(m_device);
20056 descriptorSet.AppendDummy();
20057 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20058
20059 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20060
20061 m_errorMonitor->VerifyNotFound();
20062}
20063
20064TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020065 TEST_DESCRIPTION(
20066 "Test that pipeline validation accepts basic use of 64bit vertex "
20067 "attributes. This is interesting because they consume multiple "
20068 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020069 m_errorMonitor->ExpectSuccess();
20070
20071 ASSERT_NO_FATAL_FAILURE(InitState());
20072 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20073
20074 if (!m_device->phy().features().shaderFloat64) {
20075 printf("Device does not support 64bit vertex attributes; skipped.\n");
20076 return;
20077 }
20078
20079 VkVertexInputBindingDescription input_bindings[1];
20080 memset(input_bindings, 0, sizeof(input_bindings));
20081
20082 VkVertexInputAttributeDescription input_attribs[4];
20083 memset(input_attribs, 0, sizeof(input_attribs));
20084 input_attribs[0].location = 0;
20085 input_attribs[0].offset = 0;
20086 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20087 input_attribs[1].location = 2;
20088 input_attribs[1].offset = 32;
20089 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20090 input_attribs[2].location = 4;
20091 input_attribs[2].offset = 64;
20092 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20093 input_attribs[3].location = 6;
20094 input_attribs[3].offset = 96;
20095 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20096
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020097 char const *vsSource =
20098 "#version 450\n"
20099 "\n"
20100 "layout(location=0) in dmat4 x;\n"
20101 "out gl_PerVertex {\n"
20102 " vec4 gl_Position;\n"
20103 "};\n"
20104 "void main(){\n"
20105 " gl_Position = vec4(x[0][0]);\n"
20106 "}\n";
20107 char const *fsSource =
20108 "#version 450\n"
20109 "\n"
20110 "layout(location=0) out vec4 color;\n"
20111 "void main(){\n"
20112 " color = vec4(1);\n"
20113 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020114
20115 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20116 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20117
20118 VkPipelineObj pipe(m_device);
20119 pipe.AddColorAttachment();
20120 pipe.AddShader(&vs);
20121 pipe.AddShader(&fs);
20122
20123 pipe.AddVertexInputBindings(input_bindings, 1);
20124 pipe.AddVertexInputAttribs(input_attribs, 4);
20125
20126 VkDescriptorSetObj descriptorSet(m_device);
20127 descriptorSet.AppendDummy();
20128 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20129
20130 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20131
20132 m_errorMonitor->VerifyNotFound();
20133}
20134
20135TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20136 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20137 m_errorMonitor->ExpectSuccess();
20138
20139 ASSERT_NO_FATAL_FAILURE(InitState());
20140
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020141 char const *vsSource =
20142 "#version 450\n"
20143 "\n"
20144 "out gl_PerVertex {\n"
20145 " vec4 gl_Position;\n"
20146 "};\n"
20147 "void main(){\n"
20148 " gl_Position = vec4(1);\n"
20149 "}\n";
20150 char const *fsSource =
20151 "#version 450\n"
20152 "\n"
20153 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20154 "layout(location=0) out vec4 color;\n"
20155 "void main() {\n"
20156 " color = subpassLoad(x);\n"
20157 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020158
20159 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20160 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20161
20162 VkPipelineObj pipe(m_device);
20163 pipe.AddShader(&vs);
20164 pipe.AddShader(&fs);
20165 pipe.AddColorAttachment();
20166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20167
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020168 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
20169 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020170 VkDescriptorSetLayout dsl;
20171 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20172 ASSERT_VK_SUCCESS(err);
20173
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020174 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020175 VkPipelineLayout pl;
20176 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20177 ASSERT_VK_SUCCESS(err);
20178
20179 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020180 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20181 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20182 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
20183 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20184 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 -060020185 };
20186 VkAttachmentReference color = {
20187 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20188 };
20189 VkAttachmentReference input = {
20190 1, VK_IMAGE_LAYOUT_GENERAL,
20191 };
20192
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020193 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020194
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020195 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020196 VkRenderPass rp;
20197 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20198 ASSERT_VK_SUCCESS(err);
20199
20200 // should be OK. would go wrong here if it's going to...
20201 pipe.CreateVKPipeline(pl, rp);
20202
20203 m_errorMonitor->VerifyNotFound();
20204
20205 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20206 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20207 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20208}
20209
20210TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020211 TEST_DESCRIPTION(
20212 "Test that pipeline validation accepts a compute pipeline which declares a "
20213 "descriptor-backed resource which is not provided, but the shader does not "
20214 "statically use it. This is interesting because it requires compute pipelines "
20215 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020216 m_errorMonitor->ExpectSuccess();
20217
20218 ASSERT_NO_FATAL_FAILURE(InitState());
20219
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020220 char const *csSource =
20221 "#version 450\n"
20222 "\n"
20223 "layout(local_size_x=1) in;\n"
20224 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20225 "void main(){\n"
20226 " // x is not used.\n"
20227 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020228
20229 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20230
20231 VkDescriptorSetObj descriptorSet(m_device);
20232 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20233
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020234 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20235 nullptr,
20236 0,
20237 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20238 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20239 descriptorSet.GetPipelineLayout(),
20240 VK_NULL_HANDLE,
20241 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020242
20243 VkPipeline pipe;
20244 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20245
20246 m_errorMonitor->VerifyNotFound();
20247
20248 if (err == VK_SUCCESS) {
20249 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20250 }
20251}
20252
20253TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020254 TEST_DESCRIPTION(
20255 "Test that pipeline validation accepts a shader consuming only the "
20256 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020257 m_errorMonitor->ExpectSuccess();
20258
20259 ASSERT_NO_FATAL_FAILURE(InitState());
20260
20261 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020262 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20263 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20264 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020265 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020266 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020267 VkDescriptorSetLayout dsl;
20268 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20269 ASSERT_VK_SUCCESS(err);
20270
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020271 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020272 VkPipelineLayout pl;
20273 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20274 ASSERT_VK_SUCCESS(err);
20275
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020276 char const *csSource =
20277 "#version 450\n"
20278 "\n"
20279 "layout(local_size_x=1) in;\n"
20280 "layout(set=0, binding=0) uniform sampler s;\n"
20281 "layout(set=0, binding=1) uniform texture2D t;\n"
20282 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20283 "void main() {\n"
20284 " x = texture(sampler2D(t, s), vec2(0));\n"
20285 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020286 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20287
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020288 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20289 nullptr,
20290 0,
20291 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20292 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20293 pl,
20294 VK_NULL_HANDLE,
20295 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020296
20297 VkPipeline pipe;
20298 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20299
20300 m_errorMonitor->VerifyNotFound();
20301
20302 if (err == VK_SUCCESS) {
20303 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20304 }
20305
20306 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20307 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20308}
20309
20310TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020311 TEST_DESCRIPTION(
20312 "Test that pipeline validation accepts a shader consuming only the "
20313 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020314 m_errorMonitor->ExpectSuccess();
20315
20316 ASSERT_NO_FATAL_FAILURE(InitState());
20317
20318 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020319 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20320 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20321 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020322 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020323 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020324 VkDescriptorSetLayout dsl;
20325 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20326 ASSERT_VK_SUCCESS(err);
20327
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020328 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020329 VkPipelineLayout pl;
20330 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20331 ASSERT_VK_SUCCESS(err);
20332
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020333 char const *csSource =
20334 "#version 450\n"
20335 "\n"
20336 "layout(local_size_x=1) in;\n"
20337 "layout(set=0, binding=0) uniform texture2D t;\n"
20338 "layout(set=0, binding=1) uniform sampler s;\n"
20339 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20340 "void main() {\n"
20341 " x = texture(sampler2D(t, s), vec2(0));\n"
20342 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020343 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20344
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020345 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20346 nullptr,
20347 0,
20348 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20349 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20350 pl,
20351 VK_NULL_HANDLE,
20352 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020353
20354 VkPipeline pipe;
20355 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20356
20357 m_errorMonitor->VerifyNotFound();
20358
20359 if (err == VK_SUCCESS) {
20360 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20361 }
20362
20363 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20364 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20365}
20366
20367TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020368 TEST_DESCRIPTION(
20369 "Test that pipeline validation accepts a shader consuming "
20370 "both the sampler and the image of a combined image+sampler "
20371 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020372 m_errorMonitor->ExpectSuccess();
20373
20374 ASSERT_NO_FATAL_FAILURE(InitState());
20375
20376 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020377 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20378 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020379 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020380 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020381 VkDescriptorSetLayout dsl;
20382 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20383 ASSERT_VK_SUCCESS(err);
20384
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020385 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020386 VkPipelineLayout pl;
20387 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20388 ASSERT_VK_SUCCESS(err);
20389
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020390 char const *csSource =
20391 "#version 450\n"
20392 "\n"
20393 "layout(local_size_x=1) in;\n"
20394 "layout(set=0, binding=0) uniform texture2D t;\n"
20395 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20396 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20397 "void main() {\n"
20398 " x = texture(sampler2D(t, s), vec2(0));\n"
20399 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020400 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20401
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020402 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20403 nullptr,
20404 0,
20405 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20406 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20407 pl,
20408 VK_NULL_HANDLE,
20409 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020410
20411 VkPipeline pipe;
20412 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20413
20414 m_errorMonitor->VerifyNotFound();
20415
20416 if (err == VK_SUCCESS) {
20417 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20418 }
20419
20420 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20421 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20422}
20423
20424TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20425 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20426
20427 ASSERT_NO_FATAL_FAILURE(InitState());
20428
20429 // Positive test to check parameter_validation and unique_objects support
20430 // for NV_dedicated_allocation
20431 uint32_t extension_count = 0;
20432 bool supports_nv_dedicated_allocation = false;
20433 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20434 ASSERT_VK_SUCCESS(err);
20435
20436 if (extension_count > 0) {
20437 std::vector<VkExtensionProperties> available_extensions(extension_count);
20438
20439 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20440 ASSERT_VK_SUCCESS(err);
20441
20442 for (const auto &extension_props : available_extensions) {
20443 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20444 supports_nv_dedicated_allocation = true;
20445 }
20446 }
20447 }
20448
20449 if (supports_nv_dedicated_allocation) {
20450 m_errorMonitor->ExpectSuccess();
20451
20452 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20453 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20454 dedicated_buffer_create_info.pNext = nullptr;
20455 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20456
20457 uint32_t queue_family_index = 0;
20458 VkBufferCreateInfo buffer_create_info = {};
20459 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20460 buffer_create_info.pNext = &dedicated_buffer_create_info;
20461 buffer_create_info.size = 1024;
20462 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20463 buffer_create_info.queueFamilyIndexCount = 1;
20464 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20465
20466 VkBuffer buffer;
20467 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20468 ASSERT_VK_SUCCESS(err);
20469
20470 VkMemoryRequirements memory_reqs;
20471 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20472
20473 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20474 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20475 dedicated_memory_info.pNext = nullptr;
20476 dedicated_memory_info.buffer = buffer;
20477 dedicated_memory_info.image = VK_NULL_HANDLE;
20478
20479 VkMemoryAllocateInfo memory_info = {};
20480 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20481 memory_info.pNext = &dedicated_memory_info;
20482 memory_info.allocationSize = memory_reqs.size;
20483
20484 bool pass;
20485 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20486 ASSERT_TRUE(pass);
20487
20488 VkDeviceMemory buffer_memory;
20489 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20490 ASSERT_VK_SUCCESS(err);
20491
20492 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20493 ASSERT_VK_SUCCESS(err);
20494
20495 vkDestroyBuffer(m_device->device(), buffer, NULL);
20496 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20497
20498 m_errorMonitor->VerifyNotFound();
20499 }
20500}
20501
20502TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20503 VkResult err;
20504
20505 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20506
20507 ASSERT_NO_FATAL_FAILURE(InitState());
20508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20509
20510 std::vector<const char *> device_extension_names;
20511 auto features = m_device->phy().features();
20512 // Artificially disable support for non-solid fill modes
20513 features.fillModeNonSolid = false;
20514 // The sacrificial device object
20515 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20516
20517 VkRenderpassObj render_pass(&test_device);
20518
20519 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20520 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20521 pipeline_layout_ci.setLayoutCount = 0;
20522 pipeline_layout_ci.pSetLayouts = NULL;
20523
20524 VkPipelineLayout pipeline_layout;
20525 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20526 ASSERT_VK_SUCCESS(err);
20527
20528 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20529 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20530 rs_ci.pNext = nullptr;
20531 rs_ci.lineWidth = 1.0f;
20532 rs_ci.rasterizerDiscardEnable = true;
20533
20534 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20535 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20536
20537 // Set polygonMode=FILL. No error is expected
20538 m_errorMonitor->ExpectSuccess();
20539 {
20540 VkPipelineObj pipe(&test_device);
20541 pipe.AddShader(&vs);
20542 pipe.AddShader(&fs);
20543 pipe.AddColorAttachment();
20544 // Set polygonMode to a good value
20545 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20546 pipe.SetRasterization(&rs_ci);
20547 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20548 }
20549 m_errorMonitor->VerifyNotFound();
20550
20551 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20552}
20553
20554TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20555 VkResult err;
20556 ASSERT_NO_FATAL_FAILURE(InitState());
20557 ASSERT_NO_FATAL_FAILURE(InitViewport());
20558 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20559
20560 VkPipelineLayout pipeline_layout;
20561 VkPushConstantRange pc_range = {};
20562 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20563 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20564 pipeline_layout_ci.pushConstantRangeCount = 1;
20565 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20566
20567 //
20568 // Check for invalid push constant ranges in pipeline layouts.
20569 //
20570 struct PipelineLayoutTestCase {
20571 VkPushConstantRange const range;
20572 char const *msg;
20573 };
20574
20575 // Check for overlapping ranges
20576 const uint32_t ranges_per_test = 5;
20577 struct OverlappingRangeTestCase {
20578 VkPushConstantRange const ranges[ranges_per_test];
20579 char const *msg;
20580 };
20581
20582 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020583 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
20584 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
20585 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
20586 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
20587 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
20588 ""},
20589 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
20590 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
20591 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
20592 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
20593 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
20594 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020595 for (const auto &iter : overlapping_range_tests_pos) {
20596 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20597 m_errorMonitor->ExpectSuccess();
20598 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20599 m_errorMonitor->VerifyNotFound();
20600 if (VK_SUCCESS == err) {
20601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20602 }
20603 }
20604
20605 //
20606 // CmdPushConstants tests
20607 //
20608 const uint8_t dummy_values[100] = {};
20609
Tony Barbour552f6c02016-12-21 14:34:07 -070020610 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020611
20612 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020613 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
20614 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
20615 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
20616 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
20617 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
20618 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020619
20620 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20621 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020622 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
20623 {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 -060020624 };
20625
20626 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20627 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20628 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20629 ASSERT_VK_SUCCESS(err);
20630 for (const auto &iter : cmd_overlap_tests_pos) {
20631 m_errorMonitor->ExpectSuccess();
20632 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020633 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020634 m_errorMonitor->VerifyNotFound();
20635 }
20636 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20637
Tony Barbour552f6c02016-12-21 14:34:07 -070020638 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020639}
20640
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020641#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020642TEST_F(VkPositiveLayerTest, LongFenceChain)
20643{
20644 m_errorMonitor->ExpectSuccess();
20645
20646 ASSERT_NO_FATAL_FAILURE(InitState());
20647 VkResult err;
20648
20649 std::vector<VkFence> fences;
20650
20651 const int chainLength = 32768;
20652
20653 for (int i = 0; i < chainLength; i++) {
20654 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20655 VkFence fence;
20656 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20657 ASSERT_VK_SUCCESS(err);
20658
20659 fences.push_back(fence);
20660
20661 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20662 0, nullptr, 0, nullptr };
20663 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20664 ASSERT_VK_SUCCESS(err);
20665
20666 }
20667
20668 // BOOM, stack overflow.
20669 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20670
20671 for (auto fence : fences)
20672 vkDestroyFence(m_device->device(), fence, nullptr);
20673
20674 m_errorMonitor->VerifyNotFound();
20675}
20676#endif
20677
Cody Northrop1242dfd2016-07-13 17:24:59 -060020678#if defined(ANDROID) && defined(VALIDATION_APK)
20679static bool initialized = false;
20680static bool active = false;
20681
20682// Convert Intents to argv
20683// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020684std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020685 std::vector<std::string> args;
20686 JavaVM &vm = *app.activity->vm;
20687 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020688 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020689
20690 JNIEnv &env = *p_env;
20691 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020692 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020693 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020694 jmethodID get_string_extra_method =
20695 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020696 jvalue get_string_extra_args;
20697 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020698 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020699
20700 std::string args_str;
20701 if (extra_str) {
20702 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20703 args_str = extra_utf;
20704 env.ReleaseStringUTFChars(extra_str, extra_utf);
20705 env.DeleteLocalRef(extra_str);
20706 }
20707
20708 env.DeleteLocalRef(get_string_extra_args.l);
20709 env.DeleteLocalRef(intent);
20710 vm.DetachCurrentThread();
20711
20712 // split args_str
20713 std::stringstream ss(args_str);
20714 std::string arg;
20715 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020716 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020717 }
20718
20719 return args;
20720}
20721
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020722static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020723
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020724static void processCommand(struct android_app *app, int32_t cmd) {
20725 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020726 case APP_CMD_INIT_WINDOW: {
20727 if (app->window) {
20728 initialized = true;
20729 }
20730 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020731 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020732 case APP_CMD_GAINED_FOCUS: {
20733 active = true;
20734 break;
20735 }
20736 case APP_CMD_LOST_FOCUS: {
20737 active = false;
20738 break;
20739 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020740 }
20741}
20742
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020743void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020744 app_dummy();
20745
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020746 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020747
20748 int vulkanSupport = InitVulkan();
20749 if (vulkanSupport == 0) {
20750 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20751 return;
20752 }
20753
20754 app->onAppCmd = processCommand;
20755 app->onInputEvent = processInput;
20756
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020757 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020758 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020759 struct android_poll_source *source;
20760 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020761 if (source) {
20762 source->process(app, source);
20763 }
20764
20765 if (app->destroyRequested != 0) {
20766 VkTestFramework::Finish();
20767 return;
20768 }
20769 }
20770
20771 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020772 // Use the following key to send arguments to gtest, i.e.
20773 // --es args "--gtest_filter=-VkLayerTest.foo"
20774 const char key[] = "args";
20775 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020777 std::string filter = "";
20778 if (args.size() > 0) {
20779 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20780 filter += args[0];
20781 } else {
20782 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20783 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020785 int argc = 2;
20786 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20787 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020788
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020789 // Route output to files until we can override the gtest output
20790 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20791 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020793 ::testing::InitGoogleTest(&argc, argv);
20794 VkTestFramework::InitArgs(&argc, argv);
20795 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020797 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020798
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020799 if (result != 0) {
20800 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20801 } else {
20802 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20803 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020804
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020805 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020806
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020807 fclose(stdout);
20808 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020809
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020810 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020811
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020812 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020813 }
20814 }
20815}
20816#endif
20817
Tony Barbour300a6082015-04-07 13:44:53 -060020818int main(int argc, char **argv) {
20819 int result;
20820
Cody Northrop8e54a402016-03-08 22:25:52 -070020821#ifdef ANDROID
20822 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020823 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070020824#endif
20825
Tony Barbour300a6082015-04-07 13:44:53 -060020826 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020827 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020828
20829 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20830
20831 result = RUN_ALL_TESTS();
20832
Tony Barbour6918cd52015-04-09 12:58:51 -060020833 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020834 return result;
20835}