blob: 7a64082672392b9946f8e82e719b5cbce3284694 [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
Dave Houlton829c0d82017-01-24 15:09:17 -07001319TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1320 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1321
1322 // Determine which device feature are available
1323 VkPhysicalDeviceFeatures available_features;
1324 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1325
1326 // Mask out device features we don't want
1327 VkPhysicalDeviceFeatures desired_features = available_features;
1328 desired_features.sparseResidencyImage2D = VK_FALSE;
1329 desired_features.sparseResidencyImage3D = VK_FALSE;
1330 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1331
1332 VkImage image = VK_NULL_HANDLE;
1333 VkResult result = VK_RESULT_MAX_ENUM;
1334 VkImageCreateInfo image_create_info = {};
1335 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1336 image_create_info.pNext = NULL;
1337 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1338 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1339 image_create_info.extent.width = 512;
1340 image_create_info.extent.height = 1;
1341 image_create_info.extent.depth = 1;
1342 image_create_info.mipLevels = 1;
1343 image_create_info.arrayLayers = 1;
1344 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1345 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1346 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1347 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1348 image_create_info.queueFamilyIndexCount = 0;
1349 image_create_info.pQueueFamilyIndices = NULL;
1350 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1351 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1352
1353 // 1D image w/ sparse residency is an error
1354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1355 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1356 m_errorMonitor->VerifyFound();
1357 if (VK_SUCCESS == result) {
1358 vkDestroyImage(m_device->device(), image, NULL);
1359 image = VK_NULL_HANDLE;
1360 }
1361
1362 // 2D image w/ sparse residency when feature isn't available
1363 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1364 image_create_info.extent.height = 64;
1365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1366 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1367 m_errorMonitor->VerifyFound();
1368 if (VK_SUCCESS == result) {
1369 vkDestroyImage(m_device->device(), image, NULL);
1370 image = VK_NULL_HANDLE;
1371 }
1372
1373 // 3D image w/ sparse residency when feature isn't available
1374 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1375 image_create_info.extent.depth = 8;
1376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1377 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1378 m_errorMonitor->VerifyFound();
1379 if (VK_SUCCESS == result) {
1380 vkDestroyImage(m_device->device(), image, NULL);
1381 image = VK_NULL_HANDLE;
1382 }
1383}
1384
1385TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1386 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1387
1388 // Determine which device feature are available
1389 VkPhysicalDeviceFeatures available_features;
1390 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1391
1392 // These tests all require that the device support sparse residency for 2D images
1393 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1394 return;
1395 }
1396
1397 // Mask out device features we don't want
1398 VkPhysicalDeviceFeatures desired_features = available_features;
1399 desired_features.sparseResidency2Samples = VK_FALSE;
1400 desired_features.sparseResidency4Samples = VK_FALSE;
1401 desired_features.sparseResidency8Samples = VK_FALSE;
1402 desired_features.sparseResidency16Samples = VK_FALSE;
1403 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1404
1405 VkImage image = VK_NULL_HANDLE;
1406 VkResult result = VK_RESULT_MAX_ENUM;
1407 VkImageCreateInfo image_create_info = {};
1408 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1409 image_create_info.pNext = NULL;
1410 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1411 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1412 image_create_info.extent.width = 64;
1413 image_create_info.extent.height = 64;
1414 image_create_info.extent.depth = 1;
1415 image_create_info.mipLevels = 1;
1416 image_create_info.arrayLayers = 1;
1417 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1418 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1419 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1420 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1421 image_create_info.queueFamilyIndexCount = 0;
1422 image_create_info.pQueueFamilyIndices = NULL;
1423 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1424 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1425
1426 // 2D image w/ sparse residency and linear tiling is an error
1427 m_errorMonitor->SetDesiredFailureMsg(
1428 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1429 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1430 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1431 m_errorMonitor->VerifyFound();
1432 if (VK_SUCCESS == result) {
1433 vkDestroyImage(m_device->device(), image, NULL);
1434 image = VK_NULL_HANDLE;
1435 }
1436 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1437
1438 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1439 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1441 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1442 m_errorMonitor->VerifyFound();
1443 if (VK_SUCCESS == result) {
1444 vkDestroyImage(m_device->device(), image, NULL);
1445 image = VK_NULL_HANDLE;
1446 }
1447
1448 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1450 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1451 m_errorMonitor->VerifyFound();
1452 if (VK_SUCCESS == result) {
1453 vkDestroyImage(m_device->device(), image, NULL);
1454 image = VK_NULL_HANDLE;
1455 }
1456
1457 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1459 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1460 m_errorMonitor->VerifyFound();
1461 if (VK_SUCCESS == result) {
1462 vkDestroyImage(m_device->device(), image, NULL);
1463 image = VK_NULL_HANDLE;
1464 }
1465
1466 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1468 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1469 m_errorMonitor->VerifyFound();
1470 if (VK_SUCCESS == result) {
1471 vkDestroyImage(m_device->device(), image, NULL);
1472 image = VK_NULL_HANDLE;
1473 }
1474}
1475
Tobin Ehlisf11be982016-05-11 13:52:53 -06001476TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001477 TEST_DESCRIPTION(
1478 "Create a buffer and image, allocate memory, and bind the "
1479 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001480 VkResult err;
1481 bool pass;
1482 ASSERT_NO_FATAL_FAILURE(InitState());
1483
Tobin Ehlis077ded32016-05-12 17:39:13 -06001484 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001485 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001486 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001487 VkDeviceMemory mem; // buffer will be bound first
1488 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001489 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001490 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001491
1492 VkBufferCreateInfo buf_info = {};
1493 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1494 buf_info.pNext = NULL;
1495 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1496 buf_info.size = 256;
1497 buf_info.queueFamilyIndexCount = 0;
1498 buf_info.pQueueFamilyIndices = NULL;
1499 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1500 buf_info.flags = 0;
1501 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1502 ASSERT_VK_SUCCESS(err);
1503
Tobin Ehlis077ded32016-05-12 17:39:13 -06001504 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001505
1506 VkImageCreateInfo image_create_info = {};
1507 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1508 image_create_info.pNext = NULL;
1509 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1510 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1511 image_create_info.extent.width = 64;
1512 image_create_info.extent.height = 64;
1513 image_create_info.extent.depth = 1;
1514 image_create_info.mipLevels = 1;
1515 image_create_info.arrayLayers = 1;
1516 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001517 // Image tiling must be optimal to trigger error when aliasing linear buffer
1518 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001519 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1520 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1521 image_create_info.queueFamilyIndexCount = 0;
1522 image_create_info.pQueueFamilyIndices = NULL;
1523 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1524 image_create_info.flags = 0;
1525
Tobin Ehlisf11be982016-05-11 13:52:53 -06001526 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1527 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001528 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1529 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001530
Tobin Ehlis077ded32016-05-12 17:39:13 -06001531 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1532
1533 VkMemoryAllocateInfo alloc_info = {};
1534 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1535 alloc_info.pNext = NULL;
1536 alloc_info.memoryTypeIndex = 0;
1537 // Ensure memory is big enough for both bindings
1538 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001539 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1540 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001541 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001542 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001543 vkDestroyImage(m_device->device(), image, NULL);
1544 return;
1545 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001546 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1547 ASSERT_VK_SUCCESS(err);
1548 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1549 ASSERT_VK_SUCCESS(err);
1550
Rene Lindsayd14f5572016-12-16 14:57:18 -07001551 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1552
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001553 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001554 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001555 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1556 m_errorMonitor->VerifyFound();
1557
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001558 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001559 // aliasing buffer2
1560 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1561 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001562 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1563 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001564 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001565 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001567 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001568 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001569 m_errorMonitor->VerifyFound();
1570
1571 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001572 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001573 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001574 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001575 vkFreeMemory(m_device->device(), mem, NULL);
1576 vkFreeMemory(m_device->device(), mem_img, NULL);
1577}
1578
Tobin Ehlis35372522016-05-12 08:32:31 -06001579TEST_F(VkLayerTest, InvalidMemoryMapping) {
1580 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1581 VkResult err;
1582 bool pass;
1583 ASSERT_NO_FATAL_FAILURE(InitState());
1584
1585 VkBuffer buffer;
1586 VkDeviceMemory mem;
1587 VkMemoryRequirements mem_reqs;
1588
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001589 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1590
Tobin Ehlis35372522016-05-12 08:32:31 -06001591 VkBufferCreateInfo buf_info = {};
1592 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1593 buf_info.pNext = NULL;
1594 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1595 buf_info.size = 256;
1596 buf_info.queueFamilyIndexCount = 0;
1597 buf_info.pQueueFamilyIndices = NULL;
1598 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1599 buf_info.flags = 0;
1600 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1601 ASSERT_VK_SUCCESS(err);
1602
1603 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1604 VkMemoryAllocateInfo alloc_info = {};
1605 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1606 alloc_info.pNext = NULL;
1607 alloc_info.memoryTypeIndex = 0;
1608
1609 // Ensure memory is big enough for both bindings
1610 static const VkDeviceSize allocation_size = 0x10000;
1611 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001612 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 -06001613 if (!pass) {
1614 vkDestroyBuffer(m_device->device(), buffer, NULL);
1615 return;
1616 }
1617 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1618 ASSERT_VK_SUCCESS(err);
1619
1620 uint8_t *pData;
1621 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001622 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 -06001623 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1624 m_errorMonitor->VerifyFound();
1625 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001626 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001627 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1629 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1630 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001631 m_errorMonitor->VerifyFound();
1632
1633 // Unmap the memory to avoid re-map error
1634 vkUnmapMemory(m_device->device(), mem);
1635 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1637 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1638 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001639 m_errorMonitor->VerifyFound();
1640 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1642 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001643 m_errorMonitor->VerifyFound();
1644 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001646 vkUnmapMemory(m_device->device(), mem);
1647 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001648
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001650 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001651 ASSERT_VK_SUCCESS(err);
1652 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001653 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001654 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001655 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001657 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1658 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001659
Tobin Ehlis35372522016-05-12 08:32:31 -06001660 // Now flush range that oversteps mapped range
1661 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001662 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001663 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001664 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001665 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1667 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1668 m_errorMonitor->VerifyFound();
1669
1670 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1671 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001672 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001673 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001674 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001675 mmr.size = VK_WHOLE_SIZE;
1676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001677 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1678 m_errorMonitor->VerifyFound();
1679
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001680#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001681 // Some platforms have an atomsize of 1 which makes the test meaningless
1682 if (atom_size > 3) {
1683 // Now with an offset NOT a multiple of the device limit
1684 vkUnmapMemory(m_device->device(), mem);
1685 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1686 ASSERT_VK_SUCCESS(err);
1687 mmr.offset = 3; // Not a multiple of atom_size
1688 mmr.size = VK_WHOLE_SIZE;
1689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1690 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1691 m_errorMonitor->VerifyFound();
1692
1693 // Now with a size NOT a multiple of the device limit
1694 vkUnmapMemory(m_device->device(), mem);
1695 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1696 ASSERT_VK_SUCCESS(err);
1697 mmr.offset = atom_size;
1698 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1700 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1701 m_errorMonitor->VerifyFound();
1702 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001703#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001704 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1705 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001706 if (!pass) {
1707 vkFreeMemory(m_device->device(), mem, NULL);
1708 vkDestroyBuffer(m_device->device(), buffer, NULL);
1709 return;
1710 }
1711 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1712 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1713
1714 vkDestroyBuffer(m_device->device(), buffer, NULL);
1715 vkFreeMemory(m_device->device(), mem, NULL);
1716}
1717
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001718#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001719TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1720 VkResult err;
1721 bool pass;
1722
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001723 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1724 // following declaration (which is temporarily being moved below):
1725 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001726 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001727 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001728 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001729 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001730 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001731 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001732
1733 ASSERT_NO_FATAL_FAILURE(InitState());
1734
Ian Elliott3f06ce52016-04-29 14:46:21 -06001735#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1736#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1737 // Use the functions from the VK_KHR_android_surface extension without
1738 // enabling that extension:
1739
1740 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001741 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1743 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001744 pass = (err != VK_SUCCESS);
1745 ASSERT_TRUE(pass);
1746 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001747#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001748
Ian Elliott3f06ce52016-04-29 14:46:21 -06001749#if defined(VK_USE_PLATFORM_MIR_KHR)
1750 // Use the functions from the VK_KHR_mir_surface extension without enabling
1751 // that extension:
1752
1753 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001754 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001756 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1757 pass = (err != VK_SUCCESS);
1758 ASSERT_TRUE(pass);
1759 m_errorMonitor->VerifyFound();
1760
1761 // Tell whether an mir_connection supports presentation:
1762 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1764 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001765 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001766#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001767
Ian Elliott3f06ce52016-04-29 14:46:21 -06001768#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1769 // Use the functions from the VK_KHR_wayland_surface extension without
1770 // enabling that extension:
1771
1772 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001773 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1775 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001776 pass = (err != VK_SUCCESS);
1777 ASSERT_TRUE(pass);
1778 m_errorMonitor->VerifyFound();
1779
1780 // Tell whether an wayland_display supports presentation:
1781 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1783 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001784 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001785#endif // VK_USE_PLATFORM_WAYLAND_KHR
1786#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001787
Ian Elliott3f06ce52016-04-29 14:46:21 -06001788#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1790 // TO NON-LINUX PLATFORMS:
1791 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001792 // Use the functions from the VK_KHR_win32_surface extension without
1793 // enabling that extension:
1794
1795 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001796 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1798 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001799 pass = (err != VK_SUCCESS);
1800 ASSERT_TRUE(pass);
1801 m_errorMonitor->VerifyFound();
1802
1803 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001805 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001806 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001807// Set this (for now, until all platforms are supported and tested):
1808#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001809#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001810#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001811 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1812 // TO NON-LINUX PLATFORMS:
1813 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001814#endif
1815#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001816 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1817 // that extension:
1818
1819 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001820 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001822 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1823 pass = (err != VK_SUCCESS);
1824 ASSERT_TRUE(pass);
1825 m_errorMonitor->VerifyFound();
1826
1827 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001828 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001829 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1831 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001832 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001833// Set this (for now, until all platforms are supported and tested):
1834#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001835#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001836
Ian Elliott12630812016-04-29 14:35:43 -06001837#if defined(VK_USE_PLATFORM_XLIB_KHR)
1838 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1839 // that extension:
1840
1841 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001842 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001844 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1845 pass = (err != VK_SUCCESS);
1846 ASSERT_TRUE(pass);
1847 m_errorMonitor->VerifyFound();
1848
1849 // Tell whether an Xlib VisualID supports presentation:
1850 Display *dpy = NULL;
1851 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001853 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1854 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001855// Set this (for now, until all platforms are supported and tested):
1856#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001857#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001859// Use the functions from the VK_KHR_surface extension without enabling
1860// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001861
Ian Elliott489eec02016-05-05 14:12:44 -06001862#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001863 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001864 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001865 vkDestroySurfaceKHR(instance(), surface, NULL);
1866 m_errorMonitor->VerifyFound();
1867
1868 // Check if surface supports presentation:
1869 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001871 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1872 pass = (err != VK_SUCCESS);
1873 ASSERT_TRUE(pass);
1874 m_errorMonitor->VerifyFound();
1875
1876 // Check surface capabilities:
1877 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1879 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001880 pass = (err != VK_SUCCESS);
1881 ASSERT_TRUE(pass);
1882 m_errorMonitor->VerifyFound();
1883
1884 // Check surface formats:
1885 uint32_t format_count = 0;
1886 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1888 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001889 pass = (err != VK_SUCCESS);
1890 ASSERT_TRUE(pass);
1891 m_errorMonitor->VerifyFound();
1892
1893 // Check surface present modes:
1894 uint32_t present_mode_count = 0;
1895 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1897 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001898 pass = (err != VK_SUCCESS);
1899 ASSERT_TRUE(pass);
1900 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001901#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001902
Ian Elliott1c32c772016-04-28 14:47:13 -06001903 // Use the functions from the VK_KHR_swapchain extension without enabling
1904 // that extension:
1905
1906 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001908 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1909 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001910 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001911 pass = (err != VK_SUCCESS);
1912 ASSERT_TRUE(pass);
1913 m_errorMonitor->VerifyFound();
1914
1915 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1917 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001918 pass = (err != VK_SUCCESS);
1919 ASSERT_TRUE(pass);
1920 m_errorMonitor->VerifyFound();
1921
Chris Forbeseb7d5502016-09-13 18:19:21 +12001922 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1923 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1924 VkFence fence;
1925 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1926
Ian Elliott1c32c772016-04-28 14:47:13 -06001927 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001929 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001930 pass = (err != VK_SUCCESS);
1931 ASSERT_TRUE(pass);
1932 m_errorMonitor->VerifyFound();
1933
Chris Forbeseb7d5502016-09-13 18:19:21 +12001934 vkDestroyFence(m_device->device(), fence, nullptr);
1935
Ian Elliott1c32c772016-04-28 14:47:13 -06001936 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001937 //
1938 // NOTE: Currently can't test this because a real swapchain is needed (as
1939 // opposed to the fake one we created) in order for the layer to lookup the
1940 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001941
1942 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1945 m_errorMonitor->VerifyFound();
1946}
Chris Forbes09368e42016-10-13 11:59:22 +13001947#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001948
Karl Schultz6addd812016-02-02 17:17:23 -07001949TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1950 VkResult err;
1951 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001952
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1954 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001955
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001956 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001957
1958 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001959 VkImage image;
1960 VkDeviceMemory mem;
1961 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001962
Karl Schultz6addd812016-02-02 17:17:23 -07001963 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1964 const int32_t tex_width = 32;
1965 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001966
Tony Barboureb254902015-07-15 12:50:33 -06001967 VkImageCreateInfo image_create_info = {};
1968 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001969 image_create_info.pNext = NULL;
1970 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1971 image_create_info.format = tex_format;
1972 image_create_info.extent.width = tex_width;
1973 image_create_info.extent.height = tex_height;
1974 image_create_info.extent.depth = 1;
1975 image_create_info.mipLevels = 1;
1976 image_create_info.arrayLayers = 1;
1977 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1978 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1979 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1980 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001981 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001982
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001983 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001984 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001985 mem_alloc.pNext = NULL;
1986 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001987
Chia-I Wuf7458c52015-10-26 21:10:41 +08001988 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001989 ASSERT_VK_SUCCESS(err);
1990
Karl Schultz6addd812016-02-02 17:17:23 -07001991 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992
Mark Lobodzinski23065352015-05-29 09:32:35 -05001993 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001994
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001995 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 -07001996 if (!pass) { // If we can't find any unmappable memory this test doesn't
1997 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001998 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001999 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002000 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002001
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002002 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002003 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002004 ASSERT_VK_SUCCESS(err);
2005
2006 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002007 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002008 ASSERT_VK_SUCCESS(err);
2009
2010 // Map memory as if to initialize the image
2011 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002012 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002013
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002014 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002015
Chia-I Wuf7458c52015-10-26 21:10:41 +08002016 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002017 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002018}
2019
Karl Schultz6addd812016-02-02 17:17:23 -07002020TEST_F(VkLayerTest, RebindMemory) {
2021 VkResult err;
2022 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002023
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002025
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002026 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002027
2028 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002029 VkImage image;
2030 VkDeviceMemory mem1;
2031 VkDeviceMemory mem2;
2032 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002033
Karl Schultz6addd812016-02-02 17:17:23 -07002034 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2035 const int32_t tex_width = 32;
2036 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002037
Tony Barboureb254902015-07-15 12:50:33 -06002038 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002039 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2040 image_create_info.pNext = NULL;
2041 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2042 image_create_info.format = tex_format;
2043 image_create_info.extent.width = tex_width;
2044 image_create_info.extent.height = tex_height;
2045 image_create_info.extent.depth = 1;
2046 image_create_info.mipLevels = 1;
2047 image_create_info.arrayLayers = 1;
2048 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2049 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2050 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2051 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002052
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002053 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002054 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2055 mem_alloc.pNext = NULL;
2056 mem_alloc.allocationSize = 0;
2057 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002058
Karl Schultz6addd812016-02-02 17:17:23 -07002059 // Introduce failure, do NOT set memProps to
2060 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002061 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002062 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063 ASSERT_VK_SUCCESS(err);
2064
Karl Schultz6addd812016-02-02 17:17:23 -07002065 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002066
2067 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002068 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002069 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002070
2071 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002072 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002073 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002074 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002075 ASSERT_VK_SUCCESS(err);
2076
2077 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002078 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002079 ASSERT_VK_SUCCESS(err);
2080
Karl Schultz6addd812016-02-02 17:17:23 -07002081 // Introduce validation failure, try to bind a different memory object to
2082 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002083 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002084
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002085 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002086
Chia-I Wuf7458c52015-10-26 21:10:41 +08002087 vkDestroyImage(m_device->device(), image, NULL);
2088 vkFreeMemory(m_device->device(), mem1, NULL);
2089 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002090}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002091
Karl Schultz6addd812016-02-02 17:17:23 -07002092TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002093 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002094
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2096 "submitted in SIGNALED state. Fences "
2097 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002098
2099 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002100 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2101 fenceInfo.pNext = NULL;
2102 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002103
Tony Barbour300a6082015-04-07 13:44:53 -06002104 ASSERT_NO_FATAL_FAILURE(InitState());
2105 ASSERT_NO_FATAL_FAILURE(InitViewport());
2106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2107
Tony Barbour552f6c02016-12-21 14:34:07 -07002108 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002109 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002110 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002111
2112 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002113
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002114 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002115 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2116 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002117 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002118 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002119 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002120 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002121 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002122 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002123 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002124
2125 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002126 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002127
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002128 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002129}
Chris Forbes4e44c912016-06-16 10:20:00 +12002130
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002131TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002132 TEST_DESCRIPTION(
2133 "Specify wrong usage for image then create conflicting view of image "
2134 "Initialize buffer with wrong usage then perform copy expecting errors "
2135 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002137
2138 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002139
2140 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2141
Tony Barbourf92621a2016-05-02 14:28:12 -06002142 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002143 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002144 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002145 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002146
Tony Barbourf92621a2016-05-02 14:28:12 -06002147 VkImageView dsv;
2148 VkImageViewCreateInfo dsvci = {};
2149 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2150 dsvci.image = image.handle();
2151 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002152 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002153 dsvci.subresourceRange.layerCount = 1;
2154 dsvci.subresourceRange.baseMipLevel = 0;
2155 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002156 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002157
Tony Barbourf92621a2016-05-02 14:28:12 -06002158 // Create a view with depth / stencil aspect for image with different usage
2159 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002160
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002161 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002162
2163 // Initialize buffer with TRANSFER_DST usage
2164 vk_testing::Buffer buffer;
2165 VkMemoryPropertyFlags reqs = 0;
2166 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2167 VkBufferImageCopy region = {};
2168 region.bufferRowLength = 128;
2169 region.bufferImageHeight = 128;
2170 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2171 region.imageSubresource.layerCount = 1;
2172 region.imageExtent.height = 16;
2173 region.imageExtent.width = 16;
2174 region.imageExtent.depth = 1;
2175
Tony Barbourf92621a2016-05-02 14:28:12 -06002176 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2177 // TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002178 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002179
Chris Forbesda581202016-10-06 18:25:26 +13002180 // two separate errors from this call:
2181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2183
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002184 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2185 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002186 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002187}
Tony Barbour75d79f02016-08-30 09:39:07 -06002188
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002189#endif // MEM_TRACKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002190
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002191#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002192
2193TEST_F(VkLayerTest, LeakAnObject) {
2194 VkResult err;
2195
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002196 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002197
2198 // Note that we have to create a new device since destroying the
2199 // framework's device causes Teardown() to fail and just calling Teardown
2200 // will destroy the errorMonitor.
2201
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002203
2204 ASSERT_NO_FATAL_FAILURE(InitState());
2205
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002206 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002207 std::vector<VkDeviceQueueCreateInfo> queue_info;
2208 queue_info.reserve(queue_props.size());
2209 std::vector<std::vector<float>> queue_priorities;
2210 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2211 VkDeviceQueueCreateInfo qi = {};
2212 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2213 qi.pNext = NULL;
2214 qi.queueFamilyIndex = i;
2215 qi.queueCount = queue_props[i].queueCount;
2216 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2217 qi.pQueuePriorities = queue_priorities[i].data();
2218 queue_info.push_back(qi);
2219 }
2220
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002221 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002222
2223 // The sacrificial device object
2224 VkDevice testDevice;
2225 VkDeviceCreateInfo device_create_info = {};
2226 auto features = m_device->phy().features();
2227 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2228 device_create_info.pNext = NULL;
2229 device_create_info.queueCreateInfoCount = queue_info.size();
2230 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002231 device_create_info.enabledLayerCount = 0;
2232 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002233 device_create_info.pEnabledFeatures = &features;
2234 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2235 ASSERT_VK_SUCCESS(err);
2236
2237 VkFence fence;
2238 VkFenceCreateInfo fence_create_info = {};
2239 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2240 fence_create_info.pNext = NULL;
2241 fence_create_info.flags = 0;
2242 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2243 ASSERT_VK_SUCCESS(err);
2244
2245 // Induce failure by not calling vkDestroyFence
2246 vkDestroyDevice(testDevice, NULL);
2247 m_errorMonitor->VerifyFound();
2248}
2249
2250TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002251 TEST_DESCRIPTION(
2252 "Allocate command buffers from one command pool and "
2253 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002254
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002256
Cody Northropc31a84f2016-08-22 10:41:47 -06002257 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002258 VkCommandPool command_pool_one;
2259 VkCommandPool command_pool_two;
2260
2261 VkCommandPoolCreateInfo pool_create_info{};
2262 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2263 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2264 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2265
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002266 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002267
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002268 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002269
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002270 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002271 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002272 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002273 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002274 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002275 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002276 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002277
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002278 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279
2280 m_errorMonitor->VerifyFound();
2281
2282 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2283 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2284}
2285
2286TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2287 VkResult err;
2288
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002289 TEST_DESCRIPTION(
2290 "Allocate descriptor sets from one DS pool and "
2291 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002292
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294
2295 ASSERT_NO_FATAL_FAILURE(InitState());
2296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2297
2298 VkDescriptorPoolSize ds_type_count = {};
2299 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2300 ds_type_count.descriptorCount = 1;
2301
2302 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2303 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2304 ds_pool_ci.pNext = NULL;
2305 ds_pool_ci.flags = 0;
2306 ds_pool_ci.maxSets = 1;
2307 ds_pool_ci.poolSizeCount = 1;
2308 ds_pool_ci.pPoolSizes = &ds_type_count;
2309
2310 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002311 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002312 ASSERT_VK_SUCCESS(err);
2313
2314 // Create a second descriptor pool
2315 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002316 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002317 ASSERT_VK_SUCCESS(err);
2318
2319 VkDescriptorSetLayoutBinding dsl_binding = {};
2320 dsl_binding.binding = 0;
2321 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2322 dsl_binding.descriptorCount = 1;
2323 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2324 dsl_binding.pImmutableSamplers = NULL;
2325
2326 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2327 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2328 ds_layout_ci.pNext = NULL;
2329 ds_layout_ci.bindingCount = 1;
2330 ds_layout_ci.pBindings = &dsl_binding;
2331
2332 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002333 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002334 ASSERT_VK_SUCCESS(err);
2335
2336 VkDescriptorSet descriptorSet;
2337 VkDescriptorSetAllocateInfo alloc_info = {};
2338 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2339 alloc_info.descriptorSetCount = 1;
2340 alloc_info.descriptorPool = ds_pool_one;
2341 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002342 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002343 ASSERT_VK_SUCCESS(err);
2344
2345 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2346
2347 m_errorMonitor->VerifyFound();
2348
2349 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2350 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2351 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2352}
2353
2354TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002356
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002357 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002358
2359 ASSERT_NO_FATAL_FAILURE(InitState());
2360
2361 // Pass bogus handle into GetImageMemoryRequirements
2362 VkMemoryRequirements mem_reqs;
2363 uint64_t fakeImageHandle = 0xCADECADE;
2364 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2365
2366 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2367
2368 m_errorMonitor->VerifyFound();
2369}
2370
Karl Schultz6addd812016-02-02 17:17:23 -07002371TEST_F(VkLayerTest, PipelineNotBound) {
2372 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002373
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002374 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002375
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002377
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002378 ASSERT_NO_FATAL_FAILURE(InitState());
2379 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002380
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002381 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002382 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2383 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002384
2385 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002386 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2387 ds_pool_ci.pNext = NULL;
2388 ds_pool_ci.maxSets = 1;
2389 ds_pool_ci.poolSizeCount = 1;
2390 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002391
2392 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002393 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002394 ASSERT_VK_SUCCESS(err);
2395
2396 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002397 dsl_binding.binding = 0;
2398 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2399 dsl_binding.descriptorCount = 1;
2400 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2401 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002402
2403 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002404 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2405 ds_layout_ci.pNext = NULL;
2406 ds_layout_ci.bindingCount = 1;
2407 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002408
2409 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002410 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002411 ASSERT_VK_SUCCESS(err);
2412
2413 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002414 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002415 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002416 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002417 alloc_info.descriptorPool = ds_pool;
2418 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002419 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002420 ASSERT_VK_SUCCESS(err);
2421
2422 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002423 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2424 pipeline_layout_ci.pNext = NULL;
2425 pipeline_layout_ci.setLayoutCount = 1;
2426 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002427
2428 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002429 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002430 ASSERT_VK_SUCCESS(err);
2431
Mark Youngad779052016-01-06 14:26:04 -07002432 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002433
Tony Barbour552f6c02016-12-21 14:34:07 -07002434 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002435 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002436
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002437 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002438
Chia-I Wuf7458c52015-10-26 21:10:41 +08002439 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2440 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2441 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002442}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002443
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002444TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2445 VkResult err;
2446
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002447 TEST_DESCRIPTION(
2448 "Test validation check for an invalid memory type index "
2449 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002450
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002451 ASSERT_NO_FATAL_FAILURE(InitState());
2452
2453 // Create an image, allocate memory, set a bad typeIndex and then try to
2454 // bind it
2455 VkImage image;
2456 VkDeviceMemory mem;
2457 VkMemoryRequirements mem_reqs;
2458 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2459 const int32_t tex_width = 32;
2460 const int32_t tex_height = 32;
2461
2462 VkImageCreateInfo image_create_info = {};
2463 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2464 image_create_info.pNext = NULL;
2465 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2466 image_create_info.format = tex_format;
2467 image_create_info.extent.width = tex_width;
2468 image_create_info.extent.height = tex_height;
2469 image_create_info.extent.depth = 1;
2470 image_create_info.mipLevels = 1;
2471 image_create_info.arrayLayers = 1;
2472 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2473 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2474 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2475 image_create_info.flags = 0;
2476
2477 VkMemoryAllocateInfo mem_alloc = {};
2478 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2479 mem_alloc.pNext = NULL;
2480 mem_alloc.allocationSize = 0;
2481 mem_alloc.memoryTypeIndex = 0;
2482
2483 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2484 ASSERT_VK_SUCCESS(err);
2485
2486 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2487 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002488
2489 // Introduce Failure, select invalid TypeIndex
2490 VkPhysicalDeviceMemoryProperties memory_info;
2491
2492 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2493 unsigned int i;
2494 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2495 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2496 mem_alloc.memoryTypeIndex = i;
2497 break;
2498 }
2499 }
2500 if (i >= memory_info.memoryTypeCount) {
2501 printf("No invalid memory type index could be found; skipped.\n");
2502 vkDestroyImage(m_device->device(), image, NULL);
2503 return;
2504 }
2505
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002506 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 -06002507
2508 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2509 ASSERT_VK_SUCCESS(err);
2510
2511 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2512 (void)err;
2513
2514 m_errorMonitor->VerifyFound();
2515
2516 vkDestroyImage(m_device->device(), image, NULL);
2517 vkFreeMemory(m_device->device(), mem, NULL);
2518}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002519
Karl Schultz6addd812016-02-02 17:17:23 -07002520TEST_F(VkLayerTest, BindInvalidMemory) {
2521 VkResult err;
2522 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002523
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002525
Tobin Ehlisec598302015-09-15 15:02:17 -06002526 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002527
2528 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002529 VkImage image;
2530 VkDeviceMemory mem;
2531 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002532
Karl Schultz6addd812016-02-02 17:17:23 -07002533 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2534 const int32_t tex_width = 32;
2535 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002536
2537 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002538 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2539 image_create_info.pNext = NULL;
2540 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2541 image_create_info.format = tex_format;
2542 image_create_info.extent.width = tex_width;
2543 image_create_info.extent.height = tex_height;
2544 image_create_info.extent.depth = 1;
2545 image_create_info.mipLevels = 1;
2546 image_create_info.arrayLayers = 1;
2547 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2548 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2549 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2550 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002551
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002552 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002553 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2554 mem_alloc.pNext = NULL;
2555 mem_alloc.allocationSize = 0;
2556 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002557
Chia-I Wuf7458c52015-10-26 21:10:41 +08002558 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002559 ASSERT_VK_SUCCESS(err);
2560
Karl Schultz6addd812016-02-02 17:17:23 -07002561 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002562
2563 mem_alloc.allocationSize = mem_reqs.size;
2564
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002565 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002566 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002567
2568 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002569 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002570 ASSERT_VK_SUCCESS(err);
2571
2572 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002573 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002574
2575 // Try to bind free memory that has been freed
2576 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2577 // This may very well return an error.
2578 (void)err;
2579
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002580 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002581
Chia-I Wuf7458c52015-10-26 21:10:41 +08002582 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002583}
2584
Karl Schultz6addd812016-02-02 17:17:23 -07002585TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2586 VkResult err;
2587 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002588
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002590
Tobin Ehlisec598302015-09-15 15:02:17 -06002591 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002592
Karl Schultz6addd812016-02-02 17:17:23 -07002593 // Create an image object, allocate memory, destroy the object and then try
2594 // to bind it
2595 VkImage image;
2596 VkDeviceMemory mem;
2597 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002598
Karl Schultz6addd812016-02-02 17:17:23 -07002599 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2600 const int32_t tex_width = 32;
2601 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002602
2603 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002604 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2605 image_create_info.pNext = NULL;
2606 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2607 image_create_info.format = tex_format;
2608 image_create_info.extent.width = tex_width;
2609 image_create_info.extent.height = tex_height;
2610 image_create_info.extent.depth = 1;
2611 image_create_info.mipLevels = 1;
2612 image_create_info.arrayLayers = 1;
2613 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2614 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2615 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2616 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002617
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002618 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002619 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2620 mem_alloc.pNext = NULL;
2621 mem_alloc.allocationSize = 0;
2622 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002623
Chia-I Wuf7458c52015-10-26 21:10:41 +08002624 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002625 ASSERT_VK_SUCCESS(err);
2626
Karl Schultz6addd812016-02-02 17:17:23 -07002627 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002628
2629 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002630 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002631 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002632
2633 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002634 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002635 ASSERT_VK_SUCCESS(err);
2636
2637 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002638 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002639 ASSERT_VK_SUCCESS(err);
2640
2641 // Now Try to bind memory to this destroyed object
2642 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2643 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002644 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002645
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002646 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002647
Chia-I Wuf7458c52015-10-26 21:10:41 +08002648 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002649}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002650
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002651#endif // OBJ_TRACKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002652
Tobin Ehlis0788f522015-05-26 16:11:58 -06002653#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002654
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002655TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2656 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2657
2658 ASSERT_NO_FATAL_FAILURE(InitState());
2659 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2660
2661 VkVertexInputBindingDescription input_binding;
2662 memset(&input_binding, 0, sizeof(input_binding));
2663
2664 VkVertexInputAttributeDescription input_attribs;
2665 memset(&input_attribs, 0, sizeof(input_attribs));
2666
2667 // Pick a really bad format for this purpose and make sure it should fail
2668 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2669 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2670 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2671 printf("Format unsuitable for test; skipped.\n");
2672 return;
2673 }
2674
2675 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002676 char const *vsSource =
2677 "#version 450\n"
2678 "\n"
2679 "out gl_PerVertex {\n"
2680 " vec4 gl_Position;\n"
2681 "};\n"
2682 "void main(){\n"
2683 " gl_Position = vec4(1);\n"
2684 "}\n";
2685 char const *fsSource =
2686 "#version 450\n"
2687 "\n"
2688 "layout(location=0) out vec4 color;\n"
2689 "void main(){\n"
2690 " color = vec4(1);\n"
2691 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002692
2693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2694 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2695 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2696
2697 VkPipelineObj pipe(m_device);
2698 pipe.AddColorAttachment();
2699 pipe.AddShader(&vs);
2700 pipe.AddShader(&fs);
2701
2702 pipe.AddVertexInputBindings(&input_binding, 1);
2703 pipe.AddVertexInputAttribs(&input_attribs, 1);
2704
2705 VkDescriptorSetObj descriptorSet(m_device);
2706 descriptorSet.AppendDummy();
2707 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2708
2709 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2710
2711 m_errorMonitor->VerifyFound();
2712}
2713
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002714TEST_F(VkLayerTest, ImageSampleCounts) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002715 TEST_DESCRIPTION(
2716 "Use bad sample counts in image transfer calls to trigger "
2717 "validation errors.");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002718 ASSERT_NO_FATAL_FAILURE(InitState());
2719
2720 VkMemoryPropertyFlags reqs = 0;
2721 VkImageCreateInfo image_create_info = {};
2722 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2723 image_create_info.pNext = NULL;
2724 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2725 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2726 image_create_info.extent.width = 256;
2727 image_create_info.extent.height = 256;
2728 image_create_info.extent.depth = 1;
2729 image_create_info.mipLevels = 1;
2730 image_create_info.arrayLayers = 1;
2731 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2732 image_create_info.flags = 0;
2733
2734 VkImageBlit blit_region = {};
2735 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2736 blit_region.srcSubresource.baseArrayLayer = 0;
2737 blit_region.srcSubresource.layerCount = 1;
2738 blit_region.srcSubresource.mipLevel = 0;
2739 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2740 blit_region.dstSubresource.baseArrayLayer = 0;
2741 blit_region.dstSubresource.layerCount = 1;
2742 blit_region.dstSubresource.mipLevel = 0;
2743
2744 // Create two images, the source with sampleCount = 2, and attempt to blit
2745 // between them
2746 {
2747 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002748 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002749 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002750 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002751 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002752 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002753 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002754 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002755 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2757 "was created with a sample count "
2758 "of VK_SAMPLE_COUNT_2_BIT but "
2759 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002760 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2761 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002762 m_errorMonitor->VerifyFound();
2763 m_commandBuffer->EndCommandBuffer();
2764 }
2765
2766 // Create two images, the dest with sampleCount = 4, and attempt to blit
2767 // between them
2768 {
2769 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002770 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002771 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002772 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002773 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002774 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002775 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002776 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002777 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2779 "was created with a sample count "
2780 "of VK_SAMPLE_COUNT_4_BIT but "
2781 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002782 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2783 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002784 m_errorMonitor->VerifyFound();
2785 m_commandBuffer->EndCommandBuffer();
2786 }
2787
2788 VkBufferImageCopy copy_region = {};
2789 copy_region.bufferRowLength = 128;
2790 copy_region.bufferImageHeight = 128;
2791 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2792 copy_region.imageSubresource.layerCount = 1;
2793 copy_region.imageExtent.height = 64;
2794 copy_region.imageExtent.width = 64;
2795 copy_region.imageExtent.depth = 1;
2796
2797 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2798 // buffer to image
2799 {
2800 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002801 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2802 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002803 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002804 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002805 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002806 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2808 "was created with a sample count "
2809 "of VK_SAMPLE_COUNT_8_BIT but "
2810 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002811 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2812 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002813 m_errorMonitor->VerifyFound();
2814 m_commandBuffer->EndCommandBuffer();
2815 }
2816
2817 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2818 // image to buffer
2819 {
2820 vk_testing::Buffer dst_buffer;
2821 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2822 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002823 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002824 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002825 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002826 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2828 "was created with a sample count "
2829 "of VK_SAMPLE_COUNT_2_BIT but "
2830 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002831 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002832 dst_buffer.handle(), 1, &copy_region);
2833 m_errorMonitor->VerifyFound();
2834 m_commandBuffer->EndCommandBuffer();
2835 }
2836}
2837
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002838TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002839 ASSERT_NO_FATAL_FAILURE(InitState());
2840
2841 VkImageObj src_image(m_device);
2842 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2843 VkImageObj dst_image(m_device);
2844 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2845 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002846 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 -06002847
2848 VkImageBlit blitRegion = {};
2849 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2850 blitRegion.srcSubresource.baseArrayLayer = 0;
2851 blitRegion.srcSubresource.layerCount = 1;
2852 blitRegion.srcSubresource.mipLevel = 0;
2853 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2854 blitRegion.dstSubresource.baseArrayLayer = 0;
2855 blitRegion.dstSubresource.layerCount = 1;
2856 blitRegion.dstSubresource.mipLevel = 0;
2857
Dave Houlton34df4cb2016-12-01 16:43:06 -07002858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
2859
2860 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
2861 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002862
2863 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07002864 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002865 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
2866 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002867
2868 m_errorMonitor->VerifyFound();
2869
Dave Houlton34df4cb2016-12-01 16:43:06 -07002870 // Test should generate 2 VU failures
2871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
2872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002873
2874 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002875 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
2876 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002877
Dave Houlton34df4cb2016-12-01 16:43:06 -07002878 // TODO: Note that this only verifies that at least one of the VU enums was found
2879 // 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 -06002880 m_errorMonitor->VerifyFound();
2881
Tony Barbour552f6c02016-12-21 14:34:07 -07002882 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002883}
2884
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002885TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2886 VkResult err;
2887 bool pass;
2888
2889 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2890 ASSERT_NO_FATAL_FAILURE(InitState());
2891
2892 // If w/d/h granularity is 1, test is not meaningful
2893 // TODO: When virtual device limits are available, create a set of limits for this test that
2894 // will always have a granularity of > 1 for w, h, and d
2895 auto index = m_device->graphics_queue_node_index_;
2896 auto queue_family_properties = m_device->phy().queue_properties();
2897
2898 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2899 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2900 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2901 return;
2902 }
2903
2904 // Create two images of different types and try to copy between them
2905 VkImage srcImage;
2906 VkImage dstImage;
2907 VkDeviceMemory srcMem;
2908 VkDeviceMemory destMem;
2909 VkMemoryRequirements memReqs;
2910
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002911 VkImageCreateInfo image_create_info = {};
2912 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2913 image_create_info.pNext = NULL;
2914 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2915 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2916 image_create_info.extent.width = 32;
2917 image_create_info.extent.height = 32;
2918 image_create_info.extent.depth = 1;
2919 image_create_info.mipLevels = 1;
2920 image_create_info.arrayLayers = 4;
2921 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2922 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2923 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2924 image_create_info.flags = 0;
2925
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002926 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002927 ASSERT_VK_SUCCESS(err);
2928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002929 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002930 ASSERT_VK_SUCCESS(err);
2931
2932 // Allocate memory
2933 VkMemoryAllocateInfo memAlloc = {};
2934 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2935 memAlloc.pNext = NULL;
2936 memAlloc.allocationSize = 0;
2937 memAlloc.memoryTypeIndex = 0;
2938
2939 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2940 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002941 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002942 ASSERT_TRUE(pass);
2943 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2944 ASSERT_VK_SUCCESS(err);
2945
2946 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2947 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002948 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002949 ASSERT_VK_SUCCESS(err);
2950 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2951 ASSERT_VK_SUCCESS(err);
2952
2953 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2954 ASSERT_VK_SUCCESS(err);
2955 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2956 ASSERT_VK_SUCCESS(err);
2957
Tony Barbour552f6c02016-12-21 14:34:07 -07002958 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002959 VkImageCopy copyRegion;
2960 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2961 copyRegion.srcSubresource.mipLevel = 0;
2962 copyRegion.srcSubresource.baseArrayLayer = 0;
2963 copyRegion.srcSubresource.layerCount = 1;
2964 copyRegion.srcOffset.x = 0;
2965 copyRegion.srcOffset.y = 0;
2966 copyRegion.srcOffset.z = 0;
2967 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2968 copyRegion.dstSubresource.mipLevel = 0;
2969 copyRegion.dstSubresource.baseArrayLayer = 0;
2970 copyRegion.dstSubresource.layerCount = 1;
2971 copyRegion.dstOffset.x = 0;
2972 copyRegion.dstOffset.y = 0;
2973 copyRegion.dstOffset.z = 0;
2974 copyRegion.extent.width = 1;
2975 copyRegion.extent.height = 1;
2976 copyRegion.extent.depth = 1;
2977
2978 // Introduce failure by setting srcOffset to a bad granularity value
2979 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2981 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002982 m_errorMonitor->VerifyFound();
2983
2984 // Introduce failure by setting extent to a bad granularity value
2985 copyRegion.srcOffset.y = 0;
2986 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2988 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002989 m_errorMonitor->VerifyFound();
2990
2991 // Now do some buffer/image copies
2992 vk_testing::Buffer buffer;
2993 VkMemoryPropertyFlags reqs = 0;
2994 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2995 VkBufferImageCopy region = {};
2996 region.bufferOffset = 0;
2997 region.bufferRowLength = 3;
2998 region.bufferImageHeight = 128;
2999 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3000 region.imageSubresource.layerCount = 1;
3001 region.imageExtent.height = 16;
3002 region.imageExtent.width = 16;
3003 region.imageExtent.depth = 1;
3004 region.imageOffset.x = 0;
3005 region.imageOffset.y = 0;
3006 region.imageOffset.z = 0;
3007
3008 // Introduce failure by setting bufferRowLength to a bad granularity value
3009 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003010 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3011 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3012 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003013 m_errorMonitor->VerifyFound();
3014 region.bufferRowLength = 128;
3015
3016 // Introduce failure by setting bufferOffset to a bad granularity value
3017 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3019 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3020 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003021 m_errorMonitor->VerifyFound();
3022 region.bufferOffset = 0;
3023
3024 // Introduce failure by setting bufferImageHeight to a bad granularity value
3025 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3027 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3028 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003029 m_errorMonitor->VerifyFound();
3030 region.bufferImageHeight = 128;
3031
3032 // Introduce failure by setting imageExtent to a bad granularity value
3033 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3035 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3036 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003037 m_errorMonitor->VerifyFound();
3038 region.imageExtent.width = 16;
3039
3040 // Introduce failure by setting imageOffset to a bad granularity value
3041 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3043 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3044 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003045 m_errorMonitor->VerifyFound();
3046
Tony Barbour552f6c02016-12-21 14:34:07 -07003047 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003048
3049 vkDestroyImage(m_device->device(), srcImage, NULL);
3050 vkDestroyImage(m_device->device(), dstImage, NULL);
3051 vkFreeMemory(m_device->device(), srcMem, NULL);
3052 vkFreeMemory(m_device->device(), destMem, NULL);
3053}
3054
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003055TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003056 TEST_DESCRIPTION(
3057 "Submit command buffer created using one queue family and "
3058 "attempt to submit them on a queue created in a different "
3059 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003060
Cody Northropc31a84f2016-08-22 10:41:47 -06003061 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003062 // This test is meaningless unless we have multiple queue families
3063 auto queue_family_properties = m_device->phy().queue_properties();
3064 if (queue_family_properties.size() < 2) {
3065 return;
3066 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003068 // Get safe index of another queue family
3069 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3070 ASSERT_NO_FATAL_FAILURE(InitState());
3071 // Create a second queue using a different queue family
3072 VkQueue other_queue;
3073 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3074
3075 // Record an empty cmd buffer
3076 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3077 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3078 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3079 vkEndCommandBuffer(m_commandBuffer->handle());
3080
3081 // And submit on the wrong queue
3082 VkSubmitInfo submit_info = {};
3083 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3084 submit_info.commandBufferCount = 1;
3085 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003086 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003087
3088 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003089}
3090
Chris Forbes4c24a922016-11-16 08:59:10 +13003091TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3092 ASSERT_NO_FATAL_FAILURE(InitState());
3093
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003094 // There are no attachments, but refer to attachment 0.
3095 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003096 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003097 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003098 };
3099
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003100 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003101 VkRenderPass rp;
3102
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003103 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003105 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3106 m_errorMonitor->VerifyFound();
3107}
3108
Chris Forbesa58c4522016-09-28 15:19:39 +13003109TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3110 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3111 ASSERT_NO_FATAL_FAILURE(InitState());
3112
3113 // A renderpass with two subpasses, both writing the same attachment.
3114 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003115 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3116 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3117 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003118 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003119 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003120 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003121 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3122 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003123 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003124 VkSubpassDependency dep = {0,
3125 1,
3126 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3127 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3128 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3129 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3130 VK_DEPENDENCY_BY_REGION_BIT};
3131 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003132 VkRenderPass rp;
3133 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3134 ASSERT_VK_SUCCESS(err);
3135
3136 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003137 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 +13003138 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3139
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003140 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003141 VkFramebuffer fb;
3142 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3143 ASSERT_VK_SUCCESS(err);
3144
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003145 char const *vsSource =
3146 "#version 450\n"
3147 "void main() { gl_Position = vec4(1); }\n";
3148 char const *fsSource =
3149 "#version 450\n"
3150 "layout(location=0) out vec4 color;\n"
3151 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003152
3153 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3154 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3155 VkPipelineObj pipe(m_device);
3156 pipe.AddColorAttachment();
3157 pipe.AddShader(&vs);
3158 pipe.AddShader(&fs);
3159 VkViewport view_port = {};
3160 m_viewports.push_back(view_port);
3161 pipe.SetViewport(m_viewports);
3162 VkRect2D rect = {};
3163 m_scissors.push_back(rect);
3164 pipe.SetScissor(m_scissors);
3165
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003166 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003167 VkPipelineLayout pl;
3168 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3169 ASSERT_VK_SUCCESS(err);
3170 pipe.CreateVKPipeline(pl, rp);
3171
Tony Barbour552f6c02016-12-21 14:34:07 -07003172 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003173
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003174 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3175 nullptr,
3176 rp,
3177 fb,
3178 {{
3179 0, 0,
3180 },
3181 {32, 32}},
3182 0,
3183 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003184
3185 // subtest 1: bind in the wrong subpass
3186 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3187 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003188 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 +13003189 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3190 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3191 m_errorMonitor->VerifyFound();
3192
3193 vkCmdEndRenderPass(m_commandBuffer->handle());
3194
3195 // subtest 2: bind in correct subpass, then transition to next subpass
3196 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3197 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3198 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003199 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 +13003200 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3201 m_errorMonitor->VerifyFound();
3202
3203 vkCmdEndRenderPass(m_commandBuffer->handle());
3204
Tony Barbour552f6c02016-12-21 14:34:07 -07003205 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003206
3207 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3208 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3209 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3210}
3211
Tony Barbour4e919972016-08-09 13:27:40 -06003212TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003213 TEST_DESCRIPTION(
3214 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3215 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003216 ASSERT_NO_FATAL_FAILURE(InitState());
3217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3218
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3220 "Cannot execute a render pass with renderArea "
3221 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003222
3223 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3224 m_renderPassBeginInfo.renderArea.extent.width = 257;
3225 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003226 m_commandBuffer->BeginCommandBuffer();
3227 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003228 m_errorMonitor->VerifyFound();
3229}
3230
3231TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003232 TEST_DESCRIPTION(
3233 "Generate INDEPENDENT_BLEND by disabling independent "
3234 "blend and then specifying different blend states for two "
3235 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003236 VkPhysicalDeviceFeatures features = {};
3237 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003238 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003239
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3241 "Invalid Pipeline CreateInfo: If independent blend feature not "
3242 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003243
Cody Northropc31a84f2016-08-22 10:41:47 -06003244 VkDescriptorSetObj descriptorSet(m_device);
3245 descriptorSet.AppendDummy();
3246 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003247
Cody Northropc31a84f2016-08-22 10:41:47 -06003248 VkPipelineObj pipeline(m_device);
3249 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003250 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003251 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003252
Cody Northropc31a84f2016-08-22 10:41:47 -06003253 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3254 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3255 att_state1.blendEnable = VK_TRUE;
3256 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3257 att_state2.blendEnable = VK_FALSE;
3258 pipeline.AddColorAttachment(0, &att_state1);
3259 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003260 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003261 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003262}
3263
Chris Forbes26ec2122016-11-29 08:58:33 +13003264#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003265TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3266 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3267 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003268 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003269
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3271 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003272
3273 // Create a renderPass with a single color attachment
3274 VkAttachmentReference attach = {};
3275 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3276 VkSubpassDescription subpass = {};
3277 VkRenderPassCreateInfo rpci = {};
3278 rpci.subpassCount = 1;
3279 rpci.pSubpasses = &subpass;
3280 rpci.attachmentCount = 1;
3281 VkAttachmentDescription attach_desc = {};
3282 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3283 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3284 rpci.pAttachments = &attach_desc;
3285 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3286 VkRenderPass rp;
3287 subpass.pDepthStencilAttachment = &attach;
3288 subpass.pColorAttachments = NULL;
3289 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3290 m_errorMonitor->VerifyFound();
3291}
Chris Forbes26ec2122016-11-29 08:58:33 +13003292#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003293
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003294TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003295 TEST_DESCRIPTION(
3296 "Create a framebuffer where a subpass has a preserve "
3297 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003298
3299 ASSERT_NO_FATAL_FAILURE(InitState());
3300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3301
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003303
3304 VkAttachmentReference color_attach = {};
3305 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3306 color_attach.attachment = 0;
3307 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3308 VkSubpassDescription subpass = {};
3309 subpass.colorAttachmentCount = 1;
3310 subpass.pColorAttachments = &color_attach;
3311 subpass.preserveAttachmentCount = 1;
3312 subpass.pPreserveAttachments = &preserve_attachment;
3313
3314 VkRenderPassCreateInfo rpci = {};
3315 rpci.subpassCount = 1;
3316 rpci.pSubpasses = &subpass;
3317 rpci.attachmentCount = 1;
3318 VkAttachmentDescription attach_desc = {};
3319 attach_desc.format = VK_FORMAT_UNDEFINED;
3320 rpci.pAttachments = &attach_desc;
3321 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3322 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003323 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003324
3325 m_errorMonitor->VerifyFound();
3326
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003327 if (result == VK_SUCCESS) {
3328 vkDestroyRenderPass(m_device->device(), rp, NULL);
3329 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003330}
3331
Chris Forbesc5389742016-06-29 11:49:23 +12003332TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003333 TEST_DESCRIPTION(
3334 "Ensure that CreateRenderPass produces a validation error "
3335 "when the source of a subpass multisample resolve "
3336 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003337
Chris Forbesc5389742016-06-29 11:49:23 +12003338 ASSERT_NO_FATAL_FAILURE(InitState());
3339
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3341 "Subpass 0 requests multisample resolve from attachment 0 which has "
3342 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003343
3344 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003345 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3346 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3347 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3348 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3349 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3350 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003351 };
3352
3353 VkAttachmentReference color = {
3354 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3355 };
3356
3357 VkAttachmentReference resolve = {
3358 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3359 };
3360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003361 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003362
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003363 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003364
3365 VkRenderPass rp;
3366 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3367
3368 m_errorMonitor->VerifyFound();
3369
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003370 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003371}
3372
3373TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003374 TEST_DESCRIPTION(
3375 "Ensure CreateRenderPass produces a validation error "
3376 "when a subpass multisample resolve operation is "
3377 "requested, and the destination of that resolve has "
3378 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003379
Chris Forbesc5389742016-06-29 11:49:23 +12003380 ASSERT_NO_FATAL_FAILURE(InitState());
3381
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3383 "Subpass 0 requests multisample resolve into attachment 1, which "
3384 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003385
3386 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3388 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3389 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3390 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3391 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3392 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003393 };
3394
3395 VkAttachmentReference color = {
3396 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3397 };
3398
3399 VkAttachmentReference resolve = {
3400 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3401 };
3402
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003403 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003405 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003406
3407 VkRenderPass rp;
3408 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3409
3410 m_errorMonitor->VerifyFound();
3411
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003412 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003413}
3414
Chris Forbes3f128ef2016-06-29 14:58:53 +12003415TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003416 TEST_DESCRIPTION(
3417 "Ensure CreateRenderPass produces a validation error "
3418 "when the color and depth attachments used by a subpass "
3419 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003420
Chris Forbes3f128ef2016-06-29 14:58:53 +12003421 ASSERT_NO_FATAL_FAILURE(InitState());
3422
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3424 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003425
3426 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003427 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3428 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3429 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3430 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3431 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3432 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003433 };
3434
3435 VkAttachmentReference color[] = {
3436 {
3437 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3438 },
3439 {
3440 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3441 },
3442 };
3443
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003444 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003445
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003446 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003447
3448 VkRenderPass rp;
3449 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3450
3451 m_errorMonitor->VerifyFound();
3452
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003453 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003454}
3455
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003456TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003457 TEST_DESCRIPTION(
3458 "Hit errors when attempting to create a framebuffer :\n"
3459 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3460 " 2. Use a color image as depthStencil attachment\n"
3461 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3462 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3463 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3464 " 6. Framebuffer attachment where dimensions don't match\n"
3465 " 7. Framebuffer attachment w/o identity swizzle\n"
3466 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003467
3468 ASSERT_NO_FATAL_FAILURE(InitState());
3469 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3470
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3472 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3473 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003474
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003475 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003476 VkAttachmentReference attach = {};
3477 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3478 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003479 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003480 VkRenderPassCreateInfo rpci = {};
3481 rpci.subpassCount = 1;
3482 rpci.pSubpasses = &subpass;
3483 rpci.attachmentCount = 1;
3484 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003485 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003486 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003487 rpci.pAttachments = &attach_desc;
3488 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3489 VkRenderPass rp;
3490 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3491 ASSERT_VK_SUCCESS(err);
3492
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003493 VkImageView ivs[2];
3494 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3495 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003496 VkFramebufferCreateInfo fb_info = {};
3497 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3498 fb_info.pNext = NULL;
3499 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003500 // Set mis-matching attachmentCount
3501 fb_info.attachmentCount = 2;
3502 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003503 fb_info.width = 100;
3504 fb_info.height = 100;
3505 fb_info.layers = 1;
3506
3507 VkFramebuffer fb;
3508 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3509
3510 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003511 if (err == VK_SUCCESS) {
3512 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3513 }
3514 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003515
3516 // Create a renderPass with a depth-stencil attachment created with
3517 // IMAGE_USAGE_COLOR_ATTACHMENT
3518 // Add our color attachment to pDepthStencilAttachment
3519 subpass.pDepthStencilAttachment = &attach;
3520 subpass.pColorAttachments = NULL;
3521 VkRenderPass rp_ds;
3522 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3523 ASSERT_VK_SUCCESS(err);
3524 // Set correct attachment count, but attachment has COLOR usage bit set
3525 fb_info.attachmentCount = 1;
3526 fb_info.renderPass = rp_ds;
3527
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003529 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3530
3531 m_errorMonitor->VerifyFound();
3532 if (err == VK_SUCCESS) {
3533 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3534 }
3535 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003536
3537 // Create new renderpass with alternate attachment format from fb
3538 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3539 subpass.pDepthStencilAttachment = NULL;
3540 subpass.pColorAttachments = &attach;
3541 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3542 ASSERT_VK_SUCCESS(err);
3543
3544 // Cause error due to mis-matched formats between rp & fb
3545 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3546 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3548 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003549 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3550
3551 m_errorMonitor->VerifyFound();
3552 if (err == VK_SUCCESS) {
3553 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3554 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003555 vkDestroyRenderPass(m_device->device(), rp, NULL);
3556
3557 // Create new renderpass with alternate sample count from fb
3558 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3559 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3560 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3561 ASSERT_VK_SUCCESS(err);
3562
3563 // Cause error due to mis-matched sample count between rp & fb
3564 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3566 " has VK_SAMPLE_COUNT_1_BIT samples "
3567 "that do not match the "
3568 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003569 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3570
3571 m_errorMonitor->VerifyFound();
3572 if (err == VK_SUCCESS) {
3573 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3574 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003575
3576 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003577
3578 // Create a custom imageView with non-1 mip levels
3579 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003580 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 -06003581 ASSERT_TRUE(image.initialized());
3582
3583 VkImageView view;
3584 VkImageViewCreateInfo ivci = {};
3585 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3586 ivci.image = image.handle();
3587 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3588 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3589 ivci.subresourceRange.layerCount = 1;
3590 ivci.subresourceRange.baseMipLevel = 0;
3591 // Set level count 2 (only 1 is allowed for FB attachment)
3592 ivci.subresourceRange.levelCount = 2;
3593 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3594 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3595 ASSERT_VK_SUCCESS(err);
3596 // Re-create renderpass to have matching sample count
3597 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3598 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3599 ASSERT_VK_SUCCESS(err);
3600
3601 fb_info.renderPass = rp;
3602 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003604 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3605
3606 m_errorMonitor->VerifyFound();
3607 if (err == VK_SUCCESS) {
3608 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3609 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003610 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003611 // Update view to original color buffer and grow FB dimensions too big
3612 fb_info.pAttachments = ivs;
3613 fb_info.height = 1024;
3614 fb_info.width = 1024;
3615 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3617 " Attachment dimensions must be at "
3618 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003619 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3620
3621 m_errorMonitor->VerifyFound();
3622 if (err == VK_SUCCESS) {
3623 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3624 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003625 // Create view attachment with non-identity swizzle
3626 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3627 ivci.image = image.handle();
3628 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3629 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3630 ivci.subresourceRange.layerCount = 1;
3631 ivci.subresourceRange.baseMipLevel = 0;
3632 ivci.subresourceRange.levelCount = 1;
3633 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3634 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3635 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3636 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3637 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3638 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3639 ASSERT_VK_SUCCESS(err);
3640
3641 fb_info.pAttachments = &view;
3642 fb_info.height = 100;
3643 fb_info.width = 100;
3644 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3646 " has non-identy swizzle. All "
3647 "framebuffer attachments must have "
3648 "been created with the identity "
3649 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003650 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3651
3652 m_errorMonitor->VerifyFound();
3653 if (err == VK_SUCCESS) {
3654 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3655 }
3656 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003657 // reset attachment to color attachment
3658 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003659
3660 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003661 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003662 fb_info.height = 100;
3663 fb_info.layers = 1;
3664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
3665 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3666
3667 m_errorMonitor->VerifyFound();
3668 if (err == VK_SUCCESS) {
3669 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3670 }
3671
3672 // Request fb that exceeds max height
3673 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003674 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003675 fb_info.layers = 1;
3676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
3677 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3678
3679 m_errorMonitor->VerifyFound();
3680 if (err == VK_SUCCESS) {
3681 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3682 }
3683
3684 // Request fb that exceeds max layers
3685 fb_info.width = 100;
3686 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003687 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003689 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3690
3691 m_errorMonitor->VerifyFound();
3692 if (err == VK_SUCCESS) {
3693 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3694 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003695
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003696 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003697}
3698
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003699TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003700 TEST_DESCRIPTION(
3701 "Run a simple draw calls to validate failure when Depth Bias dynamic "
3702 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003703
Cody Northropc31a84f2016-08-22 10:41:47 -06003704 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003705 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3707 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003708 m_errorMonitor->VerifyFound();
3709}
3710
3711TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003712 TEST_DESCRIPTION(
3713 "Run a simple draw calls to validate failure when Line Width dynamic "
3714 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003715
Cody Northropc31a84f2016-08-22 10:41:47 -06003716 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003717 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3719 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003720 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003721}
3722
3723TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003724 TEST_DESCRIPTION(
3725 "Run a simple draw calls to validate failure when Viewport dynamic "
3726 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003727
Cody Northropc31a84f2016-08-22 10:41:47 -06003728 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003729 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3731 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003732 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003733 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003734}
3735
3736TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003737 TEST_DESCRIPTION(
3738 "Run a simple draw calls to validate failure when Scissor dynamic "
3739 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003740
Cody Northropc31a84f2016-08-22 10:41:47 -06003741 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003742 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3744 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003745 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003746 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003747}
3748
Cortd713fe82016-07-27 09:51:27 -07003749TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003750 TEST_DESCRIPTION(
3751 "Run a simple draw calls to validate failure when Blend Constants "
3752 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003753
3754 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003755 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3757 "Dynamic blend constants state not set for this command buffer");
3758 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003759 m_errorMonitor->VerifyFound();
3760}
3761
3762TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003763 TEST_DESCRIPTION(
3764 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
3765 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003766
3767 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003768 if (!m_device->phy().features().depthBounds) {
3769 printf("Device does not support depthBounds test; skipped.\n");
3770 return;
3771 }
3772 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3774 "Dynamic depth bounds state not set for this command buffer");
3775 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003776 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003777}
3778
3779TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003780 TEST_DESCRIPTION(
3781 "Run a simple draw calls to validate failure when Stencil Read dynamic "
3782 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003783
3784 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003785 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3787 "Dynamic stencil read mask state not set for this command buffer");
3788 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003789 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003790}
3791
3792TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003793 TEST_DESCRIPTION(
3794 "Run a simple draw calls to validate failure when Stencil Write dynamic"
3795 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003796
3797 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003798 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3800 "Dynamic stencil write mask state not set for this command buffer");
3801 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003802 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003803}
3804
3805TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003806 TEST_DESCRIPTION(
3807 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
3808 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003809
3810 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003811 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3813 "Dynamic stencil reference state not set for this command buffer");
3814 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003815 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003816}
3817
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003818TEST_F(VkLayerTest, IndexBufferNotBound) {
3819 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003820
3821 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3823 "Index buffer object not bound to this command buffer when Indexed ");
3824 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003825 m_errorMonitor->VerifyFound();
3826}
3827
Karl Schultz6addd812016-02-02 17:17:23 -07003828TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3830 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3831 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003832
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003833 ASSERT_NO_FATAL_FAILURE(InitState());
3834 ASSERT_NO_FATAL_FAILURE(InitViewport());
3835 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3836
Karl Schultz6addd812016-02-02 17:17:23 -07003837 // We luck out b/c by default the framework creates CB w/ the
3838 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07003839 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003840 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07003841 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003842
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003843 // Bypass framework since it does the waits automatically
3844 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003845 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003846 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3847 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003848 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003849 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003850 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003851 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003852 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003853 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003854 submit_info.pSignalSemaphores = NULL;
3855
Chris Forbes40028e22016-06-13 09:59:34 +12003856 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003857 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003858 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003859
Karl Schultz6addd812016-02-02 17:17:23 -07003860 // Cause validation error by re-submitting cmd buffer that should only be
3861 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003862 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003863 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003864
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003865 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003866}
3867
Karl Schultz6addd812016-02-02 17:17:23 -07003868TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003869 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003870 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003871
3872 ASSERT_NO_FATAL_FAILURE(InitState());
3873 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003874
Karl Schultz6addd812016-02-02 17:17:23 -07003875 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3876 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003877 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003878 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003879 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003880
3881 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003882 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3883 ds_pool_ci.pNext = NULL;
3884 ds_pool_ci.flags = 0;
3885 ds_pool_ci.maxSets = 1;
3886 ds_pool_ci.poolSizeCount = 1;
3887 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003888
3889 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003890 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003891 ASSERT_VK_SUCCESS(err);
3892
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003893 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3894 dsl_binding_samp.binding = 0;
3895 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3896 dsl_binding_samp.descriptorCount = 1;
3897 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3898 dsl_binding_samp.pImmutableSamplers = NULL;
3899
3900 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3901 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3902 ds_layout_ci.pNext = NULL;
3903 ds_layout_ci.bindingCount = 1;
3904 ds_layout_ci.pBindings = &dsl_binding_samp;
3905
3906 VkDescriptorSetLayout ds_layout_samp;
3907 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3908 ASSERT_VK_SUCCESS(err);
3909
3910 // Try to allocate 2 sets when pool only has 1 set
3911 VkDescriptorSet descriptor_sets[2];
3912 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3913 VkDescriptorSetAllocateInfo alloc_info = {};
3914 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3915 alloc_info.descriptorSetCount = 2;
3916 alloc_info.descriptorPool = ds_pool;
3917 alloc_info.pSetLayouts = set_layouts;
3918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3919 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3920 m_errorMonitor->VerifyFound();
3921
3922 alloc_info.descriptorSetCount = 1;
3923 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003924 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003925 dsl_binding.binding = 0;
3926 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3927 dsl_binding.descriptorCount = 1;
3928 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3929 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003930
Karl Schultz6addd812016-02-02 17:17:23 -07003931 ds_layout_ci.bindingCount = 1;
3932 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003933
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003934 VkDescriptorSetLayout ds_layout_ub;
3935 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003936 ASSERT_VK_SUCCESS(err);
3937
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003938 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003939 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003940 alloc_info.pSetLayouts = &ds_layout_ub;
3941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3942 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003943
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003944 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003945
Karl Schultz2825ab92016-12-02 08:23:14 -07003946 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003949}
3950
Karl Schultz6addd812016-02-02 17:17:23 -07003951TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3952 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003953
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07003954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003955
Tobin Ehlise735c692015-10-08 13:13:50 -06003956 ASSERT_NO_FATAL_FAILURE(InitState());
3957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003958
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003959 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003960 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3961 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003962
3963 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003964 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3965 ds_pool_ci.pNext = NULL;
3966 ds_pool_ci.maxSets = 1;
3967 ds_pool_ci.poolSizeCount = 1;
3968 ds_pool_ci.flags = 0;
3969 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3970 // app can only call vkResetDescriptorPool on this pool.;
3971 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003972
3973 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003974 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003975 ASSERT_VK_SUCCESS(err);
3976
3977 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003978 dsl_binding.binding = 0;
3979 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3980 dsl_binding.descriptorCount = 1;
3981 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3982 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003983
3984 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003985 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3986 ds_layout_ci.pNext = NULL;
3987 ds_layout_ci.bindingCount = 1;
3988 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003989
3990 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003991 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003992 ASSERT_VK_SUCCESS(err);
3993
3994 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003995 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003996 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003997 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003998 alloc_info.descriptorPool = ds_pool;
3999 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004000 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004001 ASSERT_VK_SUCCESS(err);
4002
4003 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004004 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004005
Chia-I Wuf7458c52015-10-26 21:10:41 +08004006 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4007 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004008}
4009
Karl Schultz6addd812016-02-02 17:17:23 -07004010TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004011 // Attempt to clear Descriptor Pool with bad object.
4012 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004013
4014 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004016 uint64_t fake_pool_handle = 0xbaad6001;
4017 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4018 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004019 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004020}
4021
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004022TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004023 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4024 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004025 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004026 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004027
4028 uint64_t fake_set_handle = 0xbaad6001;
4029 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004030 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004032
4033 ASSERT_NO_FATAL_FAILURE(InitState());
4034
4035 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4036 layout_bindings[0].binding = 0;
4037 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4038 layout_bindings[0].descriptorCount = 1;
4039 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4040 layout_bindings[0].pImmutableSamplers = NULL;
4041
4042 VkDescriptorSetLayout descriptor_set_layout;
4043 VkDescriptorSetLayoutCreateInfo dslci = {};
4044 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4045 dslci.pNext = NULL;
4046 dslci.bindingCount = 1;
4047 dslci.pBindings = layout_bindings;
4048 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004049 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004050
4051 VkPipelineLayout pipeline_layout;
4052 VkPipelineLayoutCreateInfo plci = {};
4053 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4054 plci.pNext = NULL;
4055 plci.setLayoutCount = 1;
4056 plci.pSetLayouts = &descriptor_set_layout;
4057 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004058 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004059
Tony Barbour552f6c02016-12-21 14:34:07 -07004060 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004061 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4062 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004063 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004064 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004065 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4066 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004067}
4068
Karl Schultz6addd812016-02-02 17:17:23 -07004069TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004070 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4071 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004072 uint64_t fake_layout_handle = 0xbaad6001;
4073 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004075 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004076 VkPipelineLayout pipeline_layout;
4077 VkPipelineLayoutCreateInfo plci = {};
4078 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4079 plci.pNext = NULL;
4080 plci.setLayoutCount = 1;
4081 plci.pSetLayouts = &bad_layout;
4082 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4083
4084 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004085}
4086
Mark Muellerd4914412016-06-13 17:52:06 -06004087TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004088 TEST_DESCRIPTION(
4089 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4090 "1) A uniform buffer update must have a valid buffer index."
4091 "2) When using an array of descriptors in a single WriteDescriptor,"
4092 " the descriptor types and stageflags must all be the same."
4093 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004094
Mike Weiblena6666382017-01-05 15:16:11 -07004095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004096
4097 ASSERT_NO_FATAL_FAILURE(InitState());
4098 VkDescriptorPoolSize ds_type_count[4] = {};
4099 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4100 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004101 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004102 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004103 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004104 ds_type_count[2].descriptorCount = 1;
4105 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4106 ds_type_count[3].descriptorCount = 1;
4107
4108 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4109 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4110 ds_pool_ci.maxSets = 1;
4111 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4112 ds_pool_ci.pPoolSizes = ds_type_count;
4113
4114 VkDescriptorPool ds_pool;
4115 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4116 ASSERT_VK_SUCCESS(err);
4117
Mark Muellerb9896722016-06-16 09:54:29 -06004118 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004119 layout_binding[0].binding = 0;
4120 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4121 layout_binding[0].descriptorCount = 1;
4122 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4123 layout_binding[0].pImmutableSamplers = NULL;
4124
4125 layout_binding[1].binding = 1;
4126 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4127 layout_binding[1].descriptorCount = 1;
4128 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4129 layout_binding[1].pImmutableSamplers = NULL;
4130
4131 VkSamplerCreateInfo sampler_ci = {};
4132 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4133 sampler_ci.pNext = NULL;
4134 sampler_ci.magFilter = VK_FILTER_NEAREST;
4135 sampler_ci.minFilter = VK_FILTER_NEAREST;
4136 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4137 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4138 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4139 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4140 sampler_ci.mipLodBias = 1.0;
4141 sampler_ci.anisotropyEnable = VK_FALSE;
4142 sampler_ci.maxAnisotropy = 1;
4143 sampler_ci.compareEnable = VK_FALSE;
4144 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4145 sampler_ci.minLod = 1.0;
4146 sampler_ci.maxLod = 1.0;
4147 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4148 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4149 VkSampler sampler;
4150
4151 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4152 ASSERT_VK_SUCCESS(err);
4153
4154 layout_binding[2].binding = 2;
4155 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4156 layout_binding[2].descriptorCount = 1;
4157 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4158 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4159
Mark Muellerd4914412016-06-13 17:52:06 -06004160 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4161 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4162 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4163 ds_layout_ci.pBindings = layout_binding;
4164 VkDescriptorSetLayout ds_layout;
4165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4166 ASSERT_VK_SUCCESS(err);
4167
4168 VkDescriptorSetAllocateInfo alloc_info = {};
4169 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4170 alloc_info.descriptorSetCount = 1;
4171 alloc_info.descriptorPool = ds_pool;
4172 alloc_info.pSetLayouts = &ds_layout;
4173 VkDescriptorSet descriptorSet;
4174 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4175 ASSERT_VK_SUCCESS(err);
4176
4177 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4178 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4179 pipeline_layout_ci.pNext = NULL;
4180 pipeline_layout_ci.setLayoutCount = 1;
4181 pipeline_layout_ci.pSetLayouts = &ds_layout;
4182
4183 VkPipelineLayout pipeline_layout;
4184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4185 ASSERT_VK_SUCCESS(err);
4186
Mark Mueller5c838ce2016-06-16 09:54:29 -06004187 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004188 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4189 descriptor_write.dstSet = descriptorSet;
4190 descriptor_write.dstBinding = 0;
4191 descriptor_write.descriptorCount = 1;
4192 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4193
Mark Mueller5c838ce2016-06-16 09:54:29 -06004194 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004195 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4196 m_errorMonitor->VerifyFound();
4197
4198 // Create a buffer to update the descriptor with
4199 uint32_t qfi = 0;
4200 VkBufferCreateInfo buffCI = {};
4201 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4202 buffCI.size = 1024;
4203 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4204 buffCI.queueFamilyIndexCount = 1;
4205 buffCI.pQueueFamilyIndices = &qfi;
4206
4207 VkBuffer dyub;
4208 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4209 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004210
Tony Barboure132c5f2016-12-12 11:50:20 -07004211 VkDeviceMemory mem;
4212 VkMemoryRequirements mem_reqs;
4213 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4214
4215 VkMemoryAllocateInfo mem_alloc_info = {};
4216 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4217 mem_alloc_info.allocationSize = mem_reqs.size;
4218 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4219 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4220 ASSERT_VK_SUCCESS(err);
4221
4222 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4223 ASSERT_VK_SUCCESS(err);
4224
4225 VkDescriptorBufferInfo buffInfo[2] = {};
4226 buffInfo[0].buffer = dyub;
4227 buffInfo[0].offset = 0;
4228 buffInfo[0].range = 1024;
4229 buffInfo[1].buffer = dyub;
4230 buffInfo[1].offset = 0;
4231 buffInfo[1].range = 1024;
4232 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004233 descriptor_write.descriptorCount = 2;
4234
Mark Mueller5c838ce2016-06-16 09:54:29 -06004235 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004237 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4238 m_errorMonitor->VerifyFound();
4239
Mark Mueller5c838ce2016-06-16 09:54:29 -06004240 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4241 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004242 descriptor_write.dstBinding = 1;
4243 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004244
Mark Mueller5c838ce2016-06-16 09:54:29 -06004245 // Make pImageInfo index non-null to avoid complaints of it missing
4246 VkDescriptorImageInfo imageInfo = {};
4247 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4248 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004250 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4251 m_errorMonitor->VerifyFound();
4252
Mark Muellerd4914412016-06-13 17:52:06 -06004253 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004254 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004255 vkDestroySampler(m_device->device(), sampler, NULL);
4256 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4257 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4258 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4259}
4260
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004261TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004262 TEST_DESCRIPTION(
4263 "Attempt to draw with a command buffer that is invalid "
4264 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004265 ASSERT_NO_FATAL_FAILURE(InitState());
4266
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004267 VkBuffer buffer;
4268 VkDeviceMemory mem;
4269 VkMemoryRequirements mem_reqs;
4270
4271 VkBufferCreateInfo buf_info = {};
4272 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004273 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004274 buf_info.size = 256;
4275 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4276 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4277 ASSERT_VK_SUCCESS(err);
4278
4279 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4280
4281 VkMemoryAllocateInfo alloc_info = {};
4282 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4283 alloc_info.allocationSize = 256;
4284 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004285 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 -06004286 if (!pass) {
4287 vkDestroyBuffer(m_device->device(), buffer, NULL);
4288 return;
4289 }
4290 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4291 ASSERT_VK_SUCCESS(err);
4292
4293 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4294 ASSERT_VK_SUCCESS(err);
4295
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004296 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004297 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004298 m_commandBuffer->EndCommandBuffer();
4299
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004301 // Destroy buffer dependency prior to submit to cause ERROR
4302 vkDestroyBuffer(m_device->device(), buffer, NULL);
4303
4304 VkSubmitInfo submit_info = {};
4305 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4306 submit_info.commandBufferCount = 1;
4307 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4308 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4309
4310 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004311 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004312 vkFreeMemory(m_device->handle(), mem, NULL);
4313}
4314
Tobin Ehlisea413442016-09-28 10:23:59 -06004315TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4316 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4317
4318 ASSERT_NO_FATAL_FAILURE(InitState());
4319 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4320
4321 VkDescriptorPoolSize ds_type_count;
4322 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4323 ds_type_count.descriptorCount = 1;
4324
4325 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4326 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4327 ds_pool_ci.maxSets = 1;
4328 ds_pool_ci.poolSizeCount = 1;
4329 ds_pool_ci.pPoolSizes = &ds_type_count;
4330
4331 VkDescriptorPool ds_pool;
4332 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4333 ASSERT_VK_SUCCESS(err);
4334
4335 VkDescriptorSetLayoutBinding layout_binding;
4336 layout_binding.binding = 0;
4337 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4338 layout_binding.descriptorCount = 1;
4339 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4340 layout_binding.pImmutableSamplers = NULL;
4341
4342 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4343 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4344 ds_layout_ci.bindingCount = 1;
4345 ds_layout_ci.pBindings = &layout_binding;
4346 VkDescriptorSetLayout ds_layout;
4347 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4348 ASSERT_VK_SUCCESS(err);
4349
4350 VkDescriptorSetAllocateInfo alloc_info = {};
4351 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4352 alloc_info.descriptorSetCount = 1;
4353 alloc_info.descriptorPool = ds_pool;
4354 alloc_info.pSetLayouts = &ds_layout;
4355 VkDescriptorSet descriptor_set;
4356 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4357 ASSERT_VK_SUCCESS(err);
4358
4359 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4360 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4361 pipeline_layout_ci.pNext = NULL;
4362 pipeline_layout_ci.setLayoutCount = 1;
4363 pipeline_layout_ci.pSetLayouts = &ds_layout;
4364
4365 VkPipelineLayout pipeline_layout;
4366 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4367 ASSERT_VK_SUCCESS(err);
4368
4369 VkBuffer buffer;
4370 uint32_t queue_family_index = 0;
4371 VkBufferCreateInfo buffer_create_info = {};
4372 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4373 buffer_create_info.size = 1024;
4374 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4375 buffer_create_info.queueFamilyIndexCount = 1;
4376 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4377
4378 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4379 ASSERT_VK_SUCCESS(err);
4380
4381 VkMemoryRequirements memory_reqs;
4382 VkDeviceMemory buffer_memory;
4383
4384 VkMemoryAllocateInfo memory_info = {};
4385 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4386 memory_info.allocationSize = 0;
4387 memory_info.memoryTypeIndex = 0;
4388
4389 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4390 memory_info.allocationSize = memory_reqs.size;
4391 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4392 ASSERT_TRUE(pass);
4393
4394 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4395 ASSERT_VK_SUCCESS(err);
4396 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4397 ASSERT_VK_SUCCESS(err);
4398
4399 VkBufferView view;
4400 VkBufferViewCreateInfo bvci = {};
4401 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4402 bvci.buffer = buffer;
4403 bvci.format = VK_FORMAT_R8_UNORM;
4404 bvci.range = VK_WHOLE_SIZE;
4405
4406 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4407 ASSERT_VK_SUCCESS(err);
4408
4409 VkWriteDescriptorSet descriptor_write = {};
4410 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4411 descriptor_write.dstSet = descriptor_set;
4412 descriptor_write.dstBinding = 0;
4413 descriptor_write.descriptorCount = 1;
4414 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4415 descriptor_write.pTexelBufferView = &view;
4416
4417 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4418
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004419 char const *vsSource =
4420 "#version 450\n"
4421 "\n"
4422 "out gl_PerVertex { \n"
4423 " vec4 gl_Position;\n"
4424 "};\n"
4425 "void main(){\n"
4426 " gl_Position = vec4(1);\n"
4427 "}\n";
4428 char const *fsSource =
4429 "#version 450\n"
4430 "\n"
4431 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4432 "layout(location=0) out vec4 x;\n"
4433 "void main(){\n"
4434 " x = imageLoad(s, 0);\n"
4435 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004436 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4437 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4438 VkPipelineObj pipe(m_device);
4439 pipe.AddShader(&vs);
4440 pipe.AddShader(&fs);
4441 pipe.AddColorAttachment();
4442 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4443
4444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4446
Tony Barbour552f6c02016-12-21 14:34:07 -07004447 m_commandBuffer->BeginCommandBuffer();
4448 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4449
Tobin Ehlisea413442016-09-28 10:23:59 -06004450 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4451 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4452 VkRect2D scissor = {{0, 0}, {16, 16}};
4453 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4454 // Bind pipeline to cmd buffer
4455 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4456 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4457 &descriptor_set, 0, nullptr);
4458 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004459 m_commandBuffer->EndRenderPass();
4460 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004461
4462 // Delete BufferView in order to invalidate cmd buffer
4463 vkDestroyBufferView(m_device->device(), view, NULL);
4464 // Now attempt submit of cmd buffer
4465 VkSubmitInfo submit_info = {};
4466 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4467 submit_info.commandBufferCount = 1;
4468 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4469 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4470 m_errorMonitor->VerifyFound();
4471
4472 // Clean-up
4473 vkDestroyBuffer(m_device->device(), buffer, NULL);
4474 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4475 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4476 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4477 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4478}
4479
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004480TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004481 TEST_DESCRIPTION(
4482 "Attempt to draw with a command buffer that is invalid "
4483 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004484 ASSERT_NO_FATAL_FAILURE(InitState());
4485
4486 VkImage image;
4487 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4488 VkImageCreateInfo image_create_info = {};
4489 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4490 image_create_info.pNext = NULL;
4491 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4492 image_create_info.format = tex_format;
4493 image_create_info.extent.width = 32;
4494 image_create_info.extent.height = 32;
4495 image_create_info.extent.depth = 1;
4496 image_create_info.mipLevels = 1;
4497 image_create_info.arrayLayers = 1;
4498 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4499 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004500 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004501 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004502 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004503 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004504 // Have to bind memory to image before recording cmd in cmd buffer using it
4505 VkMemoryRequirements mem_reqs;
4506 VkDeviceMemory image_mem;
4507 bool pass;
4508 VkMemoryAllocateInfo mem_alloc = {};
4509 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4510 mem_alloc.pNext = NULL;
4511 mem_alloc.memoryTypeIndex = 0;
4512 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4513 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004514 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004515 ASSERT_TRUE(pass);
4516 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4517 ASSERT_VK_SUCCESS(err);
4518 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4519 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004520
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004521 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004522 VkClearColorValue ccv;
4523 ccv.float32[0] = 1.0f;
4524 ccv.float32[1] = 1.0f;
4525 ccv.float32[2] = 1.0f;
4526 ccv.float32[3] = 1.0f;
4527 VkImageSubresourceRange isr = {};
4528 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004529 isr.baseArrayLayer = 0;
4530 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004531 isr.layerCount = 1;
4532 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004533 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004534 m_commandBuffer->EndCommandBuffer();
4535
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004537 // Destroy image dependency prior to submit to cause ERROR
4538 vkDestroyImage(m_device->device(), image, NULL);
4539
4540 VkSubmitInfo submit_info = {};
4541 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4542 submit_info.commandBufferCount = 1;
4543 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4544 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4545
4546 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004547 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004548}
4549
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004550TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004551 TEST_DESCRIPTION(
4552 "Attempt to draw with a command buffer that is invalid "
4553 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004554 VkFormatProperties format_properties;
4555 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004556 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4557 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004558 return;
4559 }
4560
4561 ASSERT_NO_FATAL_FAILURE(InitState());
4562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4563
4564 VkImageCreateInfo image_ci = {};
4565 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4566 image_ci.pNext = NULL;
4567 image_ci.imageType = VK_IMAGE_TYPE_2D;
4568 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4569 image_ci.extent.width = 32;
4570 image_ci.extent.height = 32;
4571 image_ci.extent.depth = 1;
4572 image_ci.mipLevels = 1;
4573 image_ci.arrayLayers = 1;
4574 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4575 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004576 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004577 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4578 image_ci.flags = 0;
4579 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004580 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004581
4582 VkMemoryRequirements memory_reqs;
4583 VkDeviceMemory image_memory;
4584 bool pass;
4585 VkMemoryAllocateInfo memory_info = {};
4586 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4587 memory_info.pNext = NULL;
4588 memory_info.allocationSize = 0;
4589 memory_info.memoryTypeIndex = 0;
4590 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4591 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004592 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004593 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004594 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004595 ASSERT_VK_SUCCESS(err);
4596 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4597 ASSERT_VK_SUCCESS(err);
4598
4599 VkImageViewCreateInfo ivci = {
4600 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4601 nullptr,
4602 0,
4603 image,
4604 VK_IMAGE_VIEW_TYPE_2D,
4605 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004606 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004607 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4608 };
4609 VkImageView view;
4610 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4611 ASSERT_VK_SUCCESS(err);
4612
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004613 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004614 VkFramebuffer fb;
4615 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4616 ASSERT_VK_SUCCESS(err);
4617
4618 // Just use default renderpass with our framebuffer
4619 m_renderPassBeginInfo.framebuffer = fb;
4620 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004621 m_commandBuffer->BeginCommandBuffer();
4622 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4623 m_commandBuffer->EndRenderPass();
4624 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004625 // Destroy image attached to framebuffer to invalidate cmd buffer
4626 vkDestroyImage(m_device->device(), image, NULL);
4627 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004629 QueueCommandBuffer(false);
4630 m_errorMonitor->VerifyFound();
4631
4632 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4633 vkDestroyImageView(m_device->device(), view, nullptr);
4634 vkFreeMemory(m_device->device(), image_memory, nullptr);
4635}
4636
Tobin Ehlisb329f992016-10-12 13:20:29 -06004637TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4638 TEST_DESCRIPTION("Delete in-use framebuffer.");
4639 VkFormatProperties format_properties;
4640 VkResult err = VK_SUCCESS;
4641 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4642
4643 ASSERT_NO_FATAL_FAILURE(InitState());
4644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4645
4646 VkImageObj image(m_device);
4647 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4648 ASSERT_TRUE(image.initialized());
4649 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4650
4651 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4652 VkFramebuffer fb;
4653 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4654 ASSERT_VK_SUCCESS(err);
4655
4656 // Just use default renderpass with our framebuffer
4657 m_renderPassBeginInfo.framebuffer = fb;
4658 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004659 m_commandBuffer->BeginCommandBuffer();
4660 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4661 m_commandBuffer->EndRenderPass();
4662 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004663 // Submit cmd buffer to put it in-flight
4664 VkSubmitInfo submit_info = {};
4665 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4666 submit_info.commandBufferCount = 1;
4667 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4668 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4669 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06004671 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4672 m_errorMonitor->VerifyFound();
4673 // Wait for queue to complete so we can safely destroy everything
4674 vkQueueWaitIdle(m_device->m_queue);
4675 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4676}
4677
Tobin Ehlis88becd72016-09-21 14:33:41 -06004678TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4679 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4680 VkFormatProperties format_properties;
4681 VkResult err = VK_SUCCESS;
4682 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004683
4684 ASSERT_NO_FATAL_FAILURE(InitState());
4685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4686
4687 VkImageCreateInfo image_ci = {};
4688 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4689 image_ci.pNext = NULL;
4690 image_ci.imageType = VK_IMAGE_TYPE_2D;
4691 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4692 image_ci.extent.width = 256;
4693 image_ci.extent.height = 256;
4694 image_ci.extent.depth = 1;
4695 image_ci.mipLevels = 1;
4696 image_ci.arrayLayers = 1;
4697 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4698 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004699 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004700 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4701 image_ci.flags = 0;
4702 VkImage image;
4703 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4704
4705 VkMemoryRequirements memory_reqs;
4706 VkDeviceMemory image_memory;
4707 bool pass;
4708 VkMemoryAllocateInfo memory_info = {};
4709 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4710 memory_info.pNext = NULL;
4711 memory_info.allocationSize = 0;
4712 memory_info.memoryTypeIndex = 0;
4713 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4714 memory_info.allocationSize = memory_reqs.size;
4715 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4716 ASSERT_TRUE(pass);
4717 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4718 ASSERT_VK_SUCCESS(err);
4719 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4720 ASSERT_VK_SUCCESS(err);
4721
4722 VkImageViewCreateInfo ivci = {
4723 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4724 nullptr,
4725 0,
4726 image,
4727 VK_IMAGE_VIEW_TYPE_2D,
4728 VK_FORMAT_B8G8R8A8_UNORM,
4729 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4730 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4731 };
4732 VkImageView view;
4733 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4734 ASSERT_VK_SUCCESS(err);
4735
4736 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4737 VkFramebuffer fb;
4738 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4739 ASSERT_VK_SUCCESS(err);
4740
4741 // Just use default renderpass with our framebuffer
4742 m_renderPassBeginInfo.framebuffer = fb;
4743 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004744 m_commandBuffer->BeginCommandBuffer();
4745 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4746 m_commandBuffer->EndRenderPass();
4747 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06004748 // Submit cmd buffer to put it (and attached imageView) in-flight
4749 VkSubmitInfo submit_info = {};
4750 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4751 submit_info.commandBufferCount = 1;
4752 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4753 // Submit cmd buffer to put framebuffer and children in-flight
4754 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4755 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004757 vkDestroyImage(m_device->device(), image, NULL);
4758 m_errorMonitor->VerifyFound();
4759 // Wait for queue to complete so we can safely destroy image and other objects
4760 vkQueueWaitIdle(m_device->m_queue);
4761 vkDestroyImage(m_device->device(), image, NULL);
4762 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4763 vkDestroyImageView(m_device->device(), view, nullptr);
4764 vkFreeMemory(m_device->device(), image_memory, nullptr);
4765}
4766
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004767TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4768 TEST_DESCRIPTION("Delete in-use renderPass.");
4769
4770 ASSERT_NO_FATAL_FAILURE(InitState());
4771 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4772
4773 // Create simple renderpass
4774 VkAttachmentReference attach = {};
4775 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4776 VkSubpassDescription subpass = {};
4777 subpass.pColorAttachments = &attach;
4778 VkRenderPassCreateInfo rpci = {};
4779 rpci.subpassCount = 1;
4780 rpci.pSubpasses = &subpass;
4781 rpci.attachmentCount = 1;
4782 VkAttachmentDescription attach_desc = {};
4783 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4784 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4785 rpci.pAttachments = &attach_desc;
4786 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4787 VkRenderPass rp;
4788 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4789 ASSERT_VK_SUCCESS(err);
4790
4791 // Create a pipeline that uses the given renderpass
4792 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4793 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4794
4795 VkPipelineLayout pipeline_layout;
4796 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4797 ASSERT_VK_SUCCESS(err);
4798
4799 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4800 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4801 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004802 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004803 vp_state_ci.pViewports = &vp;
4804 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004805 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004806 vp_state_ci.pScissors = &scissors;
4807
4808 VkPipelineShaderStageCreateInfo shaderStages[2];
4809 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4810
4811 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004812 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 -06004813 // but add it to be able to run on more devices
4814 shaderStages[0] = vs.GetStageCreateInfo();
4815 shaderStages[1] = fs.GetStageCreateInfo();
4816
4817 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4818 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4819
4820 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4821 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4822 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4823
4824 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4825 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4826 rs_ci.rasterizerDiscardEnable = true;
4827 rs_ci.lineWidth = 1.0f;
4828
4829 VkPipelineColorBlendAttachmentState att = {};
4830 att.blendEnable = VK_FALSE;
4831 att.colorWriteMask = 0xf;
4832
4833 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4834 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4835 cb_ci.attachmentCount = 1;
4836 cb_ci.pAttachments = &att;
4837
4838 VkGraphicsPipelineCreateInfo gp_ci = {};
4839 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4840 gp_ci.stageCount = 2;
4841 gp_ci.pStages = shaderStages;
4842 gp_ci.pVertexInputState = &vi_ci;
4843 gp_ci.pInputAssemblyState = &ia_ci;
4844 gp_ci.pViewportState = &vp_state_ci;
4845 gp_ci.pRasterizationState = &rs_ci;
4846 gp_ci.pColorBlendState = &cb_ci;
4847 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4848 gp_ci.layout = pipeline_layout;
4849 gp_ci.renderPass = rp;
4850
4851 VkPipelineCacheCreateInfo pc_ci = {};
4852 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4853
4854 VkPipeline pipeline;
4855 VkPipelineCache pipe_cache;
4856 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4857 ASSERT_VK_SUCCESS(err);
4858
4859 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4860 ASSERT_VK_SUCCESS(err);
4861 // Bind pipeline to cmd buffer, will also bind renderpass
4862 m_commandBuffer->BeginCommandBuffer();
4863 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4864 m_commandBuffer->EndCommandBuffer();
4865
4866 VkSubmitInfo submit_info = {};
4867 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4868 submit_info.commandBufferCount = 1;
4869 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4870 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4871
4872 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4873 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4874 m_errorMonitor->VerifyFound();
4875
4876 // Wait for queue to complete so we can safely destroy everything
4877 vkQueueWaitIdle(m_device->m_queue);
4878 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4879 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4880 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4881 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4882}
4883
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004884TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004886 ASSERT_NO_FATAL_FAILURE(InitState());
4887
4888 VkImage image;
4889 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4890 VkImageCreateInfo image_create_info = {};
4891 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4892 image_create_info.pNext = NULL;
4893 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4894 image_create_info.format = tex_format;
4895 image_create_info.extent.width = 32;
4896 image_create_info.extent.height = 32;
4897 image_create_info.extent.depth = 1;
4898 image_create_info.mipLevels = 1;
4899 image_create_info.arrayLayers = 1;
4900 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4901 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004902 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004903 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004904 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004905 ASSERT_VK_SUCCESS(err);
4906 // Have to bind memory to image before recording cmd in cmd buffer using it
4907 VkMemoryRequirements mem_reqs;
4908 VkDeviceMemory image_mem;
4909 bool pass;
4910 VkMemoryAllocateInfo mem_alloc = {};
4911 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4912 mem_alloc.pNext = NULL;
4913 mem_alloc.memoryTypeIndex = 0;
4914 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4915 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004916 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004917 ASSERT_TRUE(pass);
4918 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4919 ASSERT_VK_SUCCESS(err);
4920
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004921 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004923 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004924
4925 m_commandBuffer->BeginCommandBuffer();
4926 VkClearColorValue ccv;
4927 ccv.float32[0] = 1.0f;
4928 ccv.float32[1] = 1.0f;
4929 ccv.float32[2] = 1.0f;
4930 ccv.float32[3] = 1.0f;
4931 VkImageSubresourceRange isr = {};
4932 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4933 isr.baseArrayLayer = 0;
4934 isr.baseMipLevel = 0;
4935 isr.layerCount = 1;
4936 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004937 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004938 m_commandBuffer->EndCommandBuffer();
4939
4940 m_errorMonitor->VerifyFound();
4941 vkDestroyImage(m_device->device(), image, NULL);
4942 vkFreeMemory(m_device->device(), image_mem, nullptr);
4943}
4944
4945TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004946 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004947 ASSERT_NO_FATAL_FAILURE(InitState());
4948
4949 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004950 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 -06004951 VK_IMAGE_TILING_OPTIMAL, 0);
4952 ASSERT_TRUE(image.initialized());
4953
4954 VkBuffer buffer;
4955 VkDeviceMemory mem;
4956 VkMemoryRequirements mem_reqs;
4957
4958 VkBufferCreateInfo buf_info = {};
4959 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004960 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004961 buf_info.size = 256;
4962 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4963 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4964 ASSERT_VK_SUCCESS(err);
4965
4966 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4967
4968 VkMemoryAllocateInfo alloc_info = {};
4969 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4970 alloc_info.allocationSize = 256;
4971 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004972 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 -06004973 if (!pass) {
4974 vkDestroyBuffer(m_device->device(), buffer, NULL);
4975 return;
4976 }
4977 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4978 ASSERT_VK_SUCCESS(err);
4979
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004980 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004982 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004983 VkBufferImageCopy region = {};
4984 region.bufferRowLength = 128;
4985 region.bufferImageHeight = 128;
4986 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4987
4988 region.imageSubresource.layerCount = 1;
4989 region.imageExtent.height = 4;
4990 region.imageExtent.width = 4;
4991 region.imageExtent.depth = 1;
4992 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004993 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4994 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004995 m_commandBuffer->EndCommandBuffer();
4996
4997 m_errorMonitor->VerifyFound();
4998
4999 vkDestroyBuffer(m_device->device(), buffer, NULL);
5000 vkFreeMemory(m_device->handle(), mem, NULL);
5001}
5002
Tobin Ehlis85940f52016-07-07 16:57:21 -06005003TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005004 TEST_DESCRIPTION(
5005 "Attempt to draw with a command buffer that is invalid "
5006 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005007 ASSERT_NO_FATAL_FAILURE(InitState());
5008
5009 VkEvent event;
5010 VkEventCreateInfo evci = {};
5011 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5012 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5013 ASSERT_VK_SUCCESS(result);
5014
5015 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005016 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005017 m_commandBuffer->EndCommandBuffer();
5018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005020 // Destroy event dependency prior to submit to cause ERROR
5021 vkDestroyEvent(m_device->device(), event, NULL);
5022
5023 VkSubmitInfo submit_info = {};
5024 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5025 submit_info.commandBufferCount = 1;
5026 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5027 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5028
5029 m_errorMonitor->VerifyFound();
5030}
5031
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005032TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005033 TEST_DESCRIPTION(
5034 "Attempt to draw with a command buffer that is invalid "
5035 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005036 ASSERT_NO_FATAL_FAILURE(InitState());
5037
5038 VkQueryPool query_pool;
5039 VkQueryPoolCreateInfo qpci{};
5040 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5041 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5042 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005043 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005044 ASSERT_VK_SUCCESS(result);
5045
5046 m_commandBuffer->BeginCommandBuffer();
5047 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5048 m_commandBuffer->EndCommandBuffer();
5049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005051 // Destroy query pool dependency prior to submit to cause ERROR
5052 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5053
5054 VkSubmitInfo submit_info = {};
5055 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5056 submit_info.commandBufferCount = 1;
5057 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5058 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5059
5060 m_errorMonitor->VerifyFound();
5061}
5062
Tobin Ehlis24130d92016-07-08 15:50:53 -06005063TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005064 TEST_DESCRIPTION(
5065 "Attempt to draw with a command buffer that is invalid "
5066 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005067 ASSERT_NO_FATAL_FAILURE(InitState());
5068 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5069
5070 VkResult err;
5071
5072 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5073 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5074
5075 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005076 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005077 ASSERT_VK_SUCCESS(err);
5078
5079 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5080 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5081 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005082 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005083 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005084 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005085 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005086 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005087
5088 VkPipelineShaderStageCreateInfo shaderStages[2];
5089 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5090
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005091 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005092 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 -06005093 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005094 shaderStages[0] = vs.GetStageCreateInfo();
5095 shaderStages[1] = fs.GetStageCreateInfo();
5096
5097 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5098 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5099
5100 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5101 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5102 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5103
5104 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5105 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005106 rs_ci.rasterizerDiscardEnable = true;
5107 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005108
5109 VkPipelineColorBlendAttachmentState att = {};
5110 att.blendEnable = VK_FALSE;
5111 att.colorWriteMask = 0xf;
5112
5113 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5114 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5115 cb_ci.attachmentCount = 1;
5116 cb_ci.pAttachments = &att;
5117
5118 VkGraphicsPipelineCreateInfo gp_ci = {};
5119 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5120 gp_ci.stageCount = 2;
5121 gp_ci.pStages = shaderStages;
5122 gp_ci.pVertexInputState = &vi_ci;
5123 gp_ci.pInputAssemblyState = &ia_ci;
5124 gp_ci.pViewportState = &vp_state_ci;
5125 gp_ci.pRasterizationState = &rs_ci;
5126 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005127 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5128 gp_ci.layout = pipeline_layout;
5129 gp_ci.renderPass = renderPass();
5130
5131 VkPipelineCacheCreateInfo pc_ci = {};
5132 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5133
5134 VkPipeline pipeline;
5135 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005136 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005137 ASSERT_VK_SUCCESS(err);
5138
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005139 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005140 ASSERT_VK_SUCCESS(err);
5141
5142 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005143 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005144 m_commandBuffer->EndCommandBuffer();
5145 // Now destroy pipeline in order to cause error when submitting
5146 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5147
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005149
5150 VkSubmitInfo submit_info = {};
5151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5152 submit_info.commandBufferCount = 1;
5153 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5154 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5155
5156 m_errorMonitor->VerifyFound();
5157 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5158 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5159}
5160
Tobin Ehlis31289162016-08-17 14:57:58 -06005161TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005162 TEST_DESCRIPTION(
5163 "Attempt to draw with a command buffer that is invalid "
5164 "due to a bound descriptor set with a buffer dependency "
5165 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005166 ASSERT_NO_FATAL_FAILURE(InitState());
5167 ASSERT_NO_FATAL_FAILURE(InitViewport());
5168 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5169
5170 VkDescriptorPoolSize ds_type_count = {};
5171 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5172 ds_type_count.descriptorCount = 1;
5173
5174 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5175 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5176 ds_pool_ci.pNext = NULL;
5177 ds_pool_ci.maxSets = 1;
5178 ds_pool_ci.poolSizeCount = 1;
5179 ds_pool_ci.pPoolSizes = &ds_type_count;
5180
5181 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005182 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005183 ASSERT_VK_SUCCESS(err);
5184
5185 VkDescriptorSetLayoutBinding dsl_binding = {};
5186 dsl_binding.binding = 0;
5187 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5188 dsl_binding.descriptorCount = 1;
5189 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5190 dsl_binding.pImmutableSamplers = NULL;
5191
5192 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5193 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5194 ds_layout_ci.pNext = NULL;
5195 ds_layout_ci.bindingCount = 1;
5196 ds_layout_ci.pBindings = &dsl_binding;
5197 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005199 ASSERT_VK_SUCCESS(err);
5200
5201 VkDescriptorSet descriptorSet;
5202 VkDescriptorSetAllocateInfo alloc_info = {};
5203 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5204 alloc_info.descriptorSetCount = 1;
5205 alloc_info.descriptorPool = ds_pool;
5206 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005208 ASSERT_VK_SUCCESS(err);
5209
5210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5212 pipeline_layout_ci.pNext = NULL;
5213 pipeline_layout_ci.setLayoutCount = 1;
5214 pipeline_layout_ci.pSetLayouts = &ds_layout;
5215
5216 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005217 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005218 ASSERT_VK_SUCCESS(err);
5219
5220 // Create a buffer to update the descriptor with
5221 uint32_t qfi = 0;
5222 VkBufferCreateInfo buffCI = {};
5223 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5224 buffCI.size = 1024;
5225 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5226 buffCI.queueFamilyIndexCount = 1;
5227 buffCI.pQueueFamilyIndices = &qfi;
5228
5229 VkBuffer buffer;
5230 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5231 ASSERT_VK_SUCCESS(err);
5232 // Allocate memory and bind to buffer so we can make it to the appropriate
5233 // error
5234 VkMemoryAllocateInfo mem_alloc = {};
5235 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5236 mem_alloc.pNext = NULL;
5237 mem_alloc.allocationSize = 1024;
5238 mem_alloc.memoryTypeIndex = 0;
5239
5240 VkMemoryRequirements memReqs;
5241 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005242 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005243 if (!pass) {
5244 vkDestroyBuffer(m_device->device(), buffer, NULL);
5245 return;
5246 }
5247
5248 VkDeviceMemory mem;
5249 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5250 ASSERT_VK_SUCCESS(err);
5251 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5252 ASSERT_VK_SUCCESS(err);
5253 // Correctly update descriptor to avoid "NOT_UPDATED" error
5254 VkDescriptorBufferInfo buffInfo = {};
5255 buffInfo.buffer = buffer;
5256 buffInfo.offset = 0;
5257 buffInfo.range = 1024;
5258
5259 VkWriteDescriptorSet descriptor_write;
5260 memset(&descriptor_write, 0, sizeof(descriptor_write));
5261 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5262 descriptor_write.dstSet = descriptorSet;
5263 descriptor_write.dstBinding = 0;
5264 descriptor_write.descriptorCount = 1;
5265 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5266 descriptor_write.pBufferInfo = &buffInfo;
5267
5268 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5269
5270 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005271 char const *vsSource =
5272 "#version 450\n"
5273 "\n"
5274 "out gl_PerVertex { \n"
5275 " vec4 gl_Position;\n"
5276 "};\n"
5277 "void main(){\n"
5278 " gl_Position = vec4(1);\n"
5279 "}\n";
5280 char const *fsSource =
5281 "#version 450\n"
5282 "\n"
5283 "layout(location=0) out vec4 x;\n"
5284 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5285 "void main(){\n"
5286 " x = vec4(bar.y);\n"
5287 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005288 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5289 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5290 VkPipelineObj pipe(m_device);
5291 pipe.AddShader(&vs);
5292 pipe.AddShader(&fs);
5293 pipe.AddColorAttachment();
5294 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5295
Tony Barbour552f6c02016-12-21 14:34:07 -07005296 m_commandBuffer->BeginCommandBuffer();
5297 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005298 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5299 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5300 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005301
5302 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5303 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5304
Tobin Ehlis31289162016-08-17 14:57:58 -06005305 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005306 m_commandBuffer->EndRenderPass();
5307 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005309 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5310 vkDestroyBuffer(m_device->device(), buffer, NULL);
5311 // Attempt to submit cmd buffer
5312 VkSubmitInfo submit_info = {};
5313 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5314 submit_info.commandBufferCount = 1;
5315 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5316 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5317 m_errorMonitor->VerifyFound();
5318 // Cleanup
5319 vkFreeMemory(m_device->device(), mem, NULL);
5320
5321 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5322 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5323 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5324}
5325
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005326TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005327 TEST_DESCRIPTION(
5328 "Attempt to draw with a command buffer that is invalid "
5329 "due to a bound descriptor sets with a combined image "
5330 "sampler having their image, sampler, and descriptor set "
5331 "each respectively destroyed and then attempting to "
5332 "submit associated cmd buffers. Attempt to destroy a "
5333 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005334 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005335 ASSERT_NO_FATAL_FAILURE(InitViewport());
5336 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5337
5338 VkDescriptorPoolSize ds_type_count = {};
5339 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5340 ds_type_count.descriptorCount = 1;
5341
5342 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5343 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5344 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005345 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005346 ds_pool_ci.maxSets = 1;
5347 ds_pool_ci.poolSizeCount = 1;
5348 ds_pool_ci.pPoolSizes = &ds_type_count;
5349
5350 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005351 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005352 ASSERT_VK_SUCCESS(err);
5353
5354 VkDescriptorSetLayoutBinding dsl_binding = {};
5355 dsl_binding.binding = 0;
5356 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5357 dsl_binding.descriptorCount = 1;
5358 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5359 dsl_binding.pImmutableSamplers = NULL;
5360
5361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5363 ds_layout_ci.pNext = NULL;
5364 ds_layout_ci.bindingCount = 1;
5365 ds_layout_ci.pBindings = &dsl_binding;
5366 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005367 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005368 ASSERT_VK_SUCCESS(err);
5369
5370 VkDescriptorSet descriptorSet;
5371 VkDescriptorSetAllocateInfo alloc_info = {};
5372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5373 alloc_info.descriptorSetCount = 1;
5374 alloc_info.descriptorPool = ds_pool;
5375 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005377 ASSERT_VK_SUCCESS(err);
5378
5379 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5380 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5381 pipeline_layout_ci.pNext = NULL;
5382 pipeline_layout_ci.setLayoutCount = 1;
5383 pipeline_layout_ci.pSetLayouts = &ds_layout;
5384
5385 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005386 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005387 ASSERT_VK_SUCCESS(err);
5388
5389 // Create images to update the descriptor with
5390 VkImage image;
5391 VkImage image2;
5392 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5393 const int32_t tex_width = 32;
5394 const int32_t tex_height = 32;
5395 VkImageCreateInfo image_create_info = {};
5396 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5397 image_create_info.pNext = NULL;
5398 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5399 image_create_info.format = tex_format;
5400 image_create_info.extent.width = tex_width;
5401 image_create_info.extent.height = tex_height;
5402 image_create_info.extent.depth = 1;
5403 image_create_info.mipLevels = 1;
5404 image_create_info.arrayLayers = 1;
5405 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5406 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5407 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5408 image_create_info.flags = 0;
5409 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5410 ASSERT_VK_SUCCESS(err);
5411 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5412 ASSERT_VK_SUCCESS(err);
5413
5414 VkMemoryRequirements memory_reqs;
5415 VkDeviceMemory image_memory;
5416 bool pass;
5417 VkMemoryAllocateInfo memory_info = {};
5418 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5419 memory_info.pNext = NULL;
5420 memory_info.allocationSize = 0;
5421 memory_info.memoryTypeIndex = 0;
5422 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5423 // Allocate enough memory for both images
5424 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005425 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005426 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005427 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005428 ASSERT_VK_SUCCESS(err);
5429 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5430 ASSERT_VK_SUCCESS(err);
5431 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005432 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005433 ASSERT_VK_SUCCESS(err);
5434
5435 VkImageViewCreateInfo image_view_create_info = {};
5436 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5437 image_view_create_info.image = image;
5438 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5439 image_view_create_info.format = tex_format;
5440 image_view_create_info.subresourceRange.layerCount = 1;
5441 image_view_create_info.subresourceRange.baseMipLevel = 0;
5442 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005443 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005444
5445 VkImageView view;
5446 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005447 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005448 ASSERT_VK_SUCCESS(err);
5449 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005450 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005451 ASSERT_VK_SUCCESS(err);
5452 // Create Samplers
5453 VkSamplerCreateInfo sampler_ci = {};
5454 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5455 sampler_ci.pNext = NULL;
5456 sampler_ci.magFilter = VK_FILTER_NEAREST;
5457 sampler_ci.minFilter = VK_FILTER_NEAREST;
5458 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5459 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5460 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5461 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5462 sampler_ci.mipLodBias = 1.0;
5463 sampler_ci.anisotropyEnable = VK_FALSE;
5464 sampler_ci.maxAnisotropy = 1;
5465 sampler_ci.compareEnable = VK_FALSE;
5466 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5467 sampler_ci.minLod = 1.0;
5468 sampler_ci.maxLod = 1.0;
5469 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5470 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5471 VkSampler sampler;
5472 VkSampler sampler2;
5473 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5474 ASSERT_VK_SUCCESS(err);
5475 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5476 ASSERT_VK_SUCCESS(err);
5477 // Update descriptor with image and sampler
5478 VkDescriptorImageInfo img_info = {};
5479 img_info.sampler = sampler;
5480 img_info.imageView = view;
5481 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5482
5483 VkWriteDescriptorSet descriptor_write;
5484 memset(&descriptor_write, 0, sizeof(descriptor_write));
5485 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5486 descriptor_write.dstSet = descriptorSet;
5487 descriptor_write.dstBinding = 0;
5488 descriptor_write.descriptorCount = 1;
5489 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5490 descriptor_write.pImageInfo = &img_info;
5491
5492 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5493
5494 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005495 char const *vsSource =
5496 "#version 450\n"
5497 "\n"
5498 "out gl_PerVertex { \n"
5499 " vec4 gl_Position;\n"
5500 "};\n"
5501 "void main(){\n"
5502 " gl_Position = vec4(1);\n"
5503 "}\n";
5504 char const *fsSource =
5505 "#version 450\n"
5506 "\n"
5507 "layout(set=0, binding=0) uniform sampler2D s;\n"
5508 "layout(location=0) out vec4 x;\n"
5509 "void main(){\n"
5510 " x = texture(s, vec2(1));\n"
5511 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005512 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5513 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5514 VkPipelineObj pipe(m_device);
5515 pipe.AddShader(&vs);
5516 pipe.AddShader(&fs);
5517 pipe.AddColorAttachment();
5518 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5519
5520 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005522 m_commandBuffer->BeginCommandBuffer();
5523 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005524 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5525 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5526 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005527 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5528 VkRect2D scissor = {{0, 0}, {16, 16}};
5529 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5530 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005531 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005532 m_commandBuffer->EndRenderPass();
5533 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005534 // Destroy sampler invalidates the cmd buffer, causing error on submit
5535 vkDestroySampler(m_device->device(), sampler, NULL);
5536 // Attempt to submit cmd buffer
5537 VkSubmitInfo submit_info = {};
5538 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5539 submit_info.commandBufferCount = 1;
5540 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5541 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5542 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005543
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005544 // Now re-update descriptor with valid sampler and delete image
5545 img_info.sampler = sampler2;
5546 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005547
5548 VkCommandBufferBeginInfo info = {};
5549 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5550 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5551
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005553 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005554 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005555 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5556 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5557 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005558 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5559 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005560 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005561 m_commandBuffer->EndRenderPass();
5562 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005563 // Destroy image invalidates the cmd buffer, causing error on submit
5564 vkDestroyImage(m_device->device(), image, NULL);
5565 // Attempt to submit cmd buffer
5566 submit_info = {};
5567 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5568 submit_info.commandBufferCount = 1;
5569 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5570 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5571 m_errorMonitor->VerifyFound();
5572 // Now update descriptor to be valid, but then free descriptor
5573 img_info.imageView = view2;
5574 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005575 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005576 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005577 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5578 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5579 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005580 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5581 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005582 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005583 m_commandBuffer->EndRenderPass();
5584 m_commandBuffer->EndCommandBuffer();
Dave Houltonfbf52152017-01-06 12:55:29 -07005585
5586 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005588 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005589 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005590
5591 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005592 // 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 -07005593 vkQueueWaitIdle(m_device->m_queue);
5594 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5595
5596 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005597 submit_info = {};
5598 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5599 submit_info.commandBufferCount = 1;
5600 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005602 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5603 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005604
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005605 // Cleanup
5606 vkFreeMemory(m_device->device(), image_memory, NULL);
5607 vkDestroySampler(m_device->device(), sampler2, NULL);
5608 vkDestroyImage(m_device->device(), image2, NULL);
5609 vkDestroyImageView(m_device->device(), view, NULL);
5610 vkDestroyImageView(m_device->device(), view2, NULL);
5611 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5612 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5613 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5614}
5615
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005616TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5617 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5618 ASSERT_NO_FATAL_FAILURE(InitState());
5619 ASSERT_NO_FATAL_FAILURE(InitViewport());
5620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5621
5622 VkDescriptorPoolSize ds_type_count = {};
5623 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5624 ds_type_count.descriptorCount = 1;
5625
5626 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5627 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5628 ds_pool_ci.pNext = NULL;
5629 ds_pool_ci.maxSets = 1;
5630 ds_pool_ci.poolSizeCount = 1;
5631 ds_pool_ci.pPoolSizes = &ds_type_count;
5632
5633 VkDescriptorPool ds_pool;
5634 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5635 ASSERT_VK_SUCCESS(err);
5636
5637 VkDescriptorSetLayoutBinding dsl_binding = {};
5638 dsl_binding.binding = 0;
5639 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5640 dsl_binding.descriptorCount = 1;
5641 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5642 dsl_binding.pImmutableSamplers = NULL;
5643
5644 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5645 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5646 ds_layout_ci.pNext = NULL;
5647 ds_layout_ci.bindingCount = 1;
5648 ds_layout_ci.pBindings = &dsl_binding;
5649 VkDescriptorSetLayout ds_layout;
5650 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5651 ASSERT_VK_SUCCESS(err);
5652
5653 VkDescriptorSet descriptor_set;
5654 VkDescriptorSetAllocateInfo alloc_info = {};
5655 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5656 alloc_info.descriptorSetCount = 1;
5657 alloc_info.descriptorPool = ds_pool;
5658 alloc_info.pSetLayouts = &ds_layout;
5659 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5660 ASSERT_VK_SUCCESS(err);
5661
5662 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5663 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5664 pipeline_layout_ci.pNext = NULL;
5665 pipeline_layout_ci.setLayoutCount = 1;
5666 pipeline_layout_ci.pSetLayouts = &ds_layout;
5667
5668 VkPipelineLayout pipeline_layout;
5669 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5670 ASSERT_VK_SUCCESS(err);
5671
5672 // Create image to update the descriptor with
5673 VkImageObj image(m_device);
5674 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5675 ASSERT_TRUE(image.initialized());
5676
5677 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5678 // Create Sampler
5679 VkSamplerCreateInfo sampler_ci = {};
5680 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5681 sampler_ci.pNext = NULL;
5682 sampler_ci.magFilter = VK_FILTER_NEAREST;
5683 sampler_ci.minFilter = VK_FILTER_NEAREST;
5684 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5685 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5686 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5687 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5688 sampler_ci.mipLodBias = 1.0;
5689 sampler_ci.anisotropyEnable = VK_FALSE;
5690 sampler_ci.maxAnisotropy = 1;
5691 sampler_ci.compareEnable = VK_FALSE;
5692 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5693 sampler_ci.minLod = 1.0;
5694 sampler_ci.maxLod = 1.0;
5695 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5696 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5697 VkSampler sampler;
5698 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5699 ASSERT_VK_SUCCESS(err);
5700 // Update descriptor with image and sampler
5701 VkDescriptorImageInfo img_info = {};
5702 img_info.sampler = sampler;
5703 img_info.imageView = view;
5704 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5705
5706 VkWriteDescriptorSet descriptor_write;
5707 memset(&descriptor_write, 0, sizeof(descriptor_write));
5708 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5709 descriptor_write.dstSet = descriptor_set;
5710 descriptor_write.dstBinding = 0;
5711 descriptor_write.descriptorCount = 1;
5712 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5713 descriptor_write.pImageInfo = &img_info;
5714
5715 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5716
5717 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005718 char const *vsSource =
5719 "#version 450\n"
5720 "\n"
5721 "out gl_PerVertex { \n"
5722 " vec4 gl_Position;\n"
5723 "};\n"
5724 "void main(){\n"
5725 " gl_Position = vec4(1);\n"
5726 "}\n";
5727 char const *fsSource =
5728 "#version 450\n"
5729 "\n"
5730 "layout(set=0, binding=0) uniform sampler2D s;\n"
5731 "layout(location=0) out vec4 x;\n"
5732 "void main(){\n"
5733 " x = texture(s, vec2(1));\n"
5734 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005735 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5736 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5737 VkPipelineObj pipe(m_device);
5738 pipe.AddShader(&vs);
5739 pipe.AddShader(&fs);
5740 pipe.AddColorAttachment();
5741 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5742
Tony Barbour552f6c02016-12-21 14:34:07 -07005743 m_commandBuffer->BeginCommandBuffer();
5744 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005745 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5746 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5747 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005748
5749 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5750 VkRect2D scissor = {{0, 0}, {16, 16}};
5751 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5752 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
5753
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005754 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005755 m_commandBuffer->EndRenderPass();
5756 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005757 // Submit cmd buffer to put pool in-flight
5758 VkSubmitInfo submit_info = {};
5759 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5760 submit_info.commandBufferCount = 1;
5761 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5762 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5763 // Destroy pool while in-flight, causing error
5764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5765 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5766 m_errorMonitor->VerifyFound();
5767 vkQueueWaitIdle(m_device->m_queue);
5768 // Cleanup
5769 vkDestroySampler(m_device->device(), sampler, NULL);
5770 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5771 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5772 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005773 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005774}
5775
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005776TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5777 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5778 ASSERT_NO_FATAL_FAILURE(InitState());
5779 ASSERT_NO_FATAL_FAILURE(InitViewport());
5780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5781
5782 VkDescriptorPoolSize ds_type_count = {};
5783 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5784 ds_type_count.descriptorCount = 1;
5785
5786 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5787 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5788 ds_pool_ci.pNext = NULL;
5789 ds_pool_ci.maxSets = 1;
5790 ds_pool_ci.poolSizeCount = 1;
5791 ds_pool_ci.pPoolSizes = &ds_type_count;
5792
5793 VkDescriptorPool ds_pool;
5794 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5795 ASSERT_VK_SUCCESS(err);
5796
5797 VkDescriptorSetLayoutBinding dsl_binding = {};
5798 dsl_binding.binding = 0;
5799 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5800 dsl_binding.descriptorCount = 1;
5801 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5802 dsl_binding.pImmutableSamplers = NULL;
5803
5804 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5805 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5806 ds_layout_ci.pNext = NULL;
5807 ds_layout_ci.bindingCount = 1;
5808 ds_layout_ci.pBindings = &dsl_binding;
5809 VkDescriptorSetLayout ds_layout;
5810 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5811 ASSERT_VK_SUCCESS(err);
5812
5813 VkDescriptorSet descriptorSet;
5814 VkDescriptorSetAllocateInfo alloc_info = {};
5815 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5816 alloc_info.descriptorSetCount = 1;
5817 alloc_info.descriptorPool = ds_pool;
5818 alloc_info.pSetLayouts = &ds_layout;
5819 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5820 ASSERT_VK_SUCCESS(err);
5821
5822 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5823 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5824 pipeline_layout_ci.pNext = NULL;
5825 pipeline_layout_ci.setLayoutCount = 1;
5826 pipeline_layout_ci.pSetLayouts = &ds_layout;
5827
5828 VkPipelineLayout pipeline_layout;
5829 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5830 ASSERT_VK_SUCCESS(err);
5831
5832 // Create images to update the descriptor with
5833 VkImage image;
5834 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5835 const int32_t tex_width = 32;
5836 const int32_t tex_height = 32;
5837 VkImageCreateInfo image_create_info = {};
5838 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5839 image_create_info.pNext = NULL;
5840 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5841 image_create_info.format = tex_format;
5842 image_create_info.extent.width = tex_width;
5843 image_create_info.extent.height = tex_height;
5844 image_create_info.extent.depth = 1;
5845 image_create_info.mipLevels = 1;
5846 image_create_info.arrayLayers = 1;
5847 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5848 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5849 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5850 image_create_info.flags = 0;
5851 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5852 ASSERT_VK_SUCCESS(err);
5853 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5854 VkMemoryRequirements memory_reqs;
5855 VkDeviceMemory image_memory;
5856 bool pass;
5857 VkMemoryAllocateInfo memory_info = {};
5858 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5859 memory_info.pNext = NULL;
5860 memory_info.allocationSize = 0;
5861 memory_info.memoryTypeIndex = 0;
5862 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5863 // Allocate enough memory for image
5864 memory_info.allocationSize = memory_reqs.size;
5865 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5866 ASSERT_TRUE(pass);
5867 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5868 ASSERT_VK_SUCCESS(err);
5869 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5870 ASSERT_VK_SUCCESS(err);
5871
5872 VkImageViewCreateInfo image_view_create_info = {};
5873 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5874 image_view_create_info.image = image;
5875 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5876 image_view_create_info.format = tex_format;
5877 image_view_create_info.subresourceRange.layerCount = 1;
5878 image_view_create_info.subresourceRange.baseMipLevel = 0;
5879 image_view_create_info.subresourceRange.levelCount = 1;
5880 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5881
5882 VkImageView view;
5883 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5884 ASSERT_VK_SUCCESS(err);
5885 // Create Samplers
5886 VkSamplerCreateInfo sampler_ci = {};
5887 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5888 sampler_ci.pNext = NULL;
5889 sampler_ci.magFilter = VK_FILTER_NEAREST;
5890 sampler_ci.minFilter = VK_FILTER_NEAREST;
5891 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5892 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5893 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5894 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5895 sampler_ci.mipLodBias = 1.0;
5896 sampler_ci.anisotropyEnable = VK_FALSE;
5897 sampler_ci.maxAnisotropy = 1;
5898 sampler_ci.compareEnable = VK_FALSE;
5899 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5900 sampler_ci.minLod = 1.0;
5901 sampler_ci.maxLod = 1.0;
5902 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5903 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5904 VkSampler sampler;
5905 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5906 ASSERT_VK_SUCCESS(err);
5907 // Update descriptor with image and sampler
5908 VkDescriptorImageInfo img_info = {};
5909 img_info.sampler = sampler;
5910 img_info.imageView = view;
5911 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5912
5913 VkWriteDescriptorSet descriptor_write;
5914 memset(&descriptor_write, 0, sizeof(descriptor_write));
5915 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5916 descriptor_write.dstSet = descriptorSet;
5917 descriptor_write.dstBinding = 0;
5918 descriptor_write.descriptorCount = 1;
5919 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5920 descriptor_write.pImageInfo = &img_info;
5921 // Break memory binding and attempt update
5922 vkFreeMemory(m_device->device(), image_memory, nullptr);
5923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005924 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005925 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5926 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5927 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5928 m_errorMonitor->VerifyFound();
5929 // Cleanup
5930 vkDestroyImage(m_device->device(), image, NULL);
5931 vkDestroySampler(m_device->device(), sampler, NULL);
5932 vkDestroyImageView(m_device->device(), view, NULL);
5933 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5934 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5935 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5936}
5937
Karl Schultz6addd812016-02-02 17:17:23 -07005938TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005939 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5940 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005941 // Create a valid cmd buffer
5942 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005943 uint64_t fake_pipeline_handle = 0xbaad6001;
5944 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005945 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005946 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5947
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005949 m_commandBuffer->BeginCommandBuffer();
5950 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005951 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005952 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005953
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005954 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005955 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 -06005956 Draw(1, 0, 0, 0);
5957 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005958
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005959 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005960 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 -07005961 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005962 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5963 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005964}
5965
Karl Schultz6addd812016-02-02 17:17:23 -07005966TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005967 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005968 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005971
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005972 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005973 ASSERT_NO_FATAL_FAILURE(InitViewport());
5974 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005975 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005976 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5977 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005978
5979 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005980 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5981 ds_pool_ci.pNext = NULL;
5982 ds_pool_ci.maxSets = 1;
5983 ds_pool_ci.poolSizeCount = 1;
5984 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005985
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005986 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005987 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005988 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005989
Tony Barboureb254902015-07-15 12:50:33 -06005990 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005991 dsl_binding.binding = 0;
5992 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5993 dsl_binding.descriptorCount = 1;
5994 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5995 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005996
Tony Barboureb254902015-07-15 12:50:33 -06005997 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005998 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5999 ds_layout_ci.pNext = NULL;
6000 ds_layout_ci.bindingCount = 1;
6001 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006002 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006003 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006004 ASSERT_VK_SUCCESS(err);
6005
6006 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006007 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006008 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006009 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006010 alloc_info.descriptorPool = ds_pool;
6011 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006012 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006013 ASSERT_VK_SUCCESS(err);
6014
Tony Barboureb254902015-07-15 12:50:33 -06006015 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006016 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6017 pipeline_layout_ci.pNext = NULL;
6018 pipeline_layout_ci.setLayoutCount = 1;
6019 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006020
6021 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006022 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006023 ASSERT_VK_SUCCESS(err);
6024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006025 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006026 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006027 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006028 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006029
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006030 VkPipelineObj pipe(m_device);
6031 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006032 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006033 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006034 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006035
Tony Barbour552f6c02016-12-21 14:34:07 -07006036 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006037 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6038 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6039 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006040
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006041 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006042
Chia-I Wuf7458c52015-10-26 21:10:41 +08006043 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6044 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6045 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006046}
6047
Karl Schultz6addd812016-02-02 17:17:23 -07006048TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006049 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006050 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006051
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006053
6054 ASSERT_NO_FATAL_FAILURE(InitState());
6055 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006056 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6057 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006058
6059 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006060 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6061 ds_pool_ci.pNext = NULL;
6062 ds_pool_ci.maxSets = 1;
6063 ds_pool_ci.poolSizeCount = 1;
6064 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006065
6066 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006067 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006068 ASSERT_VK_SUCCESS(err);
6069
6070 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006071 dsl_binding.binding = 0;
6072 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6073 dsl_binding.descriptorCount = 1;
6074 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6075 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006076
6077 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006078 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6079 ds_layout_ci.pNext = NULL;
6080 ds_layout_ci.bindingCount = 1;
6081 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006082 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006083 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006084 ASSERT_VK_SUCCESS(err);
6085
6086 VkDescriptorSet descriptorSet;
6087 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006088 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006089 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006090 alloc_info.descriptorPool = ds_pool;
6091 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006093 ASSERT_VK_SUCCESS(err);
6094
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006095 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006096 VkWriteDescriptorSet descriptor_write;
6097 memset(&descriptor_write, 0, sizeof(descriptor_write));
6098 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6099 descriptor_write.dstSet = descriptorSet;
6100 descriptor_write.dstBinding = 0;
6101 descriptor_write.descriptorCount = 1;
6102 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6103 descriptor_write.pTexelBufferView = &view;
6104
6105 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6106
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006107 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006108
6109 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6110 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6111}
6112
Mark Youngd339ba32016-05-30 13:28:35 -06006113TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006114 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 -06006115
6116 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006118 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006119
6120 ASSERT_NO_FATAL_FAILURE(InitState());
6121
6122 // Create a buffer with no bound memory and then attempt to create
6123 // a buffer view.
6124 VkBufferCreateInfo buff_ci = {};
6125 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006126 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006127 buff_ci.size = 256;
6128 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6129 VkBuffer buffer;
6130 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6131 ASSERT_VK_SUCCESS(err);
6132
6133 VkBufferViewCreateInfo buff_view_ci = {};
6134 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6135 buff_view_ci.buffer = buffer;
6136 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6137 buff_view_ci.range = VK_WHOLE_SIZE;
6138 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006139 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006140
6141 m_errorMonitor->VerifyFound();
6142 vkDestroyBuffer(m_device->device(), buffer, NULL);
6143 // If last error is success, it still created the view, so delete it.
6144 if (err == VK_SUCCESS) {
6145 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6146 }
6147}
6148
Karl Schultz6addd812016-02-02 17:17:23 -07006149TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6150 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6151 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006152 // 1. No dynamicOffset supplied
6153 // 2. Too many dynamicOffsets supplied
6154 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006155 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6157 " requires 1 dynamicOffsets, but only "
6158 "0 dynamicOffsets are left in "
6159 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006160
6161 ASSERT_NO_FATAL_FAILURE(InitState());
6162 ASSERT_NO_FATAL_FAILURE(InitViewport());
6163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6164
6165 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006166 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6167 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006168
6169 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006170 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6171 ds_pool_ci.pNext = NULL;
6172 ds_pool_ci.maxSets = 1;
6173 ds_pool_ci.poolSizeCount = 1;
6174 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006175
6176 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006177 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006178 ASSERT_VK_SUCCESS(err);
6179
6180 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006181 dsl_binding.binding = 0;
6182 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6183 dsl_binding.descriptorCount = 1;
6184 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6185 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006186
6187 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006188 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6189 ds_layout_ci.pNext = NULL;
6190 ds_layout_ci.bindingCount = 1;
6191 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006192 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006193 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006194 ASSERT_VK_SUCCESS(err);
6195
6196 VkDescriptorSet descriptorSet;
6197 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006198 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006199 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006200 alloc_info.descriptorPool = ds_pool;
6201 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006202 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006203 ASSERT_VK_SUCCESS(err);
6204
6205 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006206 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6207 pipeline_layout_ci.pNext = NULL;
6208 pipeline_layout_ci.setLayoutCount = 1;
6209 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006210
6211 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006212 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006213 ASSERT_VK_SUCCESS(err);
6214
6215 // Create a buffer to update the descriptor with
6216 uint32_t qfi = 0;
6217 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006218 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6219 buffCI.size = 1024;
6220 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6221 buffCI.queueFamilyIndexCount = 1;
6222 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006223
6224 VkBuffer dyub;
6225 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6226 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006227 // Allocate memory and bind to buffer so we can make it to the appropriate
6228 // error
6229 VkMemoryAllocateInfo mem_alloc = {};
6230 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6231 mem_alloc.pNext = NULL;
6232 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006233 mem_alloc.memoryTypeIndex = 0;
6234
6235 VkMemoryRequirements memReqs;
6236 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006237 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006238 if (!pass) {
6239 vkDestroyBuffer(m_device->device(), dyub, NULL);
6240 return;
6241 }
6242
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006243 VkDeviceMemory mem;
6244 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6245 ASSERT_VK_SUCCESS(err);
6246 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6247 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006248 // Correctly update descriptor to avoid "NOT_UPDATED" error
6249 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006250 buffInfo.buffer = dyub;
6251 buffInfo.offset = 0;
6252 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006253
6254 VkWriteDescriptorSet descriptor_write;
6255 memset(&descriptor_write, 0, sizeof(descriptor_write));
6256 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6257 descriptor_write.dstSet = descriptorSet;
6258 descriptor_write.dstBinding = 0;
6259 descriptor_write.descriptorCount = 1;
6260 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6261 descriptor_write.pBufferInfo = &buffInfo;
6262
6263 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6264
Tony Barbour552f6c02016-12-21 14:34:07 -07006265 m_commandBuffer->BeginCommandBuffer();
6266 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006267 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6268 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006269 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006270 uint32_t pDynOff[2] = {512, 756};
6271 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6273 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6274 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6275 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006276 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006277 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6279 " dynamic offset 512 combined with "
6280 "offset 0 and range 1024 that "
6281 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006282 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006283 char const *vsSource =
6284 "#version 450\n"
6285 "\n"
6286 "out gl_PerVertex { \n"
6287 " vec4 gl_Position;\n"
6288 "};\n"
6289 "void main(){\n"
6290 " gl_Position = vec4(1);\n"
6291 "}\n";
6292 char const *fsSource =
6293 "#version 450\n"
6294 "\n"
6295 "layout(location=0) out vec4 x;\n"
6296 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6297 "void main(){\n"
6298 " x = vec4(bar.y);\n"
6299 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006300 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6301 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6302 VkPipelineObj pipe(m_device);
6303 pipe.AddShader(&vs);
6304 pipe.AddShader(&fs);
6305 pipe.AddColorAttachment();
6306 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6307
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006308 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6309 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6310 VkRect2D scissor = {{0, 0}, {16, 16}};
6311 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6312
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006313 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006314 // This update should succeed, but offset size of 512 will overstep buffer
6315 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006316 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6317 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006318 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006319 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006320
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006321 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006322 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006323
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006324 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006325 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006326 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6327}
6328
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006329TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006330 TEST_DESCRIPTION(
6331 "Attempt to update a descriptor with a non-sparse buffer "
6332 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006333 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006335 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6337 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006338
6339 ASSERT_NO_FATAL_FAILURE(InitState());
6340 ASSERT_NO_FATAL_FAILURE(InitViewport());
6341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6342
6343 VkDescriptorPoolSize ds_type_count = {};
6344 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6345 ds_type_count.descriptorCount = 1;
6346
6347 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6348 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6349 ds_pool_ci.pNext = NULL;
6350 ds_pool_ci.maxSets = 1;
6351 ds_pool_ci.poolSizeCount = 1;
6352 ds_pool_ci.pPoolSizes = &ds_type_count;
6353
6354 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006355 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006356 ASSERT_VK_SUCCESS(err);
6357
6358 VkDescriptorSetLayoutBinding dsl_binding = {};
6359 dsl_binding.binding = 0;
6360 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6361 dsl_binding.descriptorCount = 1;
6362 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6363 dsl_binding.pImmutableSamplers = NULL;
6364
6365 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6366 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6367 ds_layout_ci.pNext = NULL;
6368 ds_layout_ci.bindingCount = 1;
6369 ds_layout_ci.pBindings = &dsl_binding;
6370 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006371 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006372 ASSERT_VK_SUCCESS(err);
6373
6374 VkDescriptorSet descriptorSet;
6375 VkDescriptorSetAllocateInfo alloc_info = {};
6376 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6377 alloc_info.descriptorSetCount = 1;
6378 alloc_info.descriptorPool = ds_pool;
6379 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006380 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006381 ASSERT_VK_SUCCESS(err);
6382
6383 // Create a buffer to update the descriptor with
6384 uint32_t qfi = 0;
6385 VkBufferCreateInfo buffCI = {};
6386 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6387 buffCI.size = 1024;
6388 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6389 buffCI.queueFamilyIndexCount = 1;
6390 buffCI.pQueueFamilyIndices = &qfi;
6391
6392 VkBuffer dyub;
6393 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6394 ASSERT_VK_SUCCESS(err);
6395
6396 // Attempt to update descriptor without binding memory to it
6397 VkDescriptorBufferInfo buffInfo = {};
6398 buffInfo.buffer = dyub;
6399 buffInfo.offset = 0;
6400 buffInfo.range = 1024;
6401
6402 VkWriteDescriptorSet descriptor_write;
6403 memset(&descriptor_write, 0, sizeof(descriptor_write));
6404 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6405 descriptor_write.dstSet = descriptorSet;
6406 descriptor_write.dstBinding = 0;
6407 descriptor_write.descriptorCount = 1;
6408 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6409 descriptor_write.pBufferInfo = &buffInfo;
6410
6411 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6412 m_errorMonitor->VerifyFound();
6413
6414 vkDestroyBuffer(m_device->device(), dyub, NULL);
6415 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6416 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6417}
6418
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006419TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006420 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006421 ASSERT_NO_FATAL_FAILURE(InitState());
6422 ASSERT_NO_FATAL_FAILURE(InitViewport());
6423 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6424
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006425 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006426 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006427 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6428 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6429 pipeline_layout_ci.pushConstantRangeCount = 1;
6430 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6431
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006432 //
6433 // Check for invalid push constant ranges in pipeline layouts.
6434 //
6435 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006436 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006437 char const *msg;
6438 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006439
Karl Schultzc81037d2016-05-12 08:11:23 -06006440 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6441 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6442 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6443 "vkCreatePipelineLayout() call has push constants index 0 with "
6444 "size 0."},
6445 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6446 "vkCreatePipelineLayout() call has push constants index 0 with "
6447 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006448 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006449 "vkCreatePipelineLayout() call has push constants index 0 with "
6450 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006451 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006452 "vkCreatePipelineLayout() call has push constants index 0 with "
6453 "size 0."},
6454 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6455 "vkCreatePipelineLayout() call has push constants index 0 with "
6456 "offset 1. Offset must"},
6457 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6458 "vkCreatePipelineLayout() call has push constants index 0 "
6459 "with offset "},
6460 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6461 "vkCreatePipelineLayout() call has push constants "
6462 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006463 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006464 "vkCreatePipelineLayout() call has push constants index 0 "
6465 "with offset "},
6466 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6467 "vkCreatePipelineLayout() call has push "
6468 "constants index 0 with offset "},
6469 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6470 "vkCreatePipelineLayout() call has push "
6471 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006472 }};
6473
6474 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006475 for (const auto &iter : range_tests) {
6476 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6478 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006479 m_errorMonitor->VerifyFound();
6480 if (VK_SUCCESS == err) {
6481 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6482 }
6483 }
6484
6485 // Check for invalid stage flag
6486 pc_range.offset = 0;
6487 pc_range.size = 16;
6488 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006489 m_errorMonitor->SetDesiredFailureMsg(
6490 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6491 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006492 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006493 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006494 if (VK_SUCCESS == err) {
6495 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6496 }
6497
6498 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006499 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006500 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006501 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006502 char const *msg;
6503 };
6504
Karl Schultzc81037d2016-05-12 08:11:23 -06006505 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006506 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6507 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6508 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6509 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6510 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006511 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006512 {
6513 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6514 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6515 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6516 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6517 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006518 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006519 },
6520 {
6521 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6522 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6523 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6524 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6525 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006526 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006527 },
6528 {
6529 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6530 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6531 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6532 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6533 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006534 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006535 },
6536 {
6537 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6538 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6539 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6540 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6541 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006542 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006543 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006544
Karl Schultzc81037d2016-05-12 08:11:23 -06006545 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006546 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006547 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6549 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006550 m_errorMonitor->VerifyFound();
6551 if (VK_SUCCESS == err) {
6552 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6553 }
6554 }
6555
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006556 //
6557 // CmdPushConstants tests
6558 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006559 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006560
6561 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006562 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6563 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006564 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006565 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6566 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006567 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006568 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6569 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006570 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006571 "vkCmdPushConstants() call has push constants with offset 1. "
6572 "Offset must be a multiple of 4."},
6573 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6574 "vkCmdPushConstants() call has push constants with offset 1. "
6575 "Offset must be a multiple of 4."},
6576 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6577 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6578 "0x1 not within flag-matching ranges in pipeline layout"},
6579 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6580 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6581 "0x1 not within flag-matching ranges in pipeline layout"},
6582 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6583 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6584 "0x1 not within flag-matching ranges in pipeline layout"},
6585 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6586 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6587 "0x1 not within flag-matching ranges in pipeline layout"},
6588 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6589 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6590 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006591 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006592 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6593 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006594 }};
6595
Tony Barbour552f6c02016-12-21 14:34:07 -07006596 m_commandBuffer->BeginCommandBuffer();
6597 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006598
6599 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006600 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006601 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006602 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006603 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006604 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006605 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006606 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006607 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6609 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006610 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006611 m_errorMonitor->VerifyFound();
6612 }
6613
6614 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006616 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006617 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006618 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006619
Karl Schultzc81037d2016-05-12 08:11:23 -06006620 // overlapping range tests with cmd
6621 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6622 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6623 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6624 "0x1 not within flag-matching ranges in pipeline layout"},
6625 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6626 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6627 "0x1 not within flag-matching ranges in pipeline layout"},
6628 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6629 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6630 "0x1 not within flag-matching ranges in pipeline layout"},
6631 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006632 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006633 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006634 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6635 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006636 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006637 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006638 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006639 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006640 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006641 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6643 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006644 iter.range.size, dummy_values);
6645 m_errorMonitor->VerifyFound();
6646 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006647 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6648
Tony Barbour552f6c02016-12-21 14:34:07 -07006649 m_commandBuffer->EndRenderPass();
6650 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006651}
6652
Karl Schultz6addd812016-02-02 17:17:23 -07006653TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006654 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006655 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006656
6657 ASSERT_NO_FATAL_FAILURE(InitState());
6658 ASSERT_NO_FATAL_FAILURE(InitViewport());
6659 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6660
6661 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6662 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006663 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6664 ds_type_count[0].descriptorCount = 10;
6665 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6666 ds_type_count[1].descriptorCount = 2;
6667 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6668 ds_type_count[2].descriptorCount = 2;
6669 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6670 ds_type_count[3].descriptorCount = 5;
6671 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6672 // type
6673 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6674 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6675 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006676
6677 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006678 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6679 ds_pool_ci.pNext = NULL;
6680 ds_pool_ci.maxSets = 5;
6681 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6682 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006683
6684 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006685 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006686 ASSERT_VK_SUCCESS(err);
6687
6688 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6689 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006690 dsl_binding[0].binding = 0;
6691 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6692 dsl_binding[0].descriptorCount = 5;
6693 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6694 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006695
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006696 // Create layout identical to set0 layout but w/ different stageFlags
6697 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006698 dsl_fs_stage_only.binding = 0;
6699 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6700 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006701 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6702 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006703 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006704 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006705 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6706 ds_layout_ci.pNext = NULL;
6707 ds_layout_ci.bindingCount = 1;
6708 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006709 static const uint32_t NUM_LAYOUTS = 4;
6710 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006711 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006712 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6713 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006714 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006715 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006716 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006717 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006718 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006719 dsl_binding[0].binding = 0;
6720 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006721 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006722 dsl_binding[1].binding = 1;
6723 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6724 dsl_binding[1].descriptorCount = 2;
6725 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6726 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006727 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006728 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006729 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006730 ASSERT_VK_SUCCESS(err);
6731 dsl_binding[0].binding = 0;
6732 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006733 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006734 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006735 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006736 ASSERT_VK_SUCCESS(err);
6737 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006738 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006739 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006740 ASSERT_VK_SUCCESS(err);
6741
6742 static const uint32_t NUM_SETS = 4;
6743 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6744 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006745 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006746 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006747 alloc_info.descriptorPool = ds_pool;
6748 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006749 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006750 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006751 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006752 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006753 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006754 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006755 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006756
6757 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006758 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6759 pipeline_layout_ci.pNext = NULL;
6760 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6761 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006762
6763 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006764 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006765 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006766 // Create pipelineLayout with only one setLayout
6767 pipeline_layout_ci.setLayoutCount = 1;
6768 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006769 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006770 ASSERT_VK_SUCCESS(err);
6771 // Create pipelineLayout with 2 descriptor setLayout at index 0
6772 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6773 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006774 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006775 ASSERT_VK_SUCCESS(err);
6776 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6777 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6778 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006779 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006780 ASSERT_VK_SUCCESS(err);
6781 // Create pipelineLayout with UB type, but stageFlags for FS only
6782 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6783 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006784 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006785 ASSERT_VK_SUCCESS(err);
6786 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6787 VkDescriptorSetLayout pl_bad_s0[2] = {};
6788 pl_bad_s0[0] = ds_layout_fs_only;
6789 pl_bad_s0[1] = ds_layout[1];
6790 pipeline_layout_ci.setLayoutCount = 2;
6791 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6792 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006793 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006794 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006795
Tobin Ehlis88452832015-12-03 09:40:56 -07006796 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006797 char const *vsSource =
6798 "#version 450\n"
6799 "\n"
6800 "out gl_PerVertex {\n"
6801 " vec4 gl_Position;\n"
6802 "};\n"
6803 "void main(){\n"
6804 " gl_Position = vec4(1);\n"
6805 "}\n";
6806 char const *fsSource =
6807 "#version 450\n"
6808 "\n"
6809 "layout(location=0) out vec4 x;\n"
6810 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6811 "void main(){\n"
6812 " x = vec4(bar.y);\n"
6813 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006814 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6815 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006816 VkPipelineObj pipe(m_device);
6817 pipe.AddShader(&vs);
6818 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006819 pipe.AddColorAttachment();
6820 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006821
Tony Barbour552f6c02016-12-21 14:34:07 -07006822 m_commandBuffer->BeginCommandBuffer();
6823 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006824
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006825 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006826 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6827 // of PSO
6828 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6829 // cmd_pipeline.c
6830 // due to the fact that cmd_alloc_dset_data() has not been called in
6831 // cmd_bind_graphics_pipeline()
6832 // TODO : Want to cause various binding incompatibility issues here to test
6833 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006834 // First cause various verify_layout_compatibility() fails
6835 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006836 // verify_set_layout_compatibility fail cases:
6837 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006839 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6840 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006841 m_errorMonitor->VerifyFound();
6842
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006843 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6845 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6846 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006847 m_errorMonitor->VerifyFound();
6848
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006849 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006850 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6851 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6853 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6854 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006855 m_errorMonitor->VerifyFound();
6856
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006857 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6858 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6860 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6861 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006862 m_errorMonitor->VerifyFound();
6863
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006864 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6865 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6867 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6868 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6869 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006870 m_errorMonitor->VerifyFound();
6871
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006872 // Cause INFO messages due to disturbing previously bound Sets
6873 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006874 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6875 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006876 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6878 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6879 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006880 m_errorMonitor->VerifyFound();
6881
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006882 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6883 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006884 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6886 " newly bound as set #0 so set #1 and "
6887 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006888 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6889 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006890 m_errorMonitor->VerifyFound();
6891
Tobin Ehlis10fad692016-07-07 12:00:36 -06006892 // Now that we're done actively using the pipelineLayout that gfx pipeline
6893 // was created with, we should be able to delete it. Do that now to verify
6894 // that validation obeys pipelineLayout lifetime
6895 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6896
Tobin Ehlis88452832015-12-03 09:40:56 -07006897 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006898 // 1. Error due to not binding required set (we actually use same code as
6899 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006900 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6901 &descriptorSet[0], 0, NULL);
6902 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6903 &descriptorSet[1], 0, NULL);
6904 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 -07006905
6906 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6907 VkRect2D scissor = {{0, 0}, {16, 16}};
6908 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6909 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6910
Tobin Ehlis88452832015-12-03 09:40:56 -07006911 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006912 m_errorMonitor->VerifyFound();
6913
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006914 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006915 // 2. Error due to bound set not being compatible with PSO's
6916 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006917 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6918 &descriptorSet[0], 0, NULL);
6919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006920 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006921 m_errorMonitor->VerifyFound();
6922
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006923 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006924 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006925 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6926 }
6927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006928 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6929 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6930}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006931
Karl Schultz6addd812016-02-02 17:17:23 -07006932TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6934 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006935
6936 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006937 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006938 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006939 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006940
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006941 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006942}
6943
Karl Schultz6addd812016-02-02 17:17:23 -07006944TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6945 VkResult err;
6946 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006947
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006949
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006950 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006951
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006952 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006953 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006954 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006955 cmd.commandPool = m_commandPool;
6956 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006957 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006958
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006959 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006960 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006961
6962 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07006963 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07006964 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6965
6966 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006967 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006968 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006969 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 -07006970 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006971
6972 // The error should be caught by validation of the BeginCommandBuffer call
6973 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6974
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006975 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006976 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006977}
6978
Karl Schultz6addd812016-02-02 17:17:23 -07006979TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006980 // Cause error due to Begin while recording CB
6981 // Then cause 2 errors for attempting to reset CB w/o having
6982 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6983 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006985
6986 ASSERT_NO_FATAL_FAILURE(InitState());
6987
6988 // Calls AllocateCommandBuffers
6989 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6990
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006991 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07006992 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006993 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6994 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006995 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6996 cmd_buf_info.pNext = NULL;
6997 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006998 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006999
7000 // Begin CB to transition to recording state
7001 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7002 // Can't re-begin. This should trigger error
7003 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007004 m_errorMonitor->VerifyFound();
7005
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007007 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007008 // Reset attempt will trigger error due to incorrect CommandPool state
7009 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007010 m_errorMonitor->VerifyFound();
7011
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007013 // Transition CB to RECORDED state
7014 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7015 // Now attempting to Begin will implicitly reset, which triggers error
7016 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007017 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007018}
7019
Karl Schultz6addd812016-02-02 17:17:23 -07007020TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007021 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007022 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007023
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7025 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007026
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007027 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007029
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007030 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007031 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7032 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007033
7034 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007035 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7036 ds_pool_ci.pNext = NULL;
7037 ds_pool_ci.maxSets = 1;
7038 ds_pool_ci.poolSizeCount = 1;
7039 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007040
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007041 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007042 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007043 ASSERT_VK_SUCCESS(err);
7044
Tony Barboureb254902015-07-15 12:50:33 -06007045 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007046 dsl_binding.binding = 0;
7047 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7048 dsl_binding.descriptorCount = 1;
7049 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7050 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007051
Tony Barboureb254902015-07-15 12:50:33 -06007052 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007053 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7054 ds_layout_ci.pNext = NULL;
7055 ds_layout_ci.bindingCount = 1;
7056 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007057
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007058 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007059 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007060 ASSERT_VK_SUCCESS(err);
7061
7062 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007063 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007064 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007065 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007066 alloc_info.descriptorPool = ds_pool;
7067 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007068 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007069 ASSERT_VK_SUCCESS(err);
7070
Tony Barboureb254902015-07-15 12:50:33 -06007071 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007072 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7073 pipeline_layout_ci.setLayoutCount = 1;
7074 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007075
7076 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007077 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007078 ASSERT_VK_SUCCESS(err);
7079
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007080 VkViewport vp = {}; // Just need dummy vp to point to
7081 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007082
7083 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007084 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7085 vp_state_ci.scissorCount = 1;
7086 vp_state_ci.pScissors = &sc;
7087 vp_state_ci.viewportCount = 1;
7088 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007089
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007090 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7091 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7092 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7093 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7094 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7095 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007096 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007097 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007098 rs_state_ci.lineWidth = 1.0f;
7099
7100 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7101 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7102 vi_ci.pNext = nullptr;
7103 vi_ci.vertexBindingDescriptionCount = 0;
7104 vi_ci.pVertexBindingDescriptions = nullptr;
7105 vi_ci.vertexAttributeDescriptionCount = 0;
7106 vi_ci.pVertexAttributeDescriptions = nullptr;
7107
7108 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7109 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7110 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7111
7112 VkPipelineShaderStageCreateInfo shaderStages[2];
7113 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7114
7115 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7116 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7117 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
7118 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007119
Tony Barboureb254902015-07-15 12:50:33 -06007120 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007121 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7122 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007123 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007124 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7125 gp_ci.layout = pipeline_layout;
7126 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007127 gp_ci.pVertexInputState = &vi_ci;
7128 gp_ci.pInputAssemblyState = &ia_ci;
7129
7130 gp_ci.stageCount = 1;
7131 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007132
7133 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007134 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7135 pc_ci.initialDataSize = 0;
7136 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007137
7138 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007139 VkPipelineCache pipelineCache;
7140
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007141 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007142 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007143 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007144 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007145
Chia-I Wuf7458c52015-10-26 21:10:41 +08007146 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7147 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7148 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7149 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007150}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007151
Tobin Ehlis912df022015-09-17 08:46:18 -06007152/*// TODO : This test should be good, but needs Tess support in compiler to run
7153TEST_F(VkLayerTest, InvalidPatchControlPoints)
7154{
7155 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007156 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007157
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007159 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7160primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007161
Tobin Ehlis912df022015-09-17 08:46:18 -06007162 ASSERT_NO_FATAL_FAILURE(InitState());
7163 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007164
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007165 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007166 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007167 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007168
7169 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7170 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7171 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007172 ds_pool_ci.poolSizeCount = 1;
7173 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007174
7175 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007176 err = vkCreateDescriptorPool(m_device->device(),
7177VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007178 ASSERT_VK_SUCCESS(err);
7179
7180 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007181 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007182 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007183 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007184 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7185 dsl_binding.pImmutableSamplers = NULL;
7186
7187 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007188 ds_layout_ci.sType =
7189VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007190 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007191 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007192 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007193
7194 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007195 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7196&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007197 ASSERT_VK_SUCCESS(err);
7198
7199 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007200 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7201VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007202 ASSERT_VK_SUCCESS(err);
7203
7204 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007205 pipeline_layout_ci.sType =
7206VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007207 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007208 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007209 pipeline_layout_ci.pSetLayouts = &ds_layout;
7210
7211 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007212 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7213&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007214 ASSERT_VK_SUCCESS(err);
7215
7216 VkPipelineShaderStageCreateInfo shaderStages[3];
7217 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7218
Karl Schultz6addd812016-02-02 17:17:23 -07007219 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7220this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007221 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007222 VkShaderObj
7223tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7224this);
7225 VkShaderObj
7226te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7227this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007228
Karl Schultz6addd812016-02-02 17:17:23 -07007229 shaderStages[0].sType =
7230VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007231 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007232 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007233 shaderStages[1].sType =
7234VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007235 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007236 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007237 shaderStages[2].sType =
7238VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007239 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007240 shaderStages[2].shader = te.handle();
7241
7242 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007243 iaCI.sType =
7244VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007245 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007246
7247 VkPipelineTessellationStateCreateInfo tsCI = {};
7248 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7249 tsCI.patchControlPoints = 0; // This will cause an error
7250
7251 VkGraphicsPipelineCreateInfo gp_ci = {};
7252 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7253 gp_ci.pNext = NULL;
7254 gp_ci.stageCount = 3;
7255 gp_ci.pStages = shaderStages;
7256 gp_ci.pVertexInputState = NULL;
7257 gp_ci.pInputAssemblyState = &iaCI;
7258 gp_ci.pTessellationState = &tsCI;
7259 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007260 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007261 gp_ci.pMultisampleState = NULL;
7262 gp_ci.pDepthStencilState = NULL;
7263 gp_ci.pColorBlendState = NULL;
7264 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7265 gp_ci.layout = pipeline_layout;
7266 gp_ci.renderPass = renderPass();
7267
7268 VkPipelineCacheCreateInfo pc_ci = {};
7269 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7270 pc_ci.pNext = NULL;
7271 pc_ci.initialSize = 0;
7272 pc_ci.initialData = 0;
7273 pc_ci.maxSize = 0;
7274
7275 VkPipeline pipeline;
7276 VkPipelineCache pipelineCache;
7277
Karl Schultz6addd812016-02-02 17:17:23 -07007278 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7279&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007280 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007281 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7282&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007284 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007285
Chia-I Wuf7458c52015-10-26 21:10:41 +08007286 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7287 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7288 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7289 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007290}
7291*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007292
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007293TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007294 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007295
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007296 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007297
Tobin Ehlise68360f2015-10-01 11:15:13 -06007298 ASSERT_NO_FATAL_FAILURE(InitState());
7299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007300
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007301 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007302 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7303 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007304
7305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7307 ds_pool_ci.maxSets = 1;
7308 ds_pool_ci.poolSizeCount = 1;
7309 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007310
7311 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007312 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007313 ASSERT_VK_SUCCESS(err);
7314
7315 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007316 dsl_binding.binding = 0;
7317 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7318 dsl_binding.descriptorCount = 1;
7319 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007320
7321 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007322 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7323 ds_layout_ci.bindingCount = 1;
7324 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007325
7326 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007327 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007328 ASSERT_VK_SUCCESS(err);
7329
7330 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007331 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007332 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007333 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007334 alloc_info.descriptorPool = ds_pool;
7335 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007337 ASSERT_VK_SUCCESS(err);
7338
7339 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007340 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7341 pipeline_layout_ci.setLayoutCount = 1;
7342 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007343
7344 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007345 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007346 ASSERT_VK_SUCCESS(err);
7347
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007348 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007349 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007350 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007351 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007352 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007353 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007354
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007355 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7356 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7357 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7358 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7359 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7360 rs_state_ci.depthClampEnable = VK_FALSE;
7361 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7362 rs_state_ci.depthBiasEnable = VK_FALSE;
7363
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007364 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7365 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7366 vi_ci.pNext = nullptr;
7367 vi_ci.vertexBindingDescriptionCount = 0;
7368 vi_ci.pVertexBindingDescriptions = nullptr;
7369 vi_ci.vertexAttributeDescriptionCount = 0;
7370 vi_ci.pVertexAttributeDescriptions = nullptr;
7371
7372 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7373 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7374 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7375
7376 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7377 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7378 pipe_ms_state_ci.pNext = NULL;
7379 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7380 pipe_ms_state_ci.sampleShadingEnable = 0;
7381 pipe_ms_state_ci.minSampleShading = 1.0;
7382 pipe_ms_state_ci.pSampleMask = NULL;
7383
Cody Northropeb3a6c12015-10-05 14:44:45 -06007384 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007385 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007386
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007387 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007388 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007389 shaderStages[0] = vs.GetStageCreateInfo();
7390 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007391
7392 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007393 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7394 gp_ci.stageCount = 2;
7395 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007396 gp_ci.pVertexInputState = &vi_ci;
7397 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007398 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007399 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007400 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007401 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7402 gp_ci.layout = pipeline_layout;
7403 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007404
7405 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007406 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007407
7408 VkPipeline pipeline;
7409 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007410 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007411 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007412
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007413 if (!m_device->phy().features().multiViewport) {
7414 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7415
7416 // Check case where multiViewport is disabled and viewport count is not 1
7417 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7419 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7420 vp_state_ci.scissorCount = 0;
7421 vp_state_ci.viewportCount = 0;
7422 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7423 m_errorMonitor->VerifyFound();
7424 } else {
7425 if (m_device->props.limits.maxViewports == 1) {
7426 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7427 } else {
7428 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7429
7430 // Check is that viewportcount and scissorcount match
7431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7432 vp_state_ci.scissorCount = 1;
7433 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7434 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7435 m_errorMonitor->VerifyFound();
7436
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007437 // Check case where multiViewport is enabled and viewport count is greater than max
7438 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7441 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7442 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7443 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7444 m_errorMonitor->VerifyFound();
7445 }
7446 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007447
Chia-I Wuf7458c52015-10-26 21:10:41 +08007448 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7449 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7450 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7451 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007452}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007453
7454// 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
7455// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007456TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007457 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007458
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007459 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7460
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007462
Tobin Ehlise68360f2015-10-01 11:15:13 -06007463 ASSERT_NO_FATAL_FAILURE(InitState());
7464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007465
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007466 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007467 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7468 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007469
7470 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007471 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7472 ds_pool_ci.maxSets = 1;
7473 ds_pool_ci.poolSizeCount = 1;
7474 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007475
7476 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007477 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007478 ASSERT_VK_SUCCESS(err);
7479
7480 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007481 dsl_binding.binding = 0;
7482 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7483 dsl_binding.descriptorCount = 1;
7484 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007485
7486 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007487 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7488 ds_layout_ci.bindingCount = 1;
7489 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007490
7491 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007492 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007493 ASSERT_VK_SUCCESS(err);
7494
7495 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007496 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007497 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007498 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007499 alloc_info.descriptorPool = ds_pool;
7500 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007501 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007502 ASSERT_VK_SUCCESS(err);
7503
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007504 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7505 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7506 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7507
7508 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7509 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7510 vi_ci.pNext = nullptr;
7511 vi_ci.vertexBindingDescriptionCount = 0;
7512 vi_ci.pVertexBindingDescriptions = nullptr;
7513 vi_ci.vertexAttributeDescriptionCount = 0;
7514 vi_ci.pVertexAttributeDescriptions = nullptr;
7515
7516 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7517 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7518 pipe_ms_state_ci.pNext = NULL;
7519 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7520 pipe_ms_state_ci.sampleShadingEnable = 0;
7521 pipe_ms_state_ci.minSampleShading = 1.0;
7522 pipe_ms_state_ci.pSampleMask = NULL;
7523
Tobin Ehlise68360f2015-10-01 11:15:13 -06007524 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007525 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7526 pipeline_layout_ci.setLayoutCount = 1;
7527 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007528
7529 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007530 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007531 ASSERT_VK_SUCCESS(err);
7532
7533 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7534 // Set scissor as dynamic to avoid second error
7535 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007536 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7537 dyn_state_ci.dynamicStateCount = 1;
7538 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007539
Cody Northropeb3a6c12015-10-05 14:44:45 -06007540 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007541 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007542
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007543 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007544 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7545 // 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 +08007546 shaderStages[0] = vs.GetStageCreateInfo();
7547 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007548
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007549 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7550 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7551 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7552 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7553 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7554 rs_state_ci.depthClampEnable = VK_FALSE;
7555 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7556 rs_state_ci.depthBiasEnable = VK_FALSE;
7557
Tobin Ehlise68360f2015-10-01 11:15:13 -06007558 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007559 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7560 gp_ci.stageCount = 2;
7561 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007562 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007563 // Not setting VP state w/o dynamic vp state should cause validation error
7564 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007565 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007566 gp_ci.pVertexInputState = &vi_ci;
7567 gp_ci.pInputAssemblyState = &ia_ci;
7568 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007569 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7570 gp_ci.layout = pipeline_layout;
7571 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007572
7573 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007574 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007575
7576 VkPipeline pipeline;
7577 VkPipelineCache pipelineCache;
7578
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007579 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007580 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007581 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007582
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007583 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007584
Chia-I Wuf7458c52015-10-26 21:10:41 +08007585 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7586 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7587 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7588 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007589}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007590
7591// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7592// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007593TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7594 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007595
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007597
Tobin Ehlise68360f2015-10-01 11:15:13 -06007598 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007599
7600 if (!m_device->phy().features().multiViewport) {
7601 printf("Device does not support multiple viewports/scissors; skipped.\n");
7602 return;
7603 }
7604
Tobin Ehlise68360f2015-10-01 11:15:13 -06007605 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007606
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007607 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007608 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7609 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007610
7611 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007612 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7613 ds_pool_ci.maxSets = 1;
7614 ds_pool_ci.poolSizeCount = 1;
7615 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007616
7617 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007618 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007619 ASSERT_VK_SUCCESS(err);
7620
7621 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007622 dsl_binding.binding = 0;
7623 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7624 dsl_binding.descriptorCount = 1;
7625 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007626
7627 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007628 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7629 ds_layout_ci.bindingCount = 1;
7630 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007631
7632 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007633 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007634 ASSERT_VK_SUCCESS(err);
7635
7636 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007637 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007638 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007639 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007640 alloc_info.descriptorPool = ds_pool;
7641 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007642 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007643 ASSERT_VK_SUCCESS(err);
7644
7645 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007646 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7647 pipeline_layout_ci.setLayoutCount = 1;
7648 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007649
7650 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007651 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007652 ASSERT_VK_SUCCESS(err);
7653
7654 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007655 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7656 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007657 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007658 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007659 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007660
7661 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7662 // Set scissor as dynamic to avoid that error
7663 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007664 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7665 dyn_state_ci.dynamicStateCount = 1;
7666 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007667
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007668 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7669 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7670 pipe_ms_state_ci.pNext = NULL;
7671 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7672 pipe_ms_state_ci.sampleShadingEnable = 0;
7673 pipe_ms_state_ci.minSampleShading = 1.0;
7674 pipe_ms_state_ci.pSampleMask = NULL;
7675
Cody Northropeb3a6c12015-10-05 14:44:45 -06007676 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007677 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007678
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007679 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007680 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7681 // 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 +08007682 shaderStages[0] = vs.GetStageCreateInfo();
7683 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007684
Cody Northropf6622dc2015-10-06 10:33:21 -06007685 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7686 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7687 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007688 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007689 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007690 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007691 vi_ci.pVertexAttributeDescriptions = nullptr;
7692
7693 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7694 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7695 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7696
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007697 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007698 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007699 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007700 rs_ci.pNext = nullptr;
7701
Mark Youngc89c6312016-03-31 16:03:20 -06007702 VkPipelineColorBlendAttachmentState att = {};
7703 att.blendEnable = VK_FALSE;
7704 att.colorWriteMask = 0xf;
7705
Cody Northropf6622dc2015-10-06 10:33:21 -06007706 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7707 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7708 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007709 cb_ci.attachmentCount = 1;
7710 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007711
Tobin Ehlise68360f2015-10-01 11:15:13 -06007712 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007713 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7714 gp_ci.stageCount = 2;
7715 gp_ci.pStages = shaderStages;
7716 gp_ci.pVertexInputState = &vi_ci;
7717 gp_ci.pInputAssemblyState = &ia_ci;
7718 gp_ci.pViewportState = &vp_state_ci;
7719 gp_ci.pRasterizationState = &rs_ci;
7720 gp_ci.pColorBlendState = &cb_ci;
7721 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007722 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007723 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7724 gp_ci.layout = pipeline_layout;
7725 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007726
7727 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007728 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007729
7730 VkPipeline pipeline;
7731 VkPipelineCache pipelineCache;
7732
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007733 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007734 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007735 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007736
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007737 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007738
Tobin Ehlisd332f282015-10-02 11:00:56 -06007739 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007740 // First need to successfully create the PSO from above by setting
7741 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007742 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 -07007743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007744 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07007745 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007746 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007747 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007748 m_commandBuffer->BeginCommandBuffer();
7749 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007750 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007751 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007752 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007753 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007754 Draw(1, 0, 0, 0);
7755
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007756 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007757
7758 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7759 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7760 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7761 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007762 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007763}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007764
7765// 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 -07007766// viewportCount
7767TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7768 VkResult err;
7769
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007771
7772 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007773
7774 if (!m_device->phy().features().multiViewport) {
7775 printf("Device does not support multiple viewports/scissors; skipped.\n");
7776 return;
7777 }
7778
Karl Schultz6addd812016-02-02 17:17:23 -07007779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7780
7781 VkDescriptorPoolSize ds_type_count = {};
7782 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7783 ds_type_count.descriptorCount = 1;
7784
7785 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7786 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7787 ds_pool_ci.maxSets = 1;
7788 ds_pool_ci.poolSizeCount = 1;
7789 ds_pool_ci.pPoolSizes = &ds_type_count;
7790
7791 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007792 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007793 ASSERT_VK_SUCCESS(err);
7794
7795 VkDescriptorSetLayoutBinding dsl_binding = {};
7796 dsl_binding.binding = 0;
7797 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7798 dsl_binding.descriptorCount = 1;
7799 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7800
7801 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7802 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7803 ds_layout_ci.bindingCount = 1;
7804 ds_layout_ci.pBindings = &dsl_binding;
7805
7806 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007807 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007808 ASSERT_VK_SUCCESS(err);
7809
7810 VkDescriptorSet descriptorSet;
7811 VkDescriptorSetAllocateInfo alloc_info = {};
7812 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7813 alloc_info.descriptorSetCount = 1;
7814 alloc_info.descriptorPool = ds_pool;
7815 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007816 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007817 ASSERT_VK_SUCCESS(err);
7818
7819 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7820 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7821 pipeline_layout_ci.setLayoutCount = 1;
7822 pipeline_layout_ci.pSetLayouts = &ds_layout;
7823
7824 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007825 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007826 ASSERT_VK_SUCCESS(err);
7827
7828 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7829 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7830 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007831 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007832 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007833 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007834
7835 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7836 // Set scissor as dynamic to avoid that error
7837 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7838 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7839 dyn_state_ci.dynamicStateCount = 1;
7840 dyn_state_ci.pDynamicStates = &vp_state;
7841
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007842 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7843 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7844 pipe_ms_state_ci.pNext = NULL;
7845 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7846 pipe_ms_state_ci.sampleShadingEnable = 0;
7847 pipe_ms_state_ci.minSampleShading = 1.0;
7848 pipe_ms_state_ci.pSampleMask = NULL;
7849
Karl Schultz6addd812016-02-02 17:17:23 -07007850 VkPipelineShaderStageCreateInfo shaderStages[2];
7851 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7852
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007853 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007854 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7855 // 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 -07007856 shaderStages[0] = vs.GetStageCreateInfo();
7857 shaderStages[1] = fs.GetStageCreateInfo();
7858
7859 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7860 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7861 vi_ci.pNext = nullptr;
7862 vi_ci.vertexBindingDescriptionCount = 0;
7863 vi_ci.pVertexBindingDescriptions = nullptr;
7864 vi_ci.vertexAttributeDescriptionCount = 0;
7865 vi_ci.pVertexAttributeDescriptions = nullptr;
7866
7867 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7868 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7869 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7870
7871 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7872 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007873 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007874 rs_ci.pNext = nullptr;
7875
Mark Youngc89c6312016-03-31 16:03:20 -06007876 VkPipelineColorBlendAttachmentState att = {};
7877 att.blendEnable = VK_FALSE;
7878 att.colorWriteMask = 0xf;
7879
Karl Schultz6addd812016-02-02 17:17:23 -07007880 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7881 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7882 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007883 cb_ci.attachmentCount = 1;
7884 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007885
7886 VkGraphicsPipelineCreateInfo gp_ci = {};
7887 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7888 gp_ci.stageCount = 2;
7889 gp_ci.pStages = shaderStages;
7890 gp_ci.pVertexInputState = &vi_ci;
7891 gp_ci.pInputAssemblyState = &ia_ci;
7892 gp_ci.pViewportState = &vp_state_ci;
7893 gp_ci.pRasterizationState = &rs_ci;
7894 gp_ci.pColorBlendState = &cb_ci;
7895 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007896 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007897 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7898 gp_ci.layout = pipeline_layout;
7899 gp_ci.renderPass = renderPass();
7900
7901 VkPipelineCacheCreateInfo pc_ci = {};
7902 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7903
7904 VkPipeline pipeline;
7905 VkPipelineCache pipelineCache;
7906
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007907 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007908 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007909 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007910
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007911 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007912
7913 // Now hit second fail case where we set scissor w/ different count than PSO
7914 // First need to successfully create the PSO from above by setting
7915 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7917 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007918
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007919 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06007920 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007922 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007923 m_commandBuffer->BeginCommandBuffer();
7924 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007925 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007926 VkViewport viewports[1] = {};
7927 viewports[0].width = 8;
7928 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007929 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007930 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007931 Draw(1, 0, 0, 0);
7932
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007933 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007934
Chia-I Wuf7458c52015-10-26 21:10:41 +08007935 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7936 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7937 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7938 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007939 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007940}
7941
Mark Young7394fdd2016-03-31 14:56:43 -06007942TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7943 VkResult err;
7944
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007946
7947 ASSERT_NO_FATAL_FAILURE(InitState());
7948 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7949
7950 VkDescriptorPoolSize ds_type_count = {};
7951 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7952 ds_type_count.descriptorCount = 1;
7953
7954 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7955 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7956 ds_pool_ci.maxSets = 1;
7957 ds_pool_ci.poolSizeCount = 1;
7958 ds_pool_ci.pPoolSizes = &ds_type_count;
7959
7960 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007961 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007962 ASSERT_VK_SUCCESS(err);
7963
7964 VkDescriptorSetLayoutBinding dsl_binding = {};
7965 dsl_binding.binding = 0;
7966 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7967 dsl_binding.descriptorCount = 1;
7968 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7969
7970 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7971 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7972 ds_layout_ci.bindingCount = 1;
7973 ds_layout_ci.pBindings = &dsl_binding;
7974
7975 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007977 ASSERT_VK_SUCCESS(err);
7978
7979 VkDescriptorSet descriptorSet;
7980 VkDescriptorSetAllocateInfo alloc_info = {};
7981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7982 alloc_info.descriptorSetCount = 1;
7983 alloc_info.descriptorPool = ds_pool;
7984 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007986 ASSERT_VK_SUCCESS(err);
7987
7988 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7989 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7990 pipeline_layout_ci.setLayoutCount = 1;
7991 pipeline_layout_ci.pSetLayouts = &ds_layout;
7992
7993 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007994 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007995 ASSERT_VK_SUCCESS(err);
7996
7997 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7998 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7999 vp_state_ci.scissorCount = 1;
8000 vp_state_ci.pScissors = NULL;
8001 vp_state_ci.viewportCount = 1;
8002 vp_state_ci.pViewports = NULL;
8003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008004 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008005 // Set scissor as dynamic to avoid that error
8006 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8007 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8008 dyn_state_ci.dynamicStateCount = 2;
8009 dyn_state_ci.pDynamicStates = dynamic_states;
8010
8011 VkPipelineShaderStageCreateInfo shaderStages[2];
8012 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8013
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008014 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8015 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008016 this); // TODO - We shouldn't need a fragment shader
8017 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008018 shaderStages[0] = vs.GetStageCreateInfo();
8019 shaderStages[1] = fs.GetStageCreateInfo();
8020
8021 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8022 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8023 vi_ci.pNext = nullptr;
8024 vi_ci.vertexBindingDescriptionCount = 0;
8025 vi_ci.pVertexBindingDescriptions = nullptr;
8026 vi_ci.vertexAttributeDescriptionCount = 0;
8027 vi_ci.pVertexAttributeDescriptions = nullptr;
8028
8029 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8030 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8031 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8032
8033 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8034 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8035 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008036 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008037
Mark Young47107952016-05-02 15:59:55 -06008038 // Check too low (line width of -1.0f).
8039 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008040
8041 VkPipelineColorBlendAttachmentState att = {};
8042 att.blendEnable = VK_FALSE;
8043 att.colorWriteMask = 0xf;
8044
8045 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8046 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8047 cb_ci.pNext = nullptr;
8048 cb_ci.attachmentCount = 1;
8049 cb_ci.pAttachments = &att;
8050
8051 VkGraphicsPipelineCreateInfo gp_ci = {};
8052 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8053 gp_ci.stageCount = 2;
8054 gp_ci.pStages = shaderStages;
8055 gp_ci.pVertexInputState = &vi_ci;
8056 gp_ci.pInputAssemblyState = &ia_ci;
8057 gp_ci.pViewportState = &vp_state_ci;
8058 gp_ci.pRasterizationState = &rs_ci;
8059 gp_ci.pColorBlendState = &cb_ci;
8060 gp_ci.pDynamicState = &dyn_state_ci;
8061 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8062 gp_ci.layout = pipeline_layout;
8063 gp_ci.renderPass = renderPass();
8064
8065 VkPipelineCacheCreateInfo pc_ci = {};
8066 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8067
8068 VkPipeline pipeline;
8069 VkPipelineCache pipelineCache;
8070
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008071 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008072 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008073 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008074
8075 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008076 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008077
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008079
8080 // Check too high (line width of 65536.0f).
8081 rs_ci.lineWidth = 65536.0f;
8082
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008083 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008084 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008085 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008086
8087 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008088 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008089
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008091
8092 dyn_state_ci.dynamicStateCount = 3;
8093
8094 rs_ci.lineWidth = 1.0f;
8095
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008096 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008097 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008098 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008099 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008100 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008101
8102 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008103 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008104 m_errorMonitor->VerifyFound();
8105
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008107
8108 // Check too high with dynamic setting.
8109 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8110 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008111 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008112
8113 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8114 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8115 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8116 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008117 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008118}
8119
Karl Schultz6addd812016-02-02 17:17:23 -07008120TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008121 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008123 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008124
8125 ASSERT_NO_FATAL_FAILURE(InitState());
8126 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008127
Tony Barbour552f6c02016-12-21 14:34:07 -07008128 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008129 // Don't care about RenderPass handle b/c error should be flagged before
8130 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008131 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008132
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008133 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008134}
8135
Karl Schultz6addd812016-02-02 17:17:23 -07008136TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008137 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8139 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008140
8141 ASSERT_NO_FATAL_FAILURE(InitState());
8142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008143
Tony Barbour552f6c02016-12-21 14:34:07 -07008144 m_commandBuffer->BeginCommandBuffer();
8145 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008146 // Just create a dummy Renderpass that's non-NULL so we can get to the
8147 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008148 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008149
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008150 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008151}
8152
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008153TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008154 TEST_DESCRIPTION(
8155 "Begin a renderPass where clearValueCount is less than"
8156 "the number of renderPass attachments that use loadOp"
8157 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008158
8159 ASSERT_NO_FATAL_FAILURE(InitState());
8160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8161
8162 // Create a renderPass with a single attachment that uses loadOp CLEAR
8163 VkAttachmentReference attach = {};
8164 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8165 VkSubpassDescription subpass = {};
8166 subpass.inputAttachmentCount = 1;
8167 subpass.pInputAttachments = &attach;
8168 VkRenderPassCreateInfo rpci = {};
8169 rpci.subpassCount = 1;
8170 rpci.pSubpasses = &subpass;
8171 rpci.attachmentCount = 1;
8172 VkAttachmentDescription attach_desc = {};
8173 attach_desc.format = VK_FORMAT_UNDEFINED;
8174 // Set loadOp to CLEAR
8175 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8176 rpci.pAttachments = &attach_desc;
8177 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8178 VkRenderPass rp;
8179 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8180
8181 VkCommandBufferInheritanceInfo hinfo = {};
8182 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8183 hinfo.renderPass = VK_NULL_HANDLE;
8184 hinfo.subpass = 0;
8185 hinfo.framebuffer = VK_NULL_HANDLE;
8186 hinfo.occlusionQueryEnable = VK_FALSE;
8187 hinfo.queryFlags = 0;
8188 hinfo.pipelineStatistics = 0;
8189 VkCommandBufferBeginInfo info = {};
8190 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8191 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8192 info.pInheritanceInfo = &hinfo;
8193
8194 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8195 VkRenderPassBeginInfo rp_begin = {};
8196 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8197 rp_begin.pNext = NULL;
8198 rp_begin.renderPass = renderPass();
8199 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008200 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008201
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008204 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008205
8206 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008207
8208 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008209}
8210
Slawomir Cygan0808f392016-11-28 17:53:23 +01008211TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008212 TEST_DESCRIPTION(
8213 "Begin a renderPass where clearValueCount is greater than"
8214 "the number of renderPass attachments that use loadOp"
8215 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008216
8217 ASSERT_NO_FATAL_FAILURE(InitState());
8218 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8219
8220 // Create a renderPass with a single attachment that uses loadOp CLEAR
8221 VkAttachmentReference attach = {};
8222 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8223 VkSubpassDescription subpass = {};
8224 subpass.inputAttachmentCount = 1;
8225 subpass.pInputAttachments = &attach;
8226 VkRenderPassCreateInfo rpci = {};
8227 rpci.subpassCount = 1;
8228 rpci.pSubpasses = &subpass;
8229 rpci.attachmentCount = 1;
8230 VkAttachmentDescription attach_desc = {};
8231 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8232 // Set loadOp to CLEAR
8233 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8234 rpci.pAttachments = &attach_desc;
8235 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8236 VkRenderPass rp;
8237 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8238
8239 VkCommandBufferBeginInfo info = {};
8240 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8241 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8242
8243 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8244 VkRenderPassBeginInfo rp_begin = {};
8245 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8246 rp_begin.pNext = NULL;
8247 rp_begin.renderPass = renderPass();
8248 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008249 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008250
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8252 " has a clearValueCount of"
8253 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008254
8255 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8256
8257 m_errorMonitor->VerifyFound();
8258
8259 vkDestroyRenderPass(m_device->device(), rp, NULL);
8260}
8261
Cody Northrop3bb4d962016-05-09 16:15:57 -06008262TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008263 TEST_DESCRIPTION("End a command buffer with an active render pass");
8264
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8266 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008267
8268 ASSERT_NO_FATAL_FAILURE(InitState());
8269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8270
Tony Barbour552f6c02016-12-21 14:34:07 -07008271 m_commandBuffer->BeginCommandBuffer();
8272 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8273 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008274
8275 m_errorMonitor->VerifyFound();
8276
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008277 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8278 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008279}
8280
Karl Schultz6addd812016-02-02 17:17:23 -07008281TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008282 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8284 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008285
8286 ASSERT_NO_FATAL_FAILURE(InitState());
8287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008288
Tony Barbour552f6c02016-12-21 14:34:07 -07008289 m_commandBuffer->BeginCommandBuffer();
8290 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008291
8292 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008293 vk_testing::Buffer dstBuffer;
8294 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008295
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008296 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008297
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008298 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008299}
8300
Karl Schultz6addd812016-02-02 17:17:23 -07008301TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008302 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8304 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008305
8306 ASSERT_NO_FATAL_FAILURE(InitState());
8307 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008308
Tony Barbour552f6c02016-12-21 14:34:07 -07008309 m_commandBuffer->BeginCommandBuffer();
8310 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008311
8312 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008313 vk_testing::Buffer dstBuffer;
8314 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008315
Karl Schultz6addd812016-02-02 17:17:23 -07008316 VkDeviceSize dstOffset = 0;
8317 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008318 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008319
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008320 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008321
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008322 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008323}
8324
Karl Schultz6addd812016-02-02 17:17:23 -07008325TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008326 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8328 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008329
8330 ASSERT_NO_FATAL_FAILURE(InitState());
8331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008332
Tony Barbour552f6c02016-12-21 14:34:07 -07008333 m_commandBuffer->BeginCommandBuffer();
8334 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008335
Michael Lentine0a369f62016-02-03 16:51:46 -06008336 VkClearColorValue clear_color;
8337 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008338 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8339 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8340 const int32_t tex_width = 32;
8341 const int32_t tex_height = 32;
8342 VkImageCreateInfo image_create_info = {};
8343 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8344 image_create_info.pNext = NULL;
8345 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8346 image_create_info.format = tex_format;
8347 image_create_info.extent.width = tex_width;
8348 image_create_info.extent.height = tex_height;
8349 image_create_info.extent.depth = 1;
8350 image_create_info.mipLevels = 1;
8351 image_create_info.arrayLayers = 1;
8352 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8353 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8354 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008355
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008356 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008357 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008358
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008359 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008361 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008362
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008363 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008364}
8365
Karl Schultz6addd812016-02-02 17:17:23 -07008366TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008367 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8369 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008370
8371 ASSERT_NO_FATAL_FAILURE(InitState());
8372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008373
Tony Barbour552f6c02016-12-21 14:34:07 -07008374 m_commandBuffer->BeginCommandBuffer();
8375 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008376
8377 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008378 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008379 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8380 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8381 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8382 image_create_info.extent.width = 64;
8383 image_create_info.extent.height = 64;
8384 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8385 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008386
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008387 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008388 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008389
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008390 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008391
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008392 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8393 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008394
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008395 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008396}
8397
Karl Schultz6addd812016-02-02 17:17:23 -07008398TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008399 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008400 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008401
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8403 "vkCmdClearAttachments(): This call "
8404 "must be issued inside an active "
8405 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008406
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008407 ASSERT_NO_FATAL_FAILURE(InitState());
8408 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008409
8410 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008411 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008412 ASSERT_VK_SUCCESS(err);
8413
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008414 VkClearAttachment color_attachment;
8415 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8416 color_attachment.clearValue.color.float32[0] = 0;
8417 color_attachment.clearValue.color.float32[1] = 0;
8418 color_attachment.clearValue.color.float32[2] = 0;
8419 color_attachment.clearValue.color.float32[3] = 0;
8420 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008421 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008422 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008423
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008424 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008425}
8426
Chris Forbes3b97e932016-09-07 11:29:24 +12008427TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008428 TEST_DESCRIPTION(
8429 "Test that an error is produced when CmdNextSubpass is "
8430 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008431
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8433 "vkCmdNextSubpass(): Attempted to advance "
8434 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008435
8436 ASSERT_NO_FATAL_FAILURE(InitState());
8437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8438
Tony Barbour552f6c02016-12-21 14:34:07 -07008439 m_commandBuffer->BeginCommandBuffer();
8440 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008441
8442 // error here.
8443 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8444 m_errorMonitor->VerifyFound();
8445
Tony Barbour552f6c02016-12-21 14:34:07 -07008446 m_commandBuffer->EndRenderPass();
8447 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008448}
8449
Chris Forbes6d624702016-09-07 13:57:05 +12008450TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008451 TEST_DESCRIPTION(
8452 "Test that an error is produced when CmdEndRenderPass is "
8453 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008454
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8456 "vkCmdEndRenderPass(): Called before reaching "
8457 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008458
8459 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008460 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8461 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008462
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008463 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008464
8465 VkRenderPass rp;
8466 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8467 ASSERT_VK_SUCCESS(err);
8468
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008470
8471 VkFramebuffer fb;
8472 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8473 ASSERT_VK_SUCCESS(err);
8474
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008475 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008476
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008477 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 +12008478
8479 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8480
8481 // Error here.
8482 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8483 m_errorMonitor->VerifyFound();
8484
8485 // Clean up.
8486 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8487 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8488}
8489
Karl Schultz9e66a292016-04-21 15:57:51 -06008490TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8491 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8493 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008494
8495 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008496 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008497
8498 VkBufferMemoryBarrier buf_barrier = {};
8499 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8500 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8501 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8502 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8503 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8504 buf_barrier.buffer = VK_NULL_HANDLE;
8505 buf_barrier.offset = 0;
8506 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008507 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8508 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008509
8510 m_errorMonitor->VerifyFound();
8511}
8512
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008513TEST_F(VkLayerTest, InvalidBarriers) {
8514 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8515
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008517
8518 ASSERT_NO_FATAL_FAILURE(InitState());
8519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8520
8521 VkMemoryBarrier mem_barrier = {};
8522 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8523 mem_barrier.pNext = NULL;
8524 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8525 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008526 m_commandBuffer->BeginCommandBuffer();
8527 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008528 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008530 &mem_barrier, 0, nullptr, 0, nullptr);
8531 m_errorMonitor->VerifyFound();
8532
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008534 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008535 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 -06008536 ASSERT_TRUE(image.initialized());
8537 VkImageMemoryBarrier img_barrier = {};
8538 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8539 img_barrier.pNext = NULL;
8540 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8541 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8542 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8543 // New layout can't be UNDEFINED
8544 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8545 img_barrier.image = image.handle();
8546 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8547 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8548 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8549 img_barrier.subresourceRange.baseArrayLayer = 0;
8550 img_barrier.subresourceRange.baseMipLevel = 0;
8551 img_barrier.subresourceRange.layerCount = 1;
8552 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008553 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8554 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008555 m_errorMonitor->VerifyFound();
8556 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8557
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8559 "Subresource must have the sum of the "
8560 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008561 // baseArrayLayer + layerCount must be <= image's arrayLayers
8562 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008563 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8564 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008565 m_errorMonitor->VerifyFound();
8566 img_barrier.subresourceRange.baseArrayLayer = 0;
8567
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008569 // baseMipLevel + levelCount must be <= image's mipLevels
8570 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008571 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8572 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008573 m_errorMonitor->VerifyFound();
8574 img_barrier.subresourceRange.baseMipLevel = 0;
8575
Mike Weiblen7053aa32017-01-25 15:21:10 -07008576 // levelCount must be non-zero.
8577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8578 img_barrier.subresourceRange.levelCount = 0;
8579 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8580 nullptr, 0, nullptr, 1, &img_barrier);
8581 m_errorMonitor->VerifyFound();
8582 img_barrier.subresourceRange.levelCount = 1;
8583
8584 // layerCount must be non-zero.
8585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8586 img_barrier.subresourceRange.layerCount = 0;
8587 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8588 nullptr, 0, nullptr, 1, &img_barrier);
8589 m_errorMonitor->VerifyFound();
8590 img_barrier.subresourceRange.layerCount = 1;
8591
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008592 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 -06008593 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008594 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8595 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008596 VkBufferMemoryBarrier buf_barrier = {};
8597 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8598 buf_barrier.pNext = NULL;
8599 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8600 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8601 buf_barrier.buffer = buffer.handle();
8602 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8603 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8604 buf_barrier.offset = 0;
8605 buf_barrier.size = VK_WHOLE_SIZE;
8606 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008607 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8608 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008609 m_errorMonitor->VerifyFound();
8610 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8611
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008613 buf_barrier.offset = 257;
8614 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008615 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8616 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008617 m_errorMonitor->VerifyFound();
8618 buf_barrier.offset = 0;
8619
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008621 buf_barrier.size = 257;
8622 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008623 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8624 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008625 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008626
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008627 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008628 m_errorMonitor->SetDesiredFailureMsg(
8629 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008630 "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 -06008631 VkDepthStencilObj ds_image(m_device);
8632 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8633 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008634 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8635 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008636 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008637
8638 // Not having DEPTH or STENCIL set is an error
8639 img_barrier.subresourceRange.aspectMask = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008640 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8641 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008642 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07008643
8644 // Having anything other than DEPTH or STENCIL is an error
8645 m_errorMonitor->SetDesiredFailureMsg(
8646 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8647 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8648 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
8649 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8650 nullptr, 0, nullptr, 1, &img_barrier);
8651 m_errorMonitor->VerifyFound();
8652
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008653 // Now test depth-only
8654 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008655 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8656 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008657 VkDepthStencilObj d_image(m_device);
8658 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8659 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008660 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008661 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008662 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008663
8664 // DEPTH bit must be set
8665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8666 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8667 img_barrier.subresourceRange.aspectMask = 0;
8668 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8669 0, nullptr, 0, nullptr, 1, &img_barrier);
8670 m_errorMonitor->VerifyFound();
8671
8672 // No bits other than DEPTH may be set
8673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8674 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8675 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008676 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8677 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008678 m_errorMonitor->VerifyFound();
8679 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008680
8681 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008682 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8683 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8685 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008686 VkDepthStencilObj s_image(m_device);
8687 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8688 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008689 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008690 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008691 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008692 // Use of COLOR aspect on depth image is error
8693 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8695 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008696 m_errorMonitor->VerifyFound();
8697 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008698
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008699 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008700 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008701 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 -06008702 ASSERT_TRUE(c_image.initialized());
8703 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8704 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8705 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008706
8707 // COLOR bit must be set
8708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8709 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8710 img_barrier.subresourceRange.aspectMask = 0;
8711 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8712 nullptr, 0, nullptr, 1, &img_barrier);
8713 m_errorMonitor->VerifyFound();
8714
8715 // No bits other than COLOR may be set
8716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8717 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
8718 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008719 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8720 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008721 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008722
8723 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8724
8725 // Create command pool with incompatible queueflags
8726 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8727 uint32_t queue_family_index = UINT32_MAX;
8728 for (uint32_t i = 0; i < queue_props.size(); i++) {
8729 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8730 queue_family_index = i;
8731 break;
8732 }
8733 }
8734 if (queue_family_index == UINT32_MAX) {
8735 printf("No non-compute queue found; skipped.\n");
8736 return;
8737 }
8738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8739
8740 VkCommandPool command_pool;
8741 VkCommandPoolCreateInfo pool_create_info{};
8742 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8743 pool_create_info.queueFamilyIndex = queue_family_index;
8744 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8745 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8746
8747 // Allocate a command buffer
8748 VkCommandBuffer bad_command_buffer;
8749 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8750 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8751 command_buffer_allocate_info.commandPool = command_pool;
8752 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8753 command_buffer_allocate_info.commandBufferCount = 1;
8754 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8755
8756 VkCommandBufferBeginInfo cbbi = {};
8757 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8758 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8759 buf_barrier.offset = 0;
8760 buf_barrier.size = VK_WHOLE_SIZE;
8761 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8762 &buf_barrier, 0, nullptr);
8763 m_errorMonitor->VerifyFound();
8764
8765 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8766 vkEndCommandBuffer(bad_command_buffer);
8767 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8768 printf("The non-compute queue does not support graphics; skipped.\n");
8769 return;
8770 }
8771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8772 VkEvent event;
8773 VkEventCreateInfo event_create_info{};
8774 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8775 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8776 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8777 nullptr, 0, nullptr);
8778 m_errorMonitor->VerifyFound();
8779
8780 vkEndCommandBuffer(bad_command_buffer);
8781 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008782}
8783
Tony Barbour18ba25c2016-09-29 13:42:40 -06008784TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8785 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8786
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06008788 ASSERT_NO_FATAL_FAILURE(InitState());
8789 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008790 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 -06008791 ASSERT_TRUE(image.initialized());
8792
8793 VkImageMemoryBarrier barrier = {};
8794 VkImageSubresourceRange range;
8795 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8796 barrier.srcAccessMask = 0;
8797 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8798 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8799 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8800 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8801 barrier.image = image.handle();
8802 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8803 range.baseMipLevel = 0;
8804 range.levelCount = 1;
8805 range.baseArrayLayer = 0;
8806 range.layerCount = 1;
8807 barrier.subresourceRange = range;
8808 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8809 cmdbuf.BeginCommandBuffer();
8810 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8811 &barrier);
8812 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8813 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8814 barrier.srcAccessMask = 0;
8815 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8816 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8817 &barrier);
8818
8819 m_errorMonitor->VerifyFound();
8820}
8821
Karl Schultz6addd812016-02-02 17:17:23 -07008822TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008823 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008824 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008825
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008827
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008828 ASSERT_NO_FATAL_FAILURE(InitState());
8829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008830 uint32_t qfi = 0;
8831 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008832 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8833 buffCI.size = 1024;
8834 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8835 buffCI.queueFamilyIndexCount = 1;
8836 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008837
8838 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008839 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008840 ASSERT_VK_SUCCESS(err);
8841
Tony Barbour552f6c02016-12-21 14:34:07 -07008842 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008843 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008844 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8845 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008846 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008847 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008848
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008849 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008850
Chia-I Wuf7458c52015-10-26 21:10:41 +08008851 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008852}
8853
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008854TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8855 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8857 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8858 "of the indices specified when the device was created, via the "
8859 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008860
8861 ASSERT_NO_FATAL_FAILURE(InitState());
8862 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8863 VkBufferCreateInfo buffCI = {};
8864 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8865 buffCI.size = 1024;
8866 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8867 buffCI.queueFamilyIndexCount = 1;
8868 // Introduce failure by specifying invalid queue_family_index
8869 uint32_t qfi = 777;
8870 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008871 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008872
8873 VkBuffer ib;
8874 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8875
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008876 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008877 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008878}
8879
Karl Schultz6addd812016-02-02 17:17:23 -07008880TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008881 TEST_DESCRIPTION(
8882 "Attempt vkCmdExecuteCommands with a primary command buffer"
8883 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008884
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008885 ASSERT_NO_FATAL_FAILURE(InitState());
8886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008887
Chris Forbesf29a84f2016-10-06 18:39:28 +13008888 // An empty primary command buffer
8889 VkCommandBufferObj cb(m_device, m_commandPool);
8890 cb.BeginCommandBuffer();
8891 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008892
Chris Forbesf29a84f2016-10-06 18:39:28 +13008893 m_commandBuffer->BeginCommandBuffer();
8894 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8895 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008896
Chris Forbesf29a84f2016-10-06 18:39:28 +13008897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8898 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008899 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008900}
8901
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008902TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008903 TEST_DESCRIPTION(
8904 "Attempt to update descriptor sets for images and buffers "
8905 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008906 VkResult err;
8907
8908 ASSERT_NO_FATAL_FAILURE(InitState());
8909 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8910 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8911 ds_type_count[i].type = VkDescriptorType(i);
8912 ds_type_count[i].descriptorCount = 1;
8913 }
8914 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8915 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8916 ds_pool_ci.pNext = NULL;
8917 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8918 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8919 ds_pool_ci.pPoolSizes = ds_type_count;
8920
8921 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008922 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008923 ASSERT_VK_SUCCESS(err);
8924
8925 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008926 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008927 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8928 dsl_binding[i].binding = 0;
8929 dsl_binding[i].descriptorType = VkDescriptorType(i);
8930 dsl_binding[i].descriptorCount = 1;
8931 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8932 dsl_binding[i].pImmutableSamplers = NULL;
8933 }
8934
8935 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8936 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8937 ds_layout_ci.pNext = NULL;
8938 ds_layout_ci.bindingCount = 1;
8939 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8940 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8941 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008942 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008943 ASSERT_VK_SUCCESS(err);
8944 }
8945 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8946 VkDescriptorSetAllocateInfo alloc_info = {};
8947 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8948 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8949 alloc_info.descriptorPool = ds_pool;
8950 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008951 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008952 ASSERT_VK_SUCCESS(err);
8953
8954 // Create a buffer & bufferView to be used for invalid updates
8955 VkBufferCreateInfo buff_ci = {};
8956 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07008957 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008958 buff_ci.size = 256;
8959 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07008960 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008961 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8962 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07008963
8964 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
8965 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
8966 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
8967 ASSERT_VK_SUCCESS(err);
8968
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008969 VkMemoryRequirements mem_reqs;
8970 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8971 VkMemoryAllocateInfo mem_alloc_info = {};
8972 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8973 mem_alloc_info.pNext = NULL;
8974 mem_alloc_info.memoryTypeIndex = 0;
8975 mem_alloc_info.allocationSize = mem_reqs.size;
8976 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8977 if (!pass) {
8978 vkDestroyBuffer(m_device->device(), buffer, NULL);
8979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8980 return;
8981 }
8982 VkDeviceMemory mem;
8983 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
8984 ASSERT_VK_SUCCESS(err);
8985 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8986 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008987
8988 VkBufferViewCreateInfo buff_view_ci = {};
8989 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8990 buff_view_ci.buffer = buffer;
8991 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8992 buff_view_ci.range = VK_WHOLE_SIZE;
8993 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008994 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008995 ASSERT_VK_SUCCESS(err);
8996
Tony Barbour415497c2017-01-24 10:06:09 -07008997 // Now get resources / view for storage_texel_buffer
8998 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
8999 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9000 if (!pass) {
9001 vkDestroyBuffer(m_device->device(), buffer, NULL);
9002 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9003 vkFreeMemory(m_device->device(), mem, NULL);
9004 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9005 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9006 return;
9007 }
9008 VkDeviceMemory storage_texel_buffer_mem;
9009 VkBufferView storage_texel_buffer_view;
9010 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9011 ASSERT_VK_SUCCESS(err);
9012 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9013 ASSERT_VK_SUCCESS(err);
9014 buff_view_ci.buffer = storage_texel_buffer;
9015 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9016 ASSERT_VK_SUCCESS(err);
9017
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009018 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009019 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009020 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009021 image_ci.format = VK_FORMAT_UNDEFINED;
9022 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9023 VkFormat format = static_cast<VkFormat>(f);
9024 VkFormatProperties fProps = m_device->format_properties(format);
9025 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9026 image_ci.format = format;
9027 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9028 break;
9029 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9030 image_ci.format = format;
9031 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9032 break;
9033 }
9034 }
9035 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9036 return;
9037 }
9038
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009039 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9040 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009041 image_ci.extent.width = 64;
9042 image_ci.extent.height = 64;
9043 image_ci.extent.depth = 1;
9044 image_ci.mipLevels = 1;
9045 image_ci.arrayLayers = 1;
9046 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009047 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009048 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009049 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9050 VkImage image;
9051 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9052 ASSERT_VK_SUCCESS(err);
9053 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009054 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009055
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009056 VkMemoryAllocateInfo mem_alloc = {};
9057 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9058 mem_alloc.pNext = NULL;
9059 mem_alloc.allocationSize = 0;
9060 mem_alloc.memoryTypeIndex = 0;
9061 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9062 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009063 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009064 ASSERT_TRUE(pass);
9065 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9066 ASSERT_VK_SUCCESS(err);
9067 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9068 ASSERT_VK_SUCCESS(err);
9069 // Now create view for image
9070 VkImageViewCreateInfo image_view_ci = {};
9071 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9072 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009073 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009074 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9075 image_view_ci.subresourceRange.layerCount = 1;
9076 image_view_ci.subresourceRange.baseArrayLayer = 0;
9077 image_view_ci.subresourceRange.levelCount = 1;
9078 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9079 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009080 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009081 ASSERT_VK_SUCCESS(err);
9082
9083 VkDescriptorBufferInfo buff_info = {};
9084 buff_info.buffer = buffer;
9085 VkDescriptorImageInfo img_info = {};
9086 img_info.imageView = image_view;
9087 VkWriteDescriptorSet descriptor_write = {};
9088 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9089 descriptor_write.dstBinding = 0;
9090 descriptor_write.descriptorCount = 1;
9091 descriptor_write.pTexelBufferView = &buff_view;
9092 descriptor_write.pBufferInfo = &buff_info;
9093 descriptor_write.pImageInfo = &img_info;
9094
9095 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009096 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009097 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9098 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9099 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9100 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9101 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9102 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9103 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9104 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9105 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9106 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9107 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009108 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009109 // Start loop at 1 as SAMPLER desc type has no usage bit error
9110 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009111 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9112 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9113 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9114 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009115 descriptor_write.descriptorType = VkDescriptorType(i);
9116 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009118
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009119 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009120
9121 m_errorMonitor->VerifyFound();
9122 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009123 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9124 descriptor_write.pTexelBufferView = &buff_view;
9125 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009126 }
Tony Barbour415497c2017-01-24 10:06:09 -07009127
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009128 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9129 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009130 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009131 vkDestroyImageView(m_device->device(), image_view, NULL);
9132 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009133 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009134 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009135 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009136 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009137 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009138 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9139}
9140
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009141TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009142 TEST_DESCRIPTION(
9143 "Attempt to update buffer descriptor set that has incorrect "
9144 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9145 "1. offset value greater than buffer size\n"
9146 "2. range value of 0\n"
9147 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009148 VkResult err;
9149
9150 ASSERT_NO_FATAL_FAILURE(InitState());
9151 VkDescriptorPoolSize ds_type_count = {};
9152 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9153 ds_type_count.descriptorCount = 1;
9154
9155 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9156 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9157 ds_pool_ci.pNext = NULL;
9158 ds_pool_ci.maxSets = 1;
9159 ds_pool_ci.poolSizeCount = 1;
9160 ds_pool_ci.pPoolSizes = &ds_type_count;
9161
9162 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009163 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009164 ASSERT_VK_SUCCESS(err);
9165
9166 // Create layout with single uniform buffer descriptor
9167 VkDescriptorSetLayoutBinding dsl_binding = {};
9168 dsl_binding.binding = 0;
9169 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9170 dsl_binding.descriptorCount = 1;
9171 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9172 dsl_binding.pImmutableSamplers = NULL;
9173
9174 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9175 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9176 ds_layout_ci.pNext = NULL;
9177 ds_layout_ci.bindingCount = 1;
9178 ds_layout_ci.pBindings = &dsl_binding;
9179 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009180 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009181 ASSERT_VK_SUCCESS(err);
9182
9183 VkDescriptorSet descriptor_set = {};
9184 VkDescriptorSetAllocateInfo alloc_info = {};
9185 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9186 alloc_info.descriptorSetCount = 1;
9187 alloc_info.descriptorPool = ds_pool;
9188 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009189 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009190 ASSERT_VK_SUCCESS(err);
9191
9192 // Create a buffer to be used for invalid updates
9193 VkBufferCreateInfo buff_ci = {};
9194 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9195 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9196 buff_ci.size = 256;
9197 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9198 VkBuffer buffer;
9199 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9200 ASSERT_VK_SUCCESS(err);
9201 // Have to bind memory to buffer before descriptor update
9202 VkMemoryAllocateInfo mem_alloc = {};
9203 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9204 mem_alloc.pNext = NULL;
9205 mem_alloc.allocationSize = 256;
9206 mem_alloc.memoryTypeIndex = 0;
9207
9208 VkMemoryRequirements mem_reqs;
9209 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009210 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009211 if (!pass) {
9212 vkDestroyBuffer(m_device->device(), buffer, NULL);
9213 return;
9214 }
9215
9216 VkDeviceMemory mem;
9217 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9218 ASSERT_VK_SUCCESS(err);
9219 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9220 ASSERT_VK_SUCCESS(err);
9221
9222 VkDescriptorBufferInfo buff_info = {};
9223 buff_info.buffer = buffer;
9224 // First make offset 1 larger than buffer size
9225 buff_info.offset = 257;
9226 buff_info.range = VK_WHOLE_SIZE;
9227 VkWriteDescriptorSet descriptor_write = {};
9228 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9229 descriptor_write.dstBinding = 0;
9230 descriptor_write.descriptorCount = 1;
9231 descriptor_write.pTexelBufferView = nullptr;
9232 descriptor_write.pBufferInfo = &buff_info;
9233 descriptor_write.pImageInfo = nullptr;
9234
9235 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9236 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009238
9239 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9240
9241 m_errorMonitor->VerifyFound();
9242 // Now cause error due to range of 0
9243 buff_info.offset = 0;
9244 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009246
9247 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9248
9249 m_errorMonitor->VerifyFound();
9250 // Now cause error due to range exceeding buffer size - offset
9251 buff_info.offset = 128;
9252 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009254
9255 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9256
9257 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009258 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009259 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9260 vkDestroyBuffer(m_device->device(), buffer, NULL);
9261 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9262 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9263}
9264
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009265TEST_F(VkLayerTest, DSAspectBitsErrors) {
9266 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9267 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009268 TEST_DESCRIPTION(
9269 "Attempt to update descriptor sets for images "
9270 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009271 VkResult err;
9272
9273 ASSERT_NO_FATAL_FAILURE(InitState());
9274 VkDescriptorPoolSize ds_type_count = {};
9275 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9276 ds_type_count.descriptorCount = 1;
9277
9278 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9279 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9280 ds_pool_ci.pNext = NULL;
9281 ds_pool_ci.maxSets = 5;
9282 ds_pool_ci.poolSizeCount = 1;
9283 ds_pool_ci.pPoolSizes = &ds_type_count;
9284
9285 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009286 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009287 ASSERT_VK_SUCCESS(err);
9288
9289 VkDescriptorSetLayoutBinding dsl_binding = {};
9290 dsl_binding.binding = 0;
9291 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9292 dsl_binding.descriptorCount = 1;
9293 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9294 dsl_binding.pImmutableSamplers = NULL;
9295
9296 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9297 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9298 ds_layout_ci.pNext = NULL;
9299 ds_layout_ci.bindingCount = 1;
9300 ds_layout_ci.pBindings = &dsl_binding;
9301 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009302 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009303 ASSERT_VK_SUCCESS(err);
9304
9305 VkDescriptorSet descriptor_set = {};
9306 VkDescriptorSetAllocateInfo alloc_info = {};
9307 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9308 alloc_info.descriptorSetCount = 1;
9309 alloc_info.descriptorPool = ds_pool;
9310 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009311 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009312 ASSERT_VK_SUCCESS(err);
9313
9314 // Create an image to be used for invalid updates
9315 VkImageCreateInfo image_ci = {};
9316 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9317 image_ci.imageType = VK_IMAGE_TYPE_2D;
9318 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9319 image_ci.extent.width = 64;
9320 image_ci.extent.height = 64;
9321 image_ci.extent.depth = 1;
9322 image_ci.mipLevels = 1;
9323 image_ci.arrayLayers = 1;
9324 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9325 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9326 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9327 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9328 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9329 VkImage image;
9330 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9331 ASSERT_VK_SUCCESS(err);
9332 // Bind memory to image
9333 VkMemoryRequirements mem_reqs;
9334 VkDeviceMemory image_mem;
9335 bool pass;
9336 VkMemoryAllocateInfo mem_alloc = {};
9337 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9338 mem_alloc.pNext = NULL;
9339 mem_alloc.allocationSize = 0;
9340 mem_alloc.memoryTypeIndex = 0;
9341 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9342 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009343 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009344 ASSERT_TRUE(pass);
9345 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9346 ASSERT_VK_SUCCESS(err);
9347 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9348 ASSERT_VK_SUCCESS(err);
9349 // Now create view for image
9350 VkImageViewCreateInfo image_view_ci = {};
9351 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9352 image_view_ci.image = image;
9353 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9354 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9355 image_view_ci.subresourceRange.layerCount = 1;
9356 image_view_ci.subresourceRange.baseArrayLayer = 0;
9357 image_view_ci.subresourceRange.levelCount = 1;
9358 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009359 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009360
9361 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009362 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009363 ASSERT_VK_SUCCESS(err);
9364
9365 VkDescriptorImageInfo img_info = {};
9366 img_info.imageView = image_view;
9367 VkWriteDescriptorSet descriptor_write = {};
9368 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9369 descriptor_write.dstBinding = 0;
9370 descriptor_write.descriptorCount = 1;
9371 descriptor_write.pTexelBufferView = NULL;
9372 descriptor_write.pBufferInfo = NULL;
9373 descriptor_write.pImageInfo = &img_info;
9374 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9375 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009376 const char *error_msg =
9377 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9378 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009380
9381 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9382
9383 m_errorMonitor->VerifyFound();
9384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9385 vkDestroyImage(m_device->device(), image, NULL);
9386 vkFreeMemory(m_device->device(), image_mem, NULL);
9387 vkDestroyImageView(m_device->device(), image_view, NULL);
9388 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9389 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9390}
9391
Karl Schultz6addd812016-02-02 17:17:23 -07009392TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009393 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009394 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009395
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9397 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9398 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009399
Tobin Ehlis3b780662015-05-28 12:11:26 -06009400 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009401 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009402 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009403 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9404 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009405
9406 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009407 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9408 ds_pool_ci.pNext = NULL;
9409 ds_pool_ci.maxSets = 1;
9410 ds_pool_ci.poolSizeCount = 1;
9411 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009412
Tobin Ehlis3b780662015-05-28 12:11:26 -06009413 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009414 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009415 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009416 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009417 dsl_binding.binding = 0;
9418 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9419 dsl_binding.descriptorCount = 1;
9420 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9421 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009422
Tony Barboureb254902015-07-15 12:50:33 -06009423 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009424 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9425 ds_layout_ci.pNext = NULL;
9426 ds_layout_ci.bindingCount = 1;
9427 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009428
Tobin Ehlis3b780662015-05-28 12:11:26 -06009429 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009430 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009431 ASSERT_VK_SUCCESS(err);
9432
9433 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009434 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009435 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009436 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009437 alloc_info.descriptorPool = ds_pool;
9438 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009439 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009440 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009441
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009442 VkSamplerCreateInfo sampler_ci = {};
9443 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9444 sampler_ci.pNext = NULL;
9445 sampler_ci.magFilter = VK_FILTER_NEAREST;
9446 sampler_ci.minFilter = VK_FILTER_NEAREST;
9447 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9448 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9449 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9450 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9451 sampler_ci.mipLodBias = 1.0;
9452 sampler_ci.anisotropyEnable = VK_FALSE;
9453 sampler_ci.maxAnisotropy = 1;
9454 sampler_ci.compareEnable = VK_FALSE;
9455 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9456 sampler_ci.minLod = 1.0;
9457 sampler_ci.maxLod = 1.0;
9458 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9459 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9460 VkSampler sampler;
9461 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9462 ASSERT_VK_SUCCESS(err);
9463
9464 VkDescriptorImageInfo info = {};
9465 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009466
9467 VkWriteDescriptorSet descriptor_write;
9468 memset(&descriptor_write, 0, sizeof(descriptor_write));
9469 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009470 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009471 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009472 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009473 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009474 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009475
9476 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9477
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009478 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009479
Chia-I Wuf7458c52015-10-26 21:10:41 +08009480 vkDestroySampler(m_device->device(), sampler, NULL);
9481 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9482 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009483}
9484
Karl Schultz6addd812016-02-02 17:17:23 -07009485TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009486 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009487 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009488
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009490
Tobin Ehlis3b780662015-05-28 12:11:26 -06009491 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009492 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009493 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009494 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9495 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009496
9497 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009498 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9499 ds_pool_ci.pNext = NULL;
9500 ds_pool_ci.maxSets = 1;
9501 ds_pool_ci.poolSizeCount = 1;
9502 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009503
Tobin Ehlis3b780662015-05-28 12:11:26 -06009504 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009505 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009506 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009507
Tony Barboureb254902015-07-15 12:50:33 -06009508 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009509 dsl_binding.binding = 0;
9510 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9511 dsl_binding.descriptorCount = 1;
9512 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9513 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009514
9515 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009516 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9517 ds_layout_ci.pNext = NULL;
9518 ds_layout_ci.bindingCount = 1;
9519 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009520
Tobin Ehlis3b780662015-05-28 12:11:26 -06009521 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009522 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009523 ASSERT_VK_SUCCESS(err);
9524
9525 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009526 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009527 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009528 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009529 alloc_info.descriptorPool = ds_pool;
9530 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009531 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009532 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009533
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009534 // Correctly update descriptor to avoid "NOT_UPDATED" error
9535 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009536 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009537 buff_info.offset = 0;
9538 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009539
9540 VkWriteDescriptorSet descriptor_write;
9541 memset(&descriptor_write, 0, sizeof(descriptor_write));
9542 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009543 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009544 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009545 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009546 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9547 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009548
9549 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9550
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009551 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009552
Chia-I Wuf7458c52015-10-26 21:10:41 +08009553 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9554 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009555}
9556
Karl Schultz6addd812016-02-02 17:17:23 -07009557TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009558 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009559 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009560
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009562
Tobin Ehlis3b780662015-05-28 12:11:26 -06009563 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009564 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009565 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009566 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9567 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009568
9569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9571 ds_pool_ci.pNext = NULL;
9572 ds_pool_ci.maxSets = 1;
9573 ds_pool_ci.poolSizeCount = 1;
9574 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009575
Tobin Ehlis3b780662015-05-28 12:11:26 -06009576 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009577 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009578 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009579
Tony Barboureb254902015-07-15 12:50:33 -06009580 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009581 dsl_binding.binding = 0;
9582 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9583 dsl_binding.descriptorCount = 1;
9584 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9585 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009586
9587 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009588 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9589 ds_layout_ci.pNext = NULL;
9590 ds_layout_ci.bindingCount = 1;
9591 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009592 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009593 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009594 ASSERT_VK_SUCCESS(err);
9595
9596 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009597 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009598 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009599 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009600 alloc_info.descriptorPool = ds_pool;
9601 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009602 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009603 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009604
Tony Barboureb254902015-07-15 12:50:33 -06009605 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009606 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9607 sampler_ci.pNext = NULL;
9608 sampler_ci.magFilter = VK_FILTER_NEAREST;
9609 sampler_ci.minFilter = VK_FILTER_NEAREST;
9610 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9611 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9612 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9613 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9614 sampler_ci.mipLodBias = 1.0;
9615 sampler_ci.anisotropyEnable = VK_FALSE;
9616 sampler_ci.maxAnisotropy = 1;
9617 sampler_ci.compareEnable = VK_FALSE;
9618 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9619 sampler_ci.minLod = 1.0;
9620 sampler_ci.maxLod = 1.0;
9621 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9622 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009623
Tobin Ehlis3b780662015-05-28 12:11:26 -06009624 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009625 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009626 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009627
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009628 VkDescriptorImageInfo info = {};
9629 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009630
9631 VkWriteDescriptorSet descriptor_write;
9632 memset(&descriptor_write, 0, sizeof(descriptor_write));
9633 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009634 descriptor_write.dstSet = descriptorSet;
9635 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009636 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009637 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009638 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009639 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009640
9641 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9642
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009643 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009644
Chia-I Wuf7458c52015-10-26 21:10:41 +08009645 vkDestroySampler(m_device->device(), sampler, NULL);
9646 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9647 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009648}
9649
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009650TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9651 // Create layout w/ empty binding and attempt to update it
9652 VkResult err;
9653
9654 ASSERT_NO_FATAL_FAILURE(InitState());
9655
9656 VkDescriptorPoolSize ds_type_count = {};
9657 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9658 ds_type_count.descriptorCount = 1;
9659
9660 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9661 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9662 ds_pool_ci.pNext = NULL;
9663 ds_pool_ci.maxSets = 1;
9664 ds_pool_ci.poolSizeCount = 1;
9665 ds_pool_ci.pPoolSizes = &ds_type_count;
9666
9667 VkDescriptorPool ds_pool;
9668 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9669 ASSERT_VK_SUCCESS(err);
9670
9671 VkDescriptorSetLayoutBinding dsl_binding = {};
9672 dsl_binding.binding = 0;
9673 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9674 dsl_binding.descriptorCount = 0;
9675 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9676 dsl_binding.pImmutableSamplers = NULL;
9677
9678 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9679 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9680 ds_layout_ci.pNext = NULL;
9681 ds_layout_ci.bindingCount = 1;
9682 ds_layout_ci.pBindings = &dsl_binding;
9683 VkDescriptorSetLayout ds_layout;
9684 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9685 ASSERT_VK_SUCCESS(err);
9686
9687 VkDescriptorSet descriptor_set;
9688 VkDescriptorSetAllocateInfo alloc_info = {};
9689 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9690 alloc_info.descriptorSetCount = 1;
9691 alloc_info.descriptorPool = ds_pool;
9692 alloc_info.pSetLayouts = &ds_layout;
9693 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9694 ASSERT_VK_SUCCESS(err);
9695
9696 VkSamplerCreateInfo sampler_ci = {};
9697 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9698 sampler_ci.magFilter = VK_FILTER_NEAREST;
9699 sampler_ci.minFilter = VK_FILTER_NEAREST;
9700 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9701 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9702 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9703 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9704 sampler_ci.mipLodBias = 1.0;
9705 sampler_ci.maxAnisotropy = 1;
9706 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9707 sampler_ci.minLod = 1.0;
9708 sampler_ci.maxLod = 1.0;
9709 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9710
9711 VkSampler sampler;
9712 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9713 ASSERT_VK_SUCCESS(err);
9714
9715 VkDescriptorImageInfo info = {};
9716 info.sampler = sampler;
9717
9718 VkWriteDescriptorSet descriptor_write;
9719 memset(&descriptor_write, 0, sizeof(descriptor_write));
9720 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9721 descriptor_write.dstSet = descriptor_set;
9722 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009723 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009724 // This is the wrong type, but empty binding error will be flagged first
9725 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9726 descriptor_write.pImageInfo = &info;
9727
9728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9729 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9730 m_errorMonitor->VerifyFound();
9731
9732 vkDestroySampler(m_device->device(), sampler, NULL);
9733 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9734 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9735}
9736
Karl Schultz6addd812016-02-02 17:17:23 -07009737TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9738 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9739 // types
9740 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009741
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 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 -06009743
Tobin Ehlis3b780662015-05-28 12:11:26 -06009744 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009745
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009746 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009747 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9748 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009749
9750 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009751 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9752 ds_pool_ci.pNext = NULL;
9753 ds_pool_ci.maxSets = 1;
9754 ds_pool_ci.poolSizeCount = 1;
9755 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009756
Tobin Ehlis3b780662015-05-28 12:11:26 -06009757 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009758 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009759 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009760 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009761 dsl_binding.binding = 0;
9762 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9763 dsl_binding.descriptorCount = 1;
9764 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9765 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009766
Tony Barboureb254902015-07-15 12:50:33 -06009767 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009768 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9769 ds_layout_ci.pNext = NULL;
9770 ds_layout_ci.bindingCount = 1;
9771 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009772
Tobin Ehlis3b780662015-05-28 12:11:26 -06009773 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009774 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009775 ASSERT_VK_SUCCESS(err);
9776
9777 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009778 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009779 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009780 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009781 alloc_info.descriptorPool = ds_pool;
9782 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009783 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009784 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009785
Tony Barboureb254902015-07-15 12:50:33 -06009786 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009787 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9788 sampler_ci.pNext = NULL;
9789 sampler_ci.magFilter = VK_FILTER_NEAREST;
9790 sampler_ci.minFilter = VK_FILTER_NEAREST;
9791 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9792 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9793 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9794 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9795 sampler_ci.mipLodBias = 1.0;
9796 sampler_ci.anisotropyEnable = VK_FALSE;
9797 sampler_ci.maxAnisotropy = 1;
9798 sampler_ci.compareEnable = VK_FALSE;
9799 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9800 sampler_ci.minLod = 1.0;
9801 sampler_ci.maxLod = 1.0;
9802 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9803 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009804 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009805 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009806 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009807
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009808 VkDescriptorImageInfo info = {};
9809 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009810
9811 VkWriteDescriptorSet descriptor_write;
9812 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009813 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009814 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009815 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009816 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009817 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009818 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009819
9820 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9821
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009822 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009823
Chia-I Wuf7458c52015-10-26 21:10:41 +08009824 vkDestroySampler(m_device->device(), sampler, NULL);
9825 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9826 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009827}
9828
Karl Schultz6addd812016-02-02 17:17:23 -07009829TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009830 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009831 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009832
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009834
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009835 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009836 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9837 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009838 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009839 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9840 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009841
9842 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009843 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9844 ds_pool_ci.pNext = NULL;
9845 ds_pool_ci.maxSets = 1;
9846 ds_pool_ci.poolSizeCount = 1;
9847 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009848
9849 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009850 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009851 ASSERT_VK_SUCCESS(err);
9852
9853 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009854 dsl_binding.binding = 0;
9855 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9856 dsl_binding.descriptorCount = 1;
9857 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9858 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009859
9860 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009861 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9862 ds_layout_ci.pNext = NULL;
9863 ds_layout_ci.bindingCount = 1;
9864 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009865 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009867 ASSERT_VK_SUCCESS(err);
9868
9869 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009870 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009871 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009872 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009873 alloc_info.descriptorPool = ds_pool;
9874 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009875 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009876 ASSERT_VK_SUCCESS(err);
9877
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009878 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009879
9880 VkDescriptorImageInfo descriptor_info;
9881 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9882 descriptor_info.sampler = sampler;
9883
9884 VkWriteDescriptorSet descriptor_write;
9885 memset(&descriptor_write, 0, sizeof(descriptor_write));
9886 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009887 descriptor_write.dstSet = descriptorSet;
9888 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009889 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009890 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9891 descriptor_write.pImageInfo = &descriptor_info;
9892
9893 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9894
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009895 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009896
Chia-I Wuf7458c52015-10-26 21:10:41 +08009897 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9898 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009899}
9900
Karl Schultz6addd812016-02-02 17:17:23 -07009901TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9902 // Create a single combined Image/Sampler descriptor and send it an invalid
9903 // imageView
9904 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009905
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009907
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009908 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009909 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009910 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9911 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009912
9913 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009914 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9915 ds_pool_ci.pNext = NULL;
9916 ds_pool_ci.maxSets = 1;
9917 ds_pool_ci.poolSizeCount = 1;
9918 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009919
9920 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009921 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009922 ASSERT_VK_SUCCESS(err);
9923
9924 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009925 dsl_binding.binding = 0;
9926 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9927 dsl_binding.descriptorCount = 1;
9928 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9929 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009930
9931 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009932 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9933 ds_layout_ci.pNext = NULL;
9934 ds_layout_ci.bindingCount = 1;
9935 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009936 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009937 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009938 ASSERT_VK_SUCCESS(err);
9939
9940 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009941 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009942 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009943 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009944 alloc_info.descriptorPool = ds_pool;
9945 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009946 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009947 ASSERT_VK_SUCCESS(err);
9948
9949 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009950 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9951 sampler_ci.pNext = NULL;
9952 sampler_ci.magFilter = VK_FILTER_NEAREST;
9953 sampler_ci.minFilter = VK_FILTER_NEAREST;
9954 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9955 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9956 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9957 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9958 sampler_ci.mipLodBias = 1.0;
9959 sampler_ci.anisotropyEnable = VK_FALSE;
9960 sampler_ci.maxAnisotropy = 1;
9961 sampler_ci.compareEnable = VK_FALSE;
9962 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9963 sampler_ci.minLod = 1.0;
9964 sampler_ci.maxLod = 1.0;
9965 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9966 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009967
9968 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009969 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009970 ASSERT_VK_SUCCESS(err);
9971
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009972 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009973
9974 VkDescriptorImageInfo descriptor_info;
9975 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9976 descriptor_info.sampler = sampler;
9977 descriptor_info.imageView = view;
9978
9979 VkWriteDescriptorSet descriptor_write;
9980 memset(&descriptor_write, 0, sizeof(descriptor_write));
9981 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009982 descriptor_write.dstSet = descriptorSet;
9983 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009984 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009985 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9986 descriptor_write.pImageInfo = &descriptor_info;
9987
9988 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9989
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009990 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009991
Chia-I Wuf7458c52015-10-26 21:10:41 +08009992 vkDestroySampler(m_device->device(), sampler, NULL);
9993 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9994 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009995}
9996
Karl Schultz6addd812016-02-02 17:17:23 -07009997TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9998 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9999 // into the other
10000 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010001
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10003 " binding #1 with type "
10004 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10005 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010006
Tobin Ehlis04356f92015-10-27 16:35:27 -060010007 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010008 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010009 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010010 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10011 ds_type_count[0].descriptorCount = 1;
10012 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10013 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010014
10015 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010016 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10017 ds_pool_ci.pNext = NULL;
10018 ds_pool_ci.maxSets = 1;
10019 ds_pool_ci.poolSizeCount = 2;
10020 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010021
10022 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010023 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010024 ASSERT_VK_SUCCESS(err);
10025 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010026 dsl_binding[0].binding = 0;
10027 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10028 dsl_binding[0].descriptorCount = 1;
10029 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10030 dsl_binding[0].pImmutableSamplers = NULL;
10031 dsl_binding[1].binding = 1;
10032 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10033 dsl_binding[1].descriptorCount = 1;
10034 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10035 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010036
10037 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010038 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10039 ds_layout_ci.pNext = NULL;
10040 ds_layout_ci.bindingCount = 2;
10041 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010042
10043 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010044 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010045 ASSERT_VK_SUCCESS(err);
10046
10047 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010048 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010049 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010050 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010051 alloc_info.descriptorPool = ds_pool;
10052 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010053 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010054 ASSERT_VK_SUCCESS(err);
10055
10056 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010057 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10058 sampler_ci.pNext = NULL;
10059 sampler_ci.magFilter = VK_FILTER_NEAREST;
10060 sampler_ci.minFilter = VK_FILTER_NEAREST;
10061 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10062 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10063 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10064 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10065 sampler_ci.mipLodBias = 1.0;
10066 sampler_ci.anisotropyEnable = VK_FALSE;
10067 sampler_ci.maxAnisotropy = 1;
10068 sampler_ci.compareEnable = VK_FALSE;
10069 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10070 sampler_ci.minLod = 1.0;
10071 sampler_ci.maxLod = 1.0;
10072 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10073 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010074
10075 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010076 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010077 ASSERT_VK_SUCCESS(err);
10078
10079 VkDescriptorImageInfo info = {};
10080 info.sampler = sampler;
10081
10082 VkWriteDescriptorSet descriptor_write;
10083 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10084 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010085 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010086 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010087 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010088 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10089 descriptor_write.pImageInfo = &info;
10090 // This write update should succeed
10091 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10092 // Now perform a copy update that fails due to type mismatch
10093 VkCopyDescriptorSet copy_ds_update;
10094 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10095 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10096 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010097 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010098 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010099 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10100 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010101 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10102
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010103 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010104 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 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 -060010106 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10107 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10108 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010109 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010110 copy_ds_update.dstSet = descriptorSet;
10111 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010112 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010113 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10114
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010115 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010116
Tobin Ehlis04356f92015-10-27 16:35:27 -060010117 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10119 " binding#1 with offset index of 1 plus "
10120 "update array offset of 0 and update of "
10121 "5 descriptors oversteps total number "
10122 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010123
Tobin Ehlis04356f92015-10-27 16:35:27 -060010124 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10125 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10126 copy_ds_update.srcSet = descriptorSet;
10127 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010128 copy_ds_update.dstSet = descriptorSet;
10129 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010130 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010131 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10132
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010133 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010134
Chia-I Wuf7458c52015-10-26 21:10:41 +080010135 vkDestroySampler(m_device->device(), sampler, NULL);
10136 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10137 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010138}
10139
Karl Schultz6addd812016-02-02 17:17:23 -070010140TEST_F(VkLayerTest, NumSamplesMismatch) {
10141 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10142 // sampleCount
10143 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010144
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010146
Tobin Ehlis3b780662015-05-28 12:11:26 -060010147 ASSERT_NO_FATAL_FAILURE(InitState());
10148 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010149 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010150 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010151 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010152
10153 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010154 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10155 ds_pool_ci.pNext = NULL;
10156 ds_pool_ci.maxSets = 1;
10157 ds_pool_ci.poolSizeCount = 1;
10158 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010159
Tobin Ehlis3b780662015-05-28 12:11:26 -060010160 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010161 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010162 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010163
Tony Barboureb254902015-07-15 12:50:33 -060010164 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010165 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010166 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010167 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010168 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10169 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010170
Tony Barboureb254902015-07-15 12:50:33 -060010171 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10172 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10173 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010174 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010175 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010176
Tobin Ehlis3b780662015-05-28 12:11:26 -060010177 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010178 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010179 ASSERT_VK_SUCCESS(err);
10180
10181 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010182 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010183 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010184 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010185 alloc_info.descriptorPool = ds_pool;
10186 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010187 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010188 ASSERT_VK_SUCCESS(err);
10189
Tony Barboureb254902015-07-15 12:50:33 -060010190 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010191 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010192 pipe_ms_state_ci.pNext = NULL;
10193 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10194 pipe_ms_state_ci.sampleShadingEnable = 0;
10195 pipe_ms_state_ci.minSampleShading = 1.0;
10196 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010197
Tony Barboureb254902015-07-15 12:50:33 -060010198 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010199 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10200 pipeline_layout_ci.pNext = NULL;
10201 pipeline_layout_ci.setLayoutCount = 1;
10202 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010203
10204 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010205 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010206 ASSERT_VK_SUCCESS(err);
10207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010209 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 -060010210 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010211 VkPipelineObj pipe(m_device);
10212 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010213 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010214 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010215 pipe.SetMSAA(&pipe_ms_state_ci);
10216 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010217
Tony Barbour552f6c02016-12-21 14:34:07 -070010218 m_commandBuffer->BeginCommandBuffer();
10219 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010220 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010221
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010222 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10223 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10224 VkRect2D scissor = {{0, 0}, {16, 16}};
10225 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10226
Mark Young29927482016-05-04 14:38:51 -060010227 // Render triangle (the error should trigger on the attempt to draw).
10228 Draw(3, 1, 0, 0);
10229
10230 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010231 m_commandBuffer->EndRenderPass();
10232 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010233
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010234 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010235
Chia-I Wuf7458c52015-10-26 21:10:41 +080010236 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10237 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10238 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010239}
Mark Young29927482016-05-04 14:38:51 -060010240
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010241TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010242 TEST_DESCRIPTION(
10243 "Hit RenderPass incompatible cases. "
10244 "Initial case is drawing with an active renderpass that's "
10245 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010246 VkResult err;
10247
10248 ASSERT_NO_FATAL_FAILURE(InitState());
10249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10250
10251 VkDescriptorSetLayoutBinding dsl_binding = {};
10252 dsl_binding.binding = 0;
10253 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10254 dsl_binding.descriptorCount = 1;
10255 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10256 dsl_binding.pImmutableSamplers = NULL;
10257
10258 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10259 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10260 ds_layout_ci.pNext = NULL;
10261 ds_layout_ci.bindingCount = 1;
10262 ds_layout_ci.pBindings = &dsl_binding;
10263
10264 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010265 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010266 ASSERT_VK_SUCCESS(err);
10267
10268 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10269 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10270 pipeline_layout_ci.pNext = NULL;
10271 pipeline_layout_ci.setLayoutCount = 1;
10272 pipeline_layout_ci.pSetLayouts = &ds_layout;
10273
10274 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010275 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010276 ASSERT_VK_SUCCESS(err);
10277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010278 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010279 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 -060010280 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010281 // Create a renderpass that will be incompatible with default renderpass
10282 VkAttachmentReference attach = {};
10283 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10284 VkAttachmentReference color_att = {};
10285 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10286 VkSubpassDescription subpass = {};
10287 subpass.inputAttachmentCount = 1;
10288 subpass.pInputAttachments = &attach;
10289 subpass.colorAttachmentCount = 1;
10290 subpass.pColorAttachments = &color_att;
10291 VkRenderPassCreateInfo rpci = {};
10292 rpci.subpassCount = 1;
10293 rpci.pSubpasses = &subpass;
10294 rpci.attachmentCount = 1;
10295 VkAttachmentDescription attach_desc = {};
10296 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010297 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10298 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010299 rpci.pAttachments = &attach_desc;
10300 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10301 VkRenderPass rp;
10302 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10303 VkPipelineObj pipe(m_device);
10304 pipe.AddShader(&vs);
10305 pipe.AddShader(&fs);
10306 pipe.AddColorAttachment();
10307 VkViewport view_port = {};
10308 m_viewports.push_back(view_port);
10309 pipe.SetViewport(m_viewports);
10310 VkRect2D rect = {};
10311 m_scissors.push_back(rect);
10312 pipe.SetScissor(m_scissors);
10313 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10314
10315 VkCommandBufferInheritanceInfo cbii = {};
10316 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10317 cbii.renderPass = rp;
10318 cbii.subpass = 0;
10319 VkCommandBufferBeginInfo cbbi = {};
10320 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10321 cbbi.pInheritanceInfo = &cbii;
10322 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10323 VkRenderPassBeginInfo rpbi = {};
10324 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10325 rpbi.framebuffer = m_framebuffer;
10326 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010327 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10328 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010331 // Render triangle (the error should trigger on the attempt to draw).
10332 Draw(3, 1, 0, 0);
10333
10334 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010335 m_commandBuffer->EndRenderPass();
10336 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010337
10338 m_errorMonitor->VerifyFound();
10339
10340 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10341 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10342 vkDestroyRenderPass(m_device->device(), rp, NULL);
10343}
10344
Mark Youngc89c6312016-03-31 16:03:20 -060010345TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10346 // Create Pipeline where the number of blend attachments doesn't match the
10347 // number of color attachments. In this case, we don't add any color
10348 // blend attachments even though we have a color attachment.
10349 VkResult err;
10350
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010352
10353 ASSERT_NO_FATAL_FAILURE(InitState());
10354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10355 VkDescriptorPoolSize ds_type_count = {};
10356 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10357 ds_type_count.descriptorCount = 1;
10358
10359 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10360 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10361 ds_pool_ci.pNext = NULL;
10362 ds_pool_ci.maxSets = 1;
10363 ds_pool_ci.poolSizeCount = 1;
10364 ds_pool_ci.pPoolSizes = &ds_type_count;
10365
10366 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010367 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010368 ASSERT_VK_SUCCESS(err);
10369
10370 VkDescriptorSetLayoutBinding dsl_binding = {};
10371 dsl_binding.binding = 0;
10372 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10373 dsl_binding.descriptorCount = 1;
10374 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10375 dsl_binding.pImmutableSamplers = NULL;
10376
10377 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10378 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10379 ds_layout_ci.pNext = NULL;
10380 ds_layout_ci.bindingCount = 1;
10381 ds_layout_ci.pBindings = &dsl_binding;
10382
10383 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010384 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010385 ASSERT_VK_SUCCESS(err);
10386
10387 VkDescriptorSet descriptorSet;
10388 VkDescriptorSetAllocateInfo alloc_info = {};
10389 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10390 alloc_info.descriptorSetCount = 1;
10391 alloc_info.descriptorPool = ds_pool;
10392 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010393 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010394 ASSERT_VK_SUCCESS(err);
10395
10396 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010397 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010398 pipe_ms_state_ci.pNext = NULL;
10399 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10400 pipe_ms_state_ci.sampleShadingEnable = 0;
10401 pipe_ms_state_ci.minSampleShading = 1.0;
10402 pipe_ms_state_ci.pSampleMask = NULL;
10403
10404 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10405 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10406 pipeline_layout_ci.pNext = NULL;
10407 pipeline_layout_ci.setLayoutCount = 1;
10408 pipeline_layout_ci.pSetLayouts = &ds_layout;
10409
10410 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010411 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010412 ASSERT_VK_SUCCESS(err);
10413
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010414 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010415 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 -060010416 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010417 VkPipelineObj pipe(m_device);
10418 pipe.AddShader(&vs);
10419 pipe.AddShader(&fs);
10420 pipe.SetMSAA(&pipe_ms_state_ci);
10421 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010422 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010423
10424 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10425 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10426 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10427}
Mark Young29927482016-05-04 14:38:51 -060010428
Mark Muellerd4914412016-06-13 17:52:06 -060010429TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010430 TEST_DESCRIPTION(
10431 "Points to a wrong colorAttachment index in a VkClearAttachment "
10432 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010433 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010435
10436 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10437 m_errorMonitor->VerifyFound();
10438}
10439
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010440TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010441 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10442 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010443
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010444 ASSERT_NO_FATAL_FAILURE(InitState());
10445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010446
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010447 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010448 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10449 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010450
10451 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010452 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10453 ds_pool_ci.pNext = NULL;
10454 ds_pool_ci.maxSets = 1;
10455 ds_pool_ci.poolSizeCount = 1;
10456 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010457
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010458 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010459 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010460 ASSERT_VK_SUCCESS(err);
10461
Tony Barboureb254902015-07-15 12:50:33 -060010462 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010463 dsl_binding.binding = 0;
10464 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10465 dsl_binding.descriptorCount = 1;
10466 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10467 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010468
Tony Barboureb254902015-07-15 12:50:33 -060010469 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010470 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10471 ds_layout_ci.pNext = NULL;
10472 ds_layout_ci.bindingCount = 1;
10473 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010474
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010475 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010476 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010477 ASSERT_VK_SUCCESS(err);
10478
10479 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010480 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010481 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010482 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010483 alloc_info.descriptorPool = ds_pool;
10484 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010485 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010486 ASSERT_VK_SUCCESS(err);
10487
Tony Barboureb254902015-07-15 12:50:33 -060010488 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010490 pipe_ms_state_ci.pNext = NULL;
10491 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10492 pipe_ms_state_ci.sampleShadingEnable = 0;
10493 pipe_ms_state_ci.minSampleShading = 1.0;
10494 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010495
Tony Barboureb254902015-07-15 12:50:33 -060010496 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010497 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10498 pipeline_layout_ci.pNext = NULL;
10499 pipeline_layout_ci.setLayoutCount = 1;
10500 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010501
10502 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010504 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010506 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010507 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010508 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010509 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010510
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010511 VkPipelineObj pipe(m_device);
10512 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010513 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010514 pipe.SetMSAA(&pipe_ms_state_ci);
10515 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010516
Tony Barbour552f6c02016-12-21 14:34:07 -070010517 m_commandBuffer->BeginCommandBuffer();
10518 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010519
Karl Schultz6addd812016-02-02 17:17:23 -070010520 // Main thing we care about for this test is that the VkImage obj we're
10521 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010522 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010523 VkClearAttachment color_attachment;
10524 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10525 color_attachment.clearValue.color.float32[0] = 1.0;
10526 color_attachment.clearValue.color.float32[1] = 1.0;
10527 color_attachment.clearValue.color.float32[2] = 1.0;
10528 color_attachment.clearValue.color.float32[3] = 1.0;
10529 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010530 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010531
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010532 // Call for full-sized FB Color attachment prior to issuing a Draw
10533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070010534 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010535 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010536 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010537
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010538 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10539 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10541 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10542 m_errorMonitor->VerifyFound();
10543
10544 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10545 clear_rect.layerCount = 2;
10546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10547 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010548 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010549
Chia-I Wuf7458c52015-10-26 21:10:41 +080010550 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10551 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10552 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010553}
10554
Karl Schultz6addd812016-02-02 17:17:23 -070010555TEST_F(VkLayerTest, VtxBufferBadIndex) {
10556 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010557
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10559 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010560
Tobin Ehlis502480b2015-06-24 15:53:07 -060010561 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010562 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010564
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010565 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010566 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10567 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010568
10569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10571 ds_pool_ci.pNext = NULL;
10572 ds_pool_ci.maxSets = 1;
10573 ds_pool_ci.poolSizeCount = 1;
10574 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010575
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010576 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010577 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010578 ASSERT_VK_SUCCESS(err);
10579
Tony Barboureb254902015-07-15 12:50:33 -060010580 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010581 dsl_binding.binding = 0;
10582 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10583 dsl_binding.descriptorCount = 1;
10584 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10585 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010586
Tony Barboureb254902015-07-15 12:50:33 -060010587 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010588 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10589 ds_layout_ci.pNext = NULL;
10590 ds_layout_ci.bindingCount = 1;
10591 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010592
Tobin Ehlis502480b2015-06-24 15:53:07 -060010593 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010594 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010595 ASSERT_VK_SUCCESS(err);
10596
10597 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010598 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010599 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010600 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010601 alloc_info.descriptorPool = ds_pool;
10602 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010604 ASSERT_VK_SUCCESS(err);
10605
Tony Barboureb254902015-07-15 12:50:33 -060010606 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010607 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010608 pipe_ms_state_ci.pNext = NULL;
10609 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10610 pipe_ms_state_ci.sampleShadingEnable = 0;
10611 pipe_ms_state_ci.minSampleShading = 1.0;
10612 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010613
Tony Barboureb254902015-07-15 12:50:33 -060010614 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010615 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10616 pipeline_layout_ci.pNext = NULL;
10617 pipeline_layout_ci.setLayoutCount = 1;
10618 pipeline_layout_ci.pSetLayouts = &ds_layout;
10619 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010620
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010621 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010622 ASSERT_VK_SUCCESS(err);
10623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010624 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010625 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 -060010626 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010627 VkPipelineObj pipe(m_device);
10628 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010629 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010630 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010631 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010632 pipe.SetViewport(m_viewports);
10633 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010634 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010635
Tony Barbour552f6c02016-12-21 14:34:07 -070010636 m_commandBuffer->BeginCommandBuffer();
10637 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010638 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010639 // Don't care about actual data, just need to get to draw to flag error
10640 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010641 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010642 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010643 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010644
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010645 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010646
Chia-I Wuf7458c52015-10-26 21:10:41 +080010647 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10648 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10649 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010650}
Mark Muellerdfe37552016-07-07 14:47:42 -060010651
Mark Mueller2ee294f2016-08-04 12:59:48 -060010652TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010653 TEST_DESCRIPTION(
10654 "Use an invalid count in a vkEnumeratePhysicalDevices call."
10655 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010656 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010657
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010658 const char *invalid_queueFamilyIndex_message =
10659 "Invalid queue create request in vkCreateDevice(). Invalid "
10660 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010662 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010663
Mark Mueller880fce52016-08-17 15:23:23 -060010664 // The following test fails with recent NVidia drivers.
10665 // By the time core_validation is reached, the NVidia
10666 // driver has sanitized the invalid condition and core_validation
10667 // is not introduced to the failure condition. This is not the case
10668 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010669 // uint32_t count = static_cast<uint32_t>(~0);
10670 // VkPhysicalDevice physical_device;
10671 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10672 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010673
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010675 float queue_priority = 0.0;
10676
10677 VkDeviceQueueCreateInfo queue_create_info = {};
10678 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10679 queue_create_info.queueCount = 1;
10680 queue_create_info.pQueuePriorities = &queue_priority;
10681 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10682
10683 VkPhysicalDeviceFeatures features = m_device->phy().features();
10684 VkDevice testDevice;
10685 VkDeviceCreateInfo device_create_info = {};
10686 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10687 device_create_info.queueCreateInfoCount = 1;
10688 device_create_info.pQueueCreateInfos = &queue_create_info;
10689 device_create_info.pEnabledFeatures = &features;
10690 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10691 m_errorMonitor->VerifyFound();
10692
10693 queue_create_info.queueFamilyIndex = 1;
10694
10695 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10696 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10697 for (unsigned i = 0; i < feature_count; i++) {
10698 if (VK_FALSE == feature_array[i]) {
10699 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010701 device_create_info.pEnabledFeatures = &features;
10702 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10703 m_errorMonitor->VerifyFound();
10704 break;
10705 }
10706 }
10707}
10708
Tobin Ehlis16edf082016-11-21 12:33:49 -070010709TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10710 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10711
10712 ASSERT_NO_FATAL_FAILURE(InitState());
10713
10714 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10715 std::vector<VkDeviceQueueCreateInfo> queue_info;
10716 queue_info.reserve(queue_props.size());
10717 std::vector<std::vector<float>> queue_priorities;
10718 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10719 VkDeviceQueueCreateInfo qi{};
10720 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10721 qi.queueFamilyIndex = i;
10722 qi.queueCount = queue_props[i].queueCount;
10723 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10724 qi.pQueuePriorities = queue_priorities[i].data();
10725 queue_info.push_back(qi);
10726 }
10727
10728 std::vector<const char *> device_extension_names;
10729
10730 VkDevice local_device;
10731 VkDeviceCreateInfo device_create_info = {};
10732 auto features = m_device->phy().features();
10733 // Intentionally disable pipeline stats
10734 features.pipelineStatisticsQuery = VK_FALSE;
10735 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10736 device_create_info.pNext = NULL;
10737 device_create_info.queueCreateInfoCount = queue_info.size();
10738 device_create_info.pQueueCreateInfos = queue_info.data();
10739 device_create_info.enabledLayerCount = 0;
10740 device_create_info.ppEnabledLayerNames = NULL;
10741 device_create_info.pEnabledFeatures = &features;
10742 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10743 ASSERT_VK_SUCCESS(err);
10744
10745 VkQueryPoolCreateInfo qpci{};
10746 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10747 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10748 qpci.queryCount = 1;
10749 VkQueryPool query_pool;
10750
10751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10752 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10753 m_errorMonitor->VerifyFound();
10754
10755 vkDestroyDevice(local_device, nullptr);
10756}
10757
Mark Mueller2ee294f2016-08-04 12:59:48 -060010758TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010759 TEST_DESCRIPTION(
10760 "Use an invalid queue index in a vkCmdWaitEvents call."
10761 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060010762
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010763 const char *invalid_queue_index =
10764 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10765 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10766 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010767
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010768 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010771
10772 ASSERT_NO_FATAL_FAILURE(InitState());
10773
10774 VkEvent event;
10775 VkEventCreateInfo event_create_info{};
10776 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10777 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10778
Mark Mueller2ee294f2016-08-04 12:59:48 -060010779 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010780 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010781
Tony Barbour552f6c02016-12-21 14:34:07 -070010782 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010783
10784 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010785 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 -060010786 ASSERT_TRUE(image.initialized());
10787 VkImageMemoryBarrier img_barrier = {};
10788 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10789 img_barrier.pNext = NULL;
10790 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10791 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10792 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10793 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10794 img_barrier.image = image.handle();
10795 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010796
10797 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10798 // that layer validation catches the case when it is not.
10799 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010800 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10801 img_barrier.subresourceRange.baseArrayLayer = 0;
10802 img_barrier.subresourceRange.baseMipLevel = 0;
10803 img_barrier.subresourceRange.layerCount = 1;
10804 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010805 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10806 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010807 m_errorMonitor->VerifyFound();
10808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010810
10811 VkQueryPool query_pool;
10812 VkQueryPoolCreateInfo query_pool_create_info = {};
10813 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10814 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10815 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010816 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010817
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010818 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010819 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10820
10821 vkEndCommandBuffer(m_commandBuffer->handle());
10822 m_errorMonitor->VerifyFound();
10823
10824 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10825 vkDestroyEvent(m_device->device(), event, nullptr);
10826}
10827
Mark Muellerdfe37552016-07-07 14:47:42 -060010828TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010829 TEST_DESCRIPTION(
10830 "Submit a command buffer using deleted vertex buffer, "
10831 "delete a buffer twice, use an invalid offset for each "
10832 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060010833
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010834 const char *deleted_buffer_in_command_buffer =
10835 "Cannot submit cmd buffer "
10836 "using deleted buffer ";
10837 const char *invalid_offset_message =
10838 "vkBindBufferMemory(): "
10839 "memoryOffset is 0x";
10840 const char *invalid_storage_buffer_offset_message =
10841 "vkBindBufferMemory(): "
10842 "storage memoryOffset "
10843 "is 0x";
10844 const char *invalid_texel_buffer_offset_message =
10845 "vkBindBufferMemory(): "
10846 "texel memoryOffset "
10847 "is 0x";
10848 const char *invalid_uniform_buffer_offset_message =
10849 "vkBindBufferMemory(): "
10850 "uniform memoryOffset "
10851 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010852
10853 ASSERT_NO_FATAL_FAILURE(InitState());
10854 ASSERT_NO_FATAL_FAILURE(InitViewport());
10855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10856
10857 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010858 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010859 pipe_ms_state_ci.pNext = NULL;
10860 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10861 pipe_ms_state_ci.sampleShadingEnable = 0;
10862 pipe_ms_state_ci.minSampleShading = 1.0;
10863 pipe_ms_state_ci.pSampleMask = nullptr;
10864
10865 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10866 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10867 VkPipelineLayout pipeline_layout;
10868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010869 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010870 ASSERT_VK_SUCCESS(err);
10871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010872 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10873 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010874 VkPipelineObj pipe(m_device);
10875 pipe.AddShader(&vs);
10876 pipe.AddShader(&fs);
10877 pipe.AddColorAttachment();
10878 pipe.SetMSAA(&pipe_ms_state_ci);
10879 pipe.SetViewport(m_viewports);
10880 pipe.SetScissor(m_scissors);
10881 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10882
Tony Barbour552f6c02016-12-21 14:34:07 -070010883 m_commandBuffer->BeginCommandBuffer();
10884 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010885 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010886
10887 {
10888 // Create and bind a vertex buffer in a reduced scope, which will cause
10889 // it to be deleted upon leaving this scope
10890 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010891 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010892 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10893 draw_verticies.AddVertexInputToPipe(pipe);
10894 }
10895
10896 Draw(1, 0, 0, 0);
10897
Tony Barbour552f6c02016-12-21 14:34:07 -070010898 m_commandBuffer->EndRenderPass();
10899 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010900
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010902 QueueCommandBuffer(false);
10903 m_errorMonitor->VerifyFound();
10904
10905 {
10906 // Create and bind a vertex buffer in a reduced scope, and delete it
10907 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010908 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010910 buffer_test.TestDoubleDestroy();
10911 }
10912 m_errorMonitor->VerifyFound();
10913
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010914 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010915 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10917 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10918 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010919 m_errorMonitor->VerifyFound();
10920 }
10921
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010922 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10923 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010924 // Create and bind a memory buffer with an invalid offset again,
10925 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10927 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10928 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010929 m_errorMonitor->VerifyFound();
10930 }
10931
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010932 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010933 // Create and bind a memory buffer with an invalid offset again, but
10934 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10936 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10937 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010938 m_errorMonitor->VerifyFound();
10939 }
10940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010941 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010942 // Create and bind a memory buffer with an invalid offset again, but
10943 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10945 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10946 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010947 m_errorMonitor->VerifyFound();
10948 }
10949
10950 {
10951 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010953 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10954 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010955 m_errorMonitor->VerifyFound();
10956 }
10957
10958 {
10959 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010961 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10962 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010963 }
10964 m_errorMonitor->VerifyFound();
10965
10966 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10967}
10968
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010969// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10970TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010971 TEST_DESCRIPTION(
10972 "Hit all possible validation checks associated with the "
10973 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10974 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010975 // 3 in ValidateCmdBufImageLayouts
10976 // * -1 Attempt to submit cmd buf w/ deleted image
10977 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10978 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010979
10980 ASSERT_NO_FATAL_FAILURE(InitState());
10981 // Create src & dst images to use for copy operations
10982 VkImage src_image;
10983 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010984 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010985
10986 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10987 const int32_t tex_width = 32;
10988 const int32_t tex_height = 32;
10989
10990 VkImageCreateInfo image_create_info = {};
10991 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10992 image_create_info.pNext = NULL;
10993 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10994 image_create_info.format = tex_format;
10995 image_create_info.extent.width = tex_width;
10996 image_create_info.extent.height = tex_height;
10997 image_create_info.extent.depth = 1;
10998 image_create_info.mipLevels = 1;
10999 image_create_info.arrayLayers = 4;
11000 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11001 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11002 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011003 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011004 image_create_info.flags = 0;
11005
11006 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11007 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011008 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011009 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11010 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011011 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11012 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11013 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11014 ASSERT_VK_SUCCESS(err);
11015
11016 // Allocate memory
11017 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011018 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011019 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011020 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11021 mem_alloc.pNext = NULL;
11022 mem_alloc.allocationSize = 0;
11023 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011024
11025 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011026 mem_alloc.allocationSize = img_mem_reqs.size;
11027 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011028 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011029 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011030 ASSERT_VK_SUCCESS(err);
11031
11032 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011033 mem_alloc.allocationSize = img_mem_reqs.size;
11034 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011035 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011036 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011037 ASSERT_VK_SUCCESS(err);
11038
11039 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011040 mem_alloc.allocationSize = img_mem_reqs.size;
11041 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011042 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011043 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011044 ASSERT_VK_SUCCESS(err);
11045
11046 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11047 ASSERT_VK_SUCCESS(err);
11048 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11049 ASSERT_VK_SUCCESS(err);
11050 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11051 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011052
Tony Barbour552f6c02016-12-21 14:34:07 -070011053 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011054 VkImageCopy copy_region;
11055 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11056 copy_region.srcSubresource.mipLevel = 0;
11057 copy_region.srcSubresource.baseArrayLayer = 0;
11058 copy_region.srcSubresource.layerCount = 1;
11059 copy_region.srcOffset.x = 0;
11060 copy_region.srcOffset.y = 0;
11061 copy_region.srcOffset.z = 0;
11062 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11063 copy_region.dstSubresource.mipLevel = 0;
11064 copy_region.dstSubresource.baseArrayLayer = 0;
11065 copy_region.dstSubresource.layerCount = 1;
11066 copy_region.dstOffset.x = 0;
11067 copy_region.dstOffset.y = 0;
11068 copy_region.dstOffset.z = 0;
11069 copy_region.extent.width = 1;
11070 copy_region.extent.height = 1;
11071 copy_region.extent.depth = 1;
11072
11073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11074 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
11075 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 -060011076 m_errorMonitor->VerifyFound();
11077 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11079 "Cannot copy from an image whose source layout is "
11080 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11081 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011082 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 -060011083 m_errorMonitor->VerifyFound();
11084 // Final src error is due to bad layout type
11085 m_errorMonitor->SetDesiredFailureMsg(
11086 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11087 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011088 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 -060011089 m_errorMonitor->VerifyFound();
11090 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11092 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011093 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 -060011094 m_errorMonitor->VerifyFound();
11095 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11097 "Cannot copy from an image whose dest layout is "
11098 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11099 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011100 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 -060011101 m_errorMonitor->VerifyFound();
11102 m_errorMonitor->SetDesiredFailureMsg(
11103 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11104 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011105 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 -060011106 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011107
Cort3b021012016-12-07 12:00:57 -080011108 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11109 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11110 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11111 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11112 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11113 transfer_dst_image_barrier[0].srcAccessMask = 0;
11114 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11115 transfer_dst_image_barrier[0].image = dst_image;
11116 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11117 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11118 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11119 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11120 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11121 transfer_dst_image_barrier[0].image = depth_image;
11122 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11123 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11124 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11125
11126 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011127 VkClearColorValue color_clear_value = {};
11128 VkImageSubresourceRange clear_range;
11129 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11130 clear_range.baseMipLevel = 0;
11131 clear_range.baseArrayLayer = 0;
11132 clear_range.layerCount = 1;
11133 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011134
Cort3b021012016-12-07 12:00:57 -080011135 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11136 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11138 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011139 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011140 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011141 // Fail due to provided layout not matching actual current layout for color clear.
11142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011143 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011144 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011145
Cort530cf382016-12-08 09:59:47 -080011146 VkClearDepthStencilValue depth_clear_value = {};
11147 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011148
11149 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11150 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011153 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011154 m_errorMonitor->VerifyFound();
11155 // Fail due to provided layout not matching actual current layout for depth clear.
11156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011157 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011158 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011159
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011160 // Now cause error due to bad image layout transition in PipelineBarrier
11161 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011162 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011163 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011164 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011165 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011166 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11167 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011168 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11170 "You cannot transition the layout of aspect 1 from "
11171 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11172 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011173 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11174 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011175 m_errorMonitor->VerifyFound();
11176
11177 // Finally some layout errors at RenderPass create time
11178 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11179 VkAttachmentReference attach = {};
11180 // perf warning for GENERAL layout w/ non-DS input attachment
11181 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11182 VkSubpassDescription subpass = {};
11183 subpass.inputAttachmentCount = 1;
11184 subpass.pInputAttachments = &attach;
11185 VkRenderPassCreateInfo rpci = {};
11186 rpci.subpassCount = 1;
11187 rpci.pSubpasses = &subpass;
11188 rpci.attachmentCount = 1;
11189 VkAttachmentDescription attach_desc = {};
11190 attach_desc.format = VK_FORMAT_UNDEFINED;
11191 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011192 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011193 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11195 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011196 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11197 m_errorMonitor->VerifyFound();
11198 // error w/ non-general layout
11199 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11200
11201 m_errorMonitor->SetDesiredFailureMsg(
11202 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11203 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11204 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11205 m_errorMonitor->VerifyFound();
11206 subpass.inputAttachmentCount = 0;
11207 subpass.colorAttachmentCount = 1;
11208 subpass.pColorAttachments = &attach;
11209 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11210 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11212 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011213 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11214 m_errorMonitor->VerifyFound();
11215 // error w/ non-color opt or GENERAL layout for color attachment
11216 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11217 m_errorMonitor->SetDesiredFailureMsg(
11218 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11219 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11220 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11221 m_errorMonitor->VerifyFound();
11222 subpass.colorAttachmentCount = 0;
11223 subpass.pDepthStencilAttachment = &attach;
11224 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11225 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11227 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011228 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11229 m_errorMonitor->VerifyFound();
11230 // error w/ non-ds opt or GENERAL layout for color attachment
11231 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11233 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11234 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011235 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11236 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011237 // For this error we need a valid renderpass so create default one
11238 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11239 attach.attachment = 0;
11240 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11241 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11242 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11243 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11244 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11245 // Can't do a CLEAR load on READ_ONLY initialLayout
11246 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11247 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11248 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11250 " with invalid first layout "
11251 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11252 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011253 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11254 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011255
Cort3b021012016-12-07 12:00:57 -080011256 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11257 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11258 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011259 vkDestroyImage(m_device->device(), src_image, NULL);
11260 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011261 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011262}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011263
Tobin Ehlise0936662016-10-11 08:10:51 -060011264TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11265 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11266 VkResult err;
11267
11268 ASSERT_NO_FATAL_FAILURE(InitState());
11269
11270 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11271 VkImageTiling tiling;
11272 VkFormatProperties format_properties;
11273 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11274 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11275 tiling = VK_IMAGE_TILING_LINEAR;
11276 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11277 tiling = VK_IMAGE_TILING_OPTIMAL;
11278 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011279 printf(
11280 "Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11281 "skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011282 return;
11283 }
11284
11285 VkDescriptorPoolSize ds_type = {};
11286 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11287 ds_type.descriptorCount = 1;
11288
11289 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11290 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11291 ds_pool_ci.maxSets = 1;
11292 ds_pool_ci.poolSizeCount = 1;
11293 ds_pool_ci.pPoolSizes = &ds_type;
11294 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11295
11296 VkDescriptorPool ds_pool;
11297 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11298 ASSERT_VK_SUCCESS(err);
11299
11300 VkDescriptorSetLayoutBinding dsl_binding = {};
11301 dsl_binding.binding = 0;
11302 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11303 dsl_binding.descriptorCount = 1;
11304 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11305 dsl_binding.pImmutableSamplers = NULL;
11306
11307 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11308 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11309 ds_layout_ci.pNext = NULL;
11310 ds_layout_ci.bindingCount = 1;
11311 ds_layout_ci.pBindings = &dsl_binding;
11312
11313 VkDescriptorSetLayout ds_layout;
11314 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11315 ASSERT_VK_SUCCESS(err);
11316
11317 VkDescriptorSetAllocateInfo alloc_info = {};
11318 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11319 alloc_info.descriptorSetCount = 1;
11320 alloc_info.descriptorPool = ds_pool;
11321 alloc_info.pSetLayouts = &ds_layout;
11322 VkDescriptorSet descriptor_set;
11323 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11324 ASSERT_VK_SUCCESS(err);
11325
11326 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11327 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11328 pipeline_layout_ci.pNext = NULL;
11329 pipeline_layout_ci.setLayoutCount = 1;
11330 pipeline_layout_ci.pSetLayouts = &ds_layout;
11331 VkPipelineLayout pipeline_layout;
11332 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11333 ASSERT_VK_SUCCESS(err);
11334
11335 VkImageObj image(m_device);
11336 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11337 ASSERT_TRUE(image.initialized());
11338 VkImageView view = image.targetView(tex_format);
11339
11340 VkDescriptorImageInfo image_info = {};
11341 image_info.imageView = view;
11342 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11343
11344 VkWriteDescriptorSet descriptor_write = {};
11345 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11346 descriptor_write.dstSet = descriptor_set;
11347 descriptor_write.dstBinding = 0;
11348 descriptor_write.descriptorCount = 1;
11349 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11350 descriptor_write.pImageInfo = &image_info;
11351
11352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11353 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11354 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11355 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11356 m_errorMonitor->VerifyFound();
11357
11358 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11359 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11360 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11361 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11362}
11363
Mark Mueller93b938f2016-08-18 10:27:40 -060011364TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011365 TEST_DESCRIPTION(
11366 "Use vkCmdExecuteCommands with invalid state "
11367 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011368
11369 ASSERT_NO_FATAL_FAILURE(InitState());
11370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11371
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011372 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011373 const char *simultaneous_use_message2 =
11374 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11375 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011376
11377 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011378 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011379 command_buffer_allocate_info.commandPool = m_commandPool;
11380 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11381 command_buffer_allocate_info.commandBufferCount = 1;
11382
11383 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011384 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011385 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11386 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011387 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011388 command_buffer_inheritance_info.renderPass = m_renderPass;
11389 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011390
Mark Mueller93b938f2016-08-18 10:27:40 -060011391 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011392 command_buffer_begin_info.flags =
11393 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011394 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11395
11396 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11397 vkEndCommandBuffer(secondary_command_buffer);
11398
Mark Mueller93b938f2016-08-18 10:27:40 -060011399 VkSubmitInfo submit_info = {};
11400 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11401 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011402 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011403
Mark Mueller4042b652016-09-05 22:52:21 -060011404 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011405 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11407 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011408 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011409 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011410 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11411 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011412
Dave Houltonfbf52152017-01-06 12:55:29 -070011413 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011414 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011415 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011416
Mark Mueller4042b652016-09-05 22:52:21 -060011417 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011418 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011419 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11422 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011423 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011424 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11425 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011426
11427 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011428}
11429
Tobin Ehlisb093da82017-01-19 12:05:27 -070011430TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011431 TEST_DESCRIPTION(
11432 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11433 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070011434
11435 ASSERT_NO_FATAL_FAILURE(InitState());
11436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11437
11438 std::vector<const char *> device_extension_names;
11439 auto features = m_device->phy().features();
11440 // Make sure gs & ts are disabled
11441 features.geometryShader = false;
11442 features.tessellationShader = false;
11443 // The sacrificial device object
11444 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11445
11446 VkCommandPoolCreateInfo pool_create_info{};
11447 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11448 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11449
11450 VkCommandPool command_pool;
11451 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11452
11453 VkCommandBufferAllocateInfo cmd = {};
11454 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11455 cmd.pNext = NULL;
11456 cmd.commandPool = command_pool;
11457 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11458 cmd.commandBufferCount = 1;
11459
11460 VkCommandBuffer cmd_buffer;
11461 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11462 ASSERT_VK_SUCCESS(err);
11463
11464 VkEvent event;
11465 VkEventCreateInfo evci = {};
11466 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11467 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11468 ASSERT_VK_SUCCESS(result);
11469
11470 VkCommandBufferBeginInfo cbbi = {};
11471 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11472 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11473 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11474 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11475 m_errorMonitor->VerifyFound();
11476
11477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11478 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11479 m_errorMonitor->VerifyFound();
11480
11481 vkDestroyEvent(test_device.handle(), event, NULL);
11482 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11483}
11484
Mark Mueller917f6bc2016-08-30 10:57:19 -060011485TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011486 TEST_DESCRIPTION(
11487 "Use vkCmdExecuteCommands with invalid state "
11488 "in primary and secondary command buffers. "
11489 "Delete objects that are inuse. Call VkQueueSubmit "
11490 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011491
11492 ASSERT_NO_FATAL_FAILURE(InitState());
11493 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11494
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011495 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011496 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011497
Tony Barbour552f6c02016-12-21 14:34:07 -070011498 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011499
11500 VkEvent event;
11501 VkEventCreateInfo event_create_info = {};
11502 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11503 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011504 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011505
Tony Barbour552f6c02016-12-21 14:34:07 -070011506 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011507 vkDestroyEvent(m_device->device(), event, nullptr);
11508
11509 VkSubmitInfo submit_info = {};
11510 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11511 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011512 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011514 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11515 m_errorMonitor->VerifyFound();
11516
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011517 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011518 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11519
11520 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11521
Mark Mueller917f6bc2016-08-30 10:57:19 -060011522 VkSemaphoreCreateInfo semaphore_create_info = {};
11523 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11524 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011525 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011526 VkFenceCreateInfo fence_create_info = {};
11527 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11528 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011529 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011530
11531 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011532 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011533 descriptor_pool_type_count.descriptorCount = 1;
11534
11535 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11536 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11537 descriptor_pool_create_info.maxSets = 1;
11538 descriptor_pool_create_info.poolSizeCount = 1;
11539 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011540 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011541
11542 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011543 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011544
11545 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011546 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011547 descriptorset_layout_binding.descriptorCount = 1;
11548 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11549
11550 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011551 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011552 descriptorset_layout_create_info.bindingCount = 1;
11553 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11554
11555 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011556 ASSERT_VK_SUCCESS(
11557 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011558
11559 VkDescriptorSet descriptorset;
11560 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011561 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011562 descriptorset_allocate_info.descriptorSetCount = 1;
11563 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11564 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011565 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011566
Mark Mueller4042b652016-09-05 22:52:21 -060011567 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11568
11569 VkDescriptorBufferInfo buffer_info = {};
11570 buffer_info.buffer = buffer_test.GetBuffer();
11571 buffer_info.offset = 0;
11572 buffer_info.range = 1024;
11573
11574 VkWriteDescriptorSet write_descriptor_set = {};
11575 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11576 write_descriptor_set.dstSet = descriptorset;
11577 write_descriptor_set.descriptorCount = 1;
11578 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11579 write_descriptor_set.pBufferInfo = &buffer_info;
11580
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011581 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011582
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011583 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11584 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011585
11586 VkPipelineObj pipe(m_device);
11587 pipe.AddColorAttachment();
11588 pipe.AddShader(&vs);
11589 pipe.AddShader(&fs);
11590
11591 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011592 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011593 pipeline_layout_create_info.setLayoutCount = 1;
11594 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11595
11596 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011597 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011598
11599 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11600
Tony Barbour552f6c02016-12-21 14:34:07 -070011601 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011602 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011603
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011604 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11605 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11606 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011607
Tony Barbour552f6c02016-12-21 14:34:07 -070011608 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011609
Mark Mueller917f6bc2016-08-30 10:57:19 -060011610 submit_info.signalSemaphoreCount = 1;
11611 submit_info.pSignalSemaphores = &semaphore;
11612 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011613 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011614
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011616 vkDestroyEvent(m_device->device(), event, nullptr);
11617 m_errorMonitor->VerifyFound();
11618
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011620 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11621 m_errorMonitor->VerifyFound();
11622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011624 vkDestroyFence(m_device->device(), fence, nullptr);
11625 m_errorMonitor->VerifyFound();
11626
Tobin Ehlis122207b2016-09-01 08:50:06 -070011627 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011628 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11629 vkDestroyFence(m_device->device(), fence, nullptr);
11630 vkDestroyEvent(m_device->device(), event, nullptr);
11631 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011632 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011633 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11634}
11635
Tobin Ehlis2adda372016-09-01 08:51:06 -070011636TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11637 TEST_DESCRIPTION("Delete in-use query pool.");
11638
11639 ASSERT_NO_FATAL_FAILURE(InitState());
11640 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11641
11642 VkQueryPool query_pool;
11643 VkQueryPoolCreateInfo query_pool_ci{};
11644 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11645 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11646 query_pool_ci.queryCount = 1;
11647 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011648 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011649 // Reset query pool to create binding with cmd buffer
11650 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11651
Tony Barbour552f6c02016-12-21 14:34:07 -070011652 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011653
11654 VkSubmitInfo submit_info = {};
11655 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11656 submit_info.commandBufferCount = 1;
11657 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11658 // Submit cmd buffer and then destroy query pool while in-flight
11659 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11660
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011662 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11663 m_errorMonitor->VerifyFound();
11664
11665 vkQueueWaitIdle(m_device->m_queue);
11666 // Now that cmd buffer done we can safely destroy query_pool
11667 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11668}
11669
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011670TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11671 TEST_DESCRIPTION("Delete in-use pipeline.");
11672
11673 ASSERT_NO_FATAL_FAILURE(InitState());
11674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11675
11676 // Empty pipeline layout used for binding PSO
11677 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11678 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11679 pipeline_layout_ci.setLayoutCount = 0;
11680 pipeline_layout_ci.pSetLayouts = NULL;
11681
11682 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011683 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011684 ASSERT_VK_SUCCESS(err);
11685
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011687 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011688 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11689 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011690 // Store pipeline handle so we can actually delete it before test finishes
11691 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011692 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011693 VkPipelineObj pipe(m_device);
11694 pipe.AddShader(&vs);
11695 pipe.AddShader(&fs);
11696 pipe.AddColorAttachment();
11697 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11698 delete_this_pipeline = pipe.handle();
11699
Tony Barbour552f6c02016-12-21 14:34:07 -070011700 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011701 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011702 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011703
Tony Barbour552f6c02016-12-21 14:34:07 -070011704 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011705
11706 VkSubmitInfo submit_info = {};
11707 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11708 submit_info.commandBufferCount = 1;
11709 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11710 // Submit cmd buffer and then pipeline destroyed while in-flight
11711 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011712 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011713 m_errorMonitor->VerifyFound();
11714 // Make sure queue finished and then actually delete pipeline
11715 vkQueueWaitIdle(m_device->m_queue);
11716 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11717 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11718}
11719
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011720TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11721 TEST_DESCRIPTION("Delete in-use imageView.");
11722
11723 ASSERT_NO_FATAL_FAILURE(InitState());
11724 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11725
11726 VkDescriptorPoolSize ds_type_count;
11727 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11728 ds_type_count.descriptorCount = 1;
11729
11730 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11731 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11732 ds_pool_ci.maxSets = 1;
11733 ds_pool_ci.poolSizeCount = 1;
11734 ds_pool_ci.pPoolSizes = &ds_type_count;
11735
11736 VkDescriptorPool ds_pool;
11737 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11738 ASSERT_VK_SUCCESS(err);
11739
11740 VkSamplerCreateInfo sampler_ci = {};
11741 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11742 sampler_ci.pNext = NULL;
11743 sampler_ci.magFilter = VK_FILTER_NEAREST;
11744 sampler_ci.minFilter = VK_FILTER_NEAREST;
11745 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11746 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11747 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11748 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11749 sampler_ci.mipLodBias = 1.0;
11750 sampler_ci.anisotropyEnable = VK_FALSE;
11751 sampler_ci.maxAnisotropy = 1;
11752 sampler_ci.compareEnable = VK_FALSE;
11753 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11754 sampler_ci.minLod = 1.0;
11755 sampler_ci.maxLod = 1.0;
11756 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11757 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11758 VkSampler sampler;
11759
11760 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11761 ASSERT_VK_SUCCESS(err);
11762
11763 VkDescriptorSetLayoutBinding layout_binding;
11764 layout_binding.binding = 0;
11765 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11766 layout_binding.descriptorCount = 1;
11767 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11768 layout_binding.pImmutableSamplers = NULL;
11769
11770 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11771 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11772 ds_layout_ci.bindingCount = 1;
11773 ds_layout_ci.pBindings = &layout_binding;
11774 VkDescriptorSetLayout ds_layout;
11775 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11776 ASSERT_VK_SUCCESS(err);
11777
11778 VkDescriptorSetAllocateInfo alloc_info = {};
11779 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11780 alloc_info.descriptorSetCount = 1;
11781 alloc_info.descriptorPool = ds_pool;
11782 alloc_info.pSetLayouts = &ds_layout;
11783 VkDescriptorSet descriptor_set;
11784 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11785 ASSERT_VK_SUCCESS(err);
11786
11787 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11788 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11789 pipeline_layout_ci.pNext = NULL;
11790 pipeline_layout_ci.setLayoutCount = 1;
11791 pipeline_layout_ci.pSetLayouts = &ds_layout;
11792
11793 VkPipelineLayout pipeline_layout;
11794 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11795 ASSERT_VK_SUCCESS(err);
11796
11797 VkImageObj image(m_device);
11798 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11799 ASSERT_TRUE(image.initialized());
11800
11801 VkImageView view;
11802 VkImageViewCreateInfo ivci = {};
11803 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11804 ivci.image = image.handle();
11805 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11806 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11807 ivci.subresourceRange.layerCount = 1;
11808 ivci.subresourceRange.baseMipLevel = 0;
11809 ivci.subresourceRange.levelCount = 1;
11810 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11811
11812 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11813 ASSERT_VK_SUCCESS(err);
11814
11815 VkDescriptorImageInfo image_info{};
11816 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11817 image_info.imageView = view;
11818 image_info.sampler = sampler;
11819
11820 VkWriteDescriptorSet descriptor_write = {};
11821 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11822 descriptor_write.dstSet = descriptor_set;
11823 descriptor_write.dstBinding = 0;
11824 descriptor_write.descriptorCount = 1;
11825 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11826 descriptor_write.pImageInfo = &image_info;
11827
11828 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11829
11830 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011831 char const *vsSource =
11832 "#version 450\n"
11833 "\n"
11834 "out gl_PerVertex { \n"
11835 " vec4 gl_Position;\n"
11836 "};\n"
11837 "void main(){\n"
11838 " gl_Position = vec4(1);\n"
11839 "}\n";
11840 char const *fsSource =
11841 "#version 450\n"
11842 "\n"
11843 "layout(set=0, binding=0) uniform sampler2D s;\n"
11844 "layout(location=0) out vec4 x;\n"
11845 "void main(){\n"
11846 " x = texture(s, vec2(1));\n"
11847 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011848 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11849 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11850 VkPipelineObj pipe(m_device);
11851 pipe.AddShader(&vs);
11852 pipe.AddShader(&fs);
11853 pipe.AddColorAttachment();
11854 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11855
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011857
Tony Barbour552f6c02016-12-21 14:34:07 -070011858 m_commandBuffer->BeginCommandBuffer();
11859 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011860 // Bind pipeline to cmd buffer
11861 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11862 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11863 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070011864
11865 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11866 VkRect2D scissor = {{0, 0}, {16, 16}};
11867 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11868 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11869
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011870 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011871 m_commandBuffer->EndRenderPass();
11872 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011873 // Submit cmd buffer then destroy sampler
11874 VkSubmitInfo submit_info = {};
11875 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11876 submit_info.commandBufferCount = 1;
11877 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11878 // Submit cmd buffer and then destroy imageView while in-flight
11879 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11880
11881 vkDestroyImageView(m_device->device(), view, nullptr);
11882 m_errorMonitor->VerifyFound();
11883 vkQueueWaitIdle(m_device->m_queue);
11884 // Now we can actually destroy imageView
11885 vkDestroyImageView(m_device->device(), view, NULL);
11886 vkDestroySampler(m_device->device(), sampler, nullptr);
11887 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11888 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11889 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11890}
11891
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011892TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11893 TEST_DESCRIPTION("Delete in-use bufferView.");
11894
11895 ASSERT_NO_FATAL_FAILURE(InitState());
11896 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11897
11898 VkDescriptorPoolSize ds_type_count;
11899 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11900 ds_type_count.descriptorCount = 1;
11901
11902 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11903 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11904 ds_pool_ci.maxSets = 1;
11905 ds_pool_ci.poolSizeCount = 1;
11906 ds_pool_ci.pPoolSizes = &ds_type_count;
11907
11908 VkDescriptorPool ds_pool;
11909 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11910 ASSERT_VK_SUCCESS(err);
11911
11912 VkDescriptorSetLayoutBinding layout_binding;
11913 layout_binding.binding = 0;
11914 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11915 layout_binding.descriptorCount = 1;
11916 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11917 layout_binding.pImmutableSamplers = NULL;
11918
11919 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11920 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11921 ds_layout_ci.bindingCount = 1;
11922 ds_layout_ci.pBindings = &layout_binding;
11923 VkDescriptorSetLayout ds_layout;
11924 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11925 ASSERT_VK_SUCCESS(err);
11926
11927 VkDescriptorSetAllocateInfo alloc_info = {};
11928 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11929 alloc_info.descriptorSetCount = 1;
11930 alloc_info.descriptorPool = ds_pool;
11931 alloc_info.pSetLayouts = &ds_layout;
11932 VkDescriptorSet descriptor_set;
11933 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11934 ASSERT_VK_SUCCESS(err);
11935
11936 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11937 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11938 pipeline_layout_ci.pNext = NULL;
11939 pipeline_layout_ci.setLayoutCount = 1;
11940 pipeline_layout_ci.pSetLayouts = &ds_layout;
11941
11942 VkPipelineLayout pipeline_layout;
11943 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11944 ASSERT_VK_SUCCESS(err);
11945
11946 VkBuffer buffer;
11947 uint32_t queue_family_index = 0;
11948 VkBufferCreateInfo buffer_create_info = {};
11949 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11950 buffer_create_info.size = 1024;
11951 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11952 buffer_create_info.queueFamilyIndexCount = 1;
11953 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11954
11955 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11956 ASSERT_VK_SUCCESS(err);
11957
11958 VkMemoryRequirements memory_reqs;
11959 VkDeviceMemory buffer_memory;
11960
11961 VkMemoryAllocateInfo memory_info = {};
11962 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11963 memory_info.allocationSize = 0;
11964 memory_info.memoryTypeIndex = 0;
11965
11966 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11967 memory_info.allocationSize = memory_reqs.size;
11968 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11969 ASSERT_TRUE(pass);
11970
11971 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11972 ASSERT_VK_SUCCESS(err);
11973 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11974 ASSERT_VK_SUCCESS(err);
11975
11976 VkBufferView view;
11977 VkBufferViewCreateInfo bvci = {};
11978 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11979 bvci.buffer = buffer;
11980 bvci.format = VK_FORMAT_R8_UNORM;
11981 bvci.range = VK_WHOLE_SIZE;
11982
11983 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11984 ASSERT_VK_SUCCESS(err);
11985
11986 VkWriteDescriptorSet descriptor_write = {};
11987 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11988 descriptor_write.dstSet = descriptor_set;
11989 descriptor_write.dstBinding = 0;
11990 descriptor_write.descriptorCount = 1;
11991 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11992 descriptor_write.pTexelBufferView = &view;
11993
11994 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11995
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011996 char const *vsSource =
11997 "#version 450\n"
11998 "\n"
11999 "out gl_PerVertex { \n"
12000 " vec4 gl_Position;\n"
12001 "};\n"
12002 "void main(){\n"
12003 " gl_Position = vec4(1);\n"
12004 "}\n";
12005 char const *fsSource =
12006 "#version 450\n"
12007 "\n"
12008 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12009 "layout(location=0) out vec4 x;\n"
12010 "void main(){\n"
12011 " x = imageLoad(s, 0);\n"
12012 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012013 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12014 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12015 VkPipelineObj pipe(m_device);
12016 pipe.AddShader(&vs);
12017 pipe.AddShader(&fs);
12018 pipe.AddColorAttachment();
12019 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12020
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012022
Tony Barbour552f6c02016-12-21 14:34:07 -070012023 m_commandBuffer->BeginCommandBuffer();
12024 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012025 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12026 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12027 VkRect2D scissor = {{0, 0}, {16, 16}};
12028 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12029 // Bind pipeline to cmd buffer
12030 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12031 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12032 &descriptor_set, 0, nullptr);
12033 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012034 m_commandBuffer->EndRenderPass();
12035 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012036
12037 VkSubmitInfo submit_info = {};
12038 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12039 submit_info.commandBufferCount = 1;
12040 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12041 // Submit cmd buffer and then destroy bufferView while in-flight
12042 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12043
12044 vkDestroyBufferView(m_device->device(), view, nullptr);
12045 m_errorMonitor->VerifyFound();
12046 vkQueueWaitIdle(m_device->m_queue);
12047 // Now we can actually destroy bufferView
12048 vkDestroyBufferView(m_device->device(), view, NULL);
12049 vkDestroyBuffer(m_device->device(), buffer, NULL);
12050 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12051 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12052 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12053 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12054}
12055
Tobin Ehlis209532e2016-09-07 13:52:18 -060012056TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12057 TEST_DESCRIPTION("Delete in-use sampler.");
12058
12059 ASSERT_NO_FATAL_FAILURE(InitState());
12060 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12061
12062 VkDescriptorPoolSize ds_type_count;
12063 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12064 ds_type_count.descriptorCount = 1;
12065
12066 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12067 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12068 ds_pool_ci.maxSets = 1;
12069 ds_pool_ci.poolSizeCount = 1;
12070 ds_pool_ci.pPoolSizes = &ds_type_count;
12071
12072 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012073 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012074 ASSERT_VK_SUCCESS(err);
12075
12076 VkSamplerCreateInfo sampler_ci = {};
12077 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12078 sampler_ci.pNext = NULL;
12079 sampler_ci.magFilter = VK_FILTER_NEAREST;
12080 sampler_ci.minFilter = VK_FILTER_NEAREST;
12081 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12082 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12083 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12084 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12085 sampler_ci.mipLodBias = 1.0;
12086 sampler_ci.anisotropyEnable = VK_FALSE;
12087 sampler_ci.maxAnisotropy = 1;
12088 sampler_ci.compareEnable = VK_FALSE;
12089 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12090 sampler_ci.minLod = 1.0;
12091 sampler_ci.maxLod = 1.0;
12092 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12093 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12094 VkSampler sampler;
12095
12096 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12097 ASSERT_VK_SUCCESS(err);
12098
12099 VkDescriptorSetLayoutBinding layout_binding;
12100 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012101 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012102 layout_binding.descriptorCount = 1;
12103 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12104 layout_binding.pImmutableSamplers = NULL;
12105
12106 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12107 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12108 ds_layout_ci.bindingCount = 1;
12109 ds_layout_ci.pBindings = &layout_binding;
12110 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012111 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012112 ASSERT_VK_SUCCESS(err);
12113
12114 VkDescriptorSetAllocateInfo alloc_info = {};
12115 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12116 alloc_info.descriptorSetCount = 1;
12117 alloc_info.descriptorPool = ds_pool;
12118 alloc_info.pSetLayouts = &ds_layout;
12119 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012120 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012121 ASSERT_VK_SUCCESS(err);
12122
12123 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12124 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12125 pipeline_layout_ci.pNext = NULL;
12126 pipeline_layout_ci.setLayoutCount = 1;
12127 pipeline_layout_ci.pSetLayouts = &ds_layout;
12128
12129 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012130 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012131 ASSERT_VK_SUCCESS(err);
12132
12133 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012134 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 -060012135 ASSERT_TRUE(image.initialized());
12136
12137 VkImageView view;
12138 VkImageViewCreateInfo ivci = {};
12139 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12140 ivci.image = image.handle();
12141 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12142 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12143 ivci.subresourceRange.layerCount = 1;
12144 ivci.subresourceRange.baseMipLevel = 0;
12145 ivci.subresourceRange.levelCount = 1;
12146 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12147
12148 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12149 ASSERT_VK_SUCCESS(err);
12150
12151 VkDescriptorImageInfo image_info{};
12152 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12153 image_info.imageView = view;
12154 image_info.sampler = sampler;
12155
12156 VkWriteDescriptorSet descriptor_write = {};
12157 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12158 descriptor_write.dstSet = descriptor_set;
12159 descriptor_write.dstBinding = 0;
12160 descriptor_write.descriptorCount = 1;
12161 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12162 descriptor_write.pImageInfo = &image_info;
12163
12164 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12165
12166 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012167 char const *vsSource =
12168 "#version 450\n"
12169 "\n"
12170 "out gl_PerVertex { \n"
12171 " vec4 gl_Position;\n"
12172 "};\n"
12173 "void main(){\n"
12174 " gl_Position = vec4(1);\n"
12175 "}\n";
12176 char const *fsSource =
12177 "#version 450\n"
12178 "\n"
12179 "layout(set=0, binding=0) uniform sampler2D s;\n"
12180 "layout(location=0) out vec4 x;\n"
12181 "void main(){\n"
12182 " x = texture(s, vec2(1));\n"
12183 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012184 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12185 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12186 VkPipelineObj pipe(m_device);
12187 pipe.AddShader(&vs);
12188 pipe.AddShader(&fs);
12189 pipe.AddColorAttachment();
12190 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12191
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012193
Tony Barbour552f6c02016-12-21 14:34:07 -070012194 m_commandBuffer->BeginCommandBuffer();
12195 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012196 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012197 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12198 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12199 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012200
12201 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12202 VkRect2D scissor = {{0, 0}, {16, 16}};
12203 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12204 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12205
Tobin Ehlis209532e2016-09-07 13:52:18 -060012206 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012207 m_commandBuffer->EndRenderPass();
12208 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012209 // Submit cmd buffer then destroy sampler
12210 VkSubmitInfo submit_info = {};
12211 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12212 submit_info.commandBufferCount = 1;
12213 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12214 // Submit cmd buffer and then destroy sampler while in-flight
12215 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12216
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012217 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012218 m_errorMonitor->VerifyFound();
12219 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012220
Tobin Ehlis209532e2016-09-07 13:52:18 -060012221 // Now we can actually destroy sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012222 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012223 vkDestroyImageView(m_device->device(), view, NULL);
12224 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12225 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12226 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12227}
12228
Mark Mueller1cd9f412016-08-25 13:23:52 -060012229TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012230 TEST_DESCRIPTION(
12231 "Call VkQueueSubmit with a semaphore that is already "
12232 "signaled but not waited on by the queue. Wait on a "
12233 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012234
12235 ASSERT_NO_FATAL_FAILURE(InitState());
12236 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012238 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 -070012239 const char *invalid_fence_wait_message =
12240 " which has not been submitted on a Queue or during "
12241 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012242
Tony Barbour552f6c02016-12-21 14:34:07 -070012243 m_commandBuffer->BeginCommandBuffer();
12244 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012245
12246 VkSemaphoreCreateInfo semaphore_create_info = {};
12247 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12248 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012249 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012250 VkSubmitInfo submit_info = {};
12251 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12252 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012253 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012254 submit_info.signalSemaphoreCount = 1;
12255 submit_info.pSignalSemaphores = &semaphore;
12256 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012257 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012258 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012259 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012260 m_commandBuffer->BeginCommandBuffer();
12261 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012263 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12264 m_errorMonitor->VerifyFound();
12265
Mark Mueller1cd9f412016-08-25 13:23:52 -060012266 VkFenceCreateInfo fence_create_info = {};
12267 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12268 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012269 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012272 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12273 m_errorMonitor->VerifyFound();
12274
Mark Mueller4042b652016-09-05 22:52:21 -060012275 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012276 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012277 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12278}
12279
Tobin Ehlis4af23302016-07-19 10:50:30 -060012280TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012281 TEST_DESCRIPTION(
12282 "Bind a secondary command buffer with with a framebuffer "
12283 "that does not match the framebuffer for the active "
12284 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012285 ASSERT_NO_FATAL_FAILURE(InitState());
12286 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12287
12288 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012289 VkAttachmentDescription attachment = {0,
12290 VK_FORMAT_B8G8R8A8_UNORM,
12291 VK_SAMPLE_COUNT_1_BIT,
12292 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12293 VK_ATTACHMENT_STORE_OP_STORE,
12294 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12295 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12296 VK_IMAGE_LAYOUT_UNDEFINED,
12297 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012299 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012300
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012301 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012303 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012304
12305 VkRenderPass rp;
12306 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12307 ASSERT_VK_SUCCESS(err);
12308
12309 // A compatible framebuffer.
12310 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012311 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 -060012312 ASSERT_TRUE(image.initialized());
12313
12314 VkImageViewCreateInfo ivci = {
12315 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12316 nullptr,
12317 0,
12318 image.handle(),
12319 VK_IMAGE_VIEW_TYPE_2D,
12320 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012321 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12322 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012323 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12324 };
12325 VkImageView view;
12326 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12327 ASSERT_VK_SUCCESS(err);
12328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012329 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012330 VkFramebuffer fb;
12331 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12332 ASSERT_VK_SUCCESS(err);
12333
12334 VkCommandBufferAllocateInfo cbai = {};
12335 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12336 cbai.commandPool = m_commandPool;
12337 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12338 cbai.commandBufferCount = 1;
12339
12340 VkCommandBuffer sec_cb;
12341 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12342 ASSERT_VK_SUCCESS(err);
12343 VkCommandBufferBeginInfo cbbi = {};
12344 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012345 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012346 cbii.renderPass = renderPass();
12347 cbii.framebuffer = fb;
12348 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12349 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012350 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 -060012351 cbbi.pInheritanceInfo = &cbii;
12352 vkBeginCommandBuffer(sec_cb, &cbbi);
12353 vkEndCommandBuffer(sec_cb);
12354
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012355 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120012356 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12357 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012358
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012360 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012361 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12362 m_errorMonitor->VerifyFound();
12363 // Cleanup
12364 vkDestroyImageView(m_device->device(), view, NULL);
12365 vkDestroyRenderPass(m_device->device(), rp, NULL);
12366 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12367}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012368
12369TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012370 TEST_DESCRIPTION(
12371 "If logicOp is available on the device, set it to an "
12372 "invalid value. If logicOp is not available, attempt to "
12373 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012374 ASSERT_NO_FATAL_FAILURE(InitState());
12375 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12376
12377 auto features = m_device->phy().features();
12378 // Set the expected error depending on whether or not logicOp available
12379 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12381 "If logic operations feature not "
12382 "enabled, logicOpEnable must be "
12383 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012384 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012386 }
12387 // Create a pipeline using logicOp
12388 VkResult err;
12389
12390 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12391 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12392
12393 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012394 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012395 ASSERT_VK_SUCCESS(err);
12396
12397 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12398 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12399 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012400 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012401 vp_state_ci.pViewports = &vp;
12402 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012403 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012404 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012405
12406 VkPipelineShaderStageCreateInfo shaderStages[2];
12407 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012409 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12410 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012411 shaderStages[0] = vs.GetStageCreateInfo();
12412 shaderStages[1] = fs.GetStageCreateInfo();
12413
12414 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12415 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12416
12417 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12418 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12419 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12420
12421 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12422 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012423 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012424
12425 VkPipelineColorBlendAttachmentState att = {};
12426 att.blendEnable = VK_FALSE;
12427 att.colorWriteMask = 0xf;
12428
12429 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12430 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12431 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12432 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012433 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012434 cb_ci.attachmentCount = 1;
12435 cb_ci.pAttachments = &att;
12436
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012437 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12438 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12439 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12440
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012441 VkGraphicsPipelineCreateInfo gp_ci = {};
12442 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12443 gp_ci.stageCount = 2;
12444 gp_ci.pStages = shaderStages;
12445 gp_ci.pVertexInputState = &vi_ci;
12446 gp_ci.pInputAssemblyState = &ia_ci;
12447 gp_ci.pViewportState = &vp_state_ci;
12448 gp_ci.pRasterizationState = &rs_ci;
12449 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012450 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012451 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12452 gp_ci.layout = pipeline_layout;
12453 gp_ci.renderPass = renderPass();
12454
12455 VkPipelineCacheCreateInfo pc_ci = {};
12456 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12457
12458 VkPipeline pipeline;
12459 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012460 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012461 ASSERT_VK_SUCCESS(err);
12462
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012463 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012464 m_errorMonitor->VerifyFound();
12465 if (VK_SUCCESS == err) {
12466 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12467 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012468 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12469 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12470}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012471#endif // DRAW_STATE_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012472
Tobin Ehlis0788f522015-05-26 16:11:58 -060012473#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012474#if GTEST_IS_THREADSAFE
12475struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012476 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012477 VkEvent event;
12478 bool bailout;
12479};
12480
Karl Schultz6addd812016-02-02 17:17:23 -070012481extern "C" void *AddToCommandBuffer(void *arg) {
12482 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012483
Mike Stroyana6d14942016-07-13 15:10:05 -060012484 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012485 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012486 if (data->bailout) {
12487 break;
12488 }
12489 }
12490 return NULL;
12491}
12492
Karl Schultz6addd812016-02-02 17:17:23 -070012493TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012494 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012495
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012497
Mike Stroyanaccf7692015-05-12 16:00:45 -060012498 ASSERT_NO_FATAL_FAILURE(InitState());
12499 ASSERT_NO_FATAL_FAILURE(InitViewport());
12500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12501
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012502 // Calls AllocateCommandBuffers
12503 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012504
12505 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012506 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012507
12508 VkEventCreateInfo event_info;
12509 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012510 VkResult err;
12511
12512 memset(&event_info, 0, sizeof(event_info));
12513 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12514
Chia-I Wuf7458c52015-10-26 21:10:41 +080012515 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012516 ASSERT_VK_SUCCESS(err);
12517
Mike Stroyanaccf7692015-05-12 16:00:45 -060012518 err = vkResetEvent(device(), event);
12519 ASSERT_VK_SUCCESS(err);
12520
12521 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012522 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012523 data.event = event;
12524 data.bailout = false;
12525 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012526
12527 // First do some correct operations using multiple threads.
12528 // Add many entries to command buffer from another thread.
12529 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12530 // Make non-conflicting calls from this thread at the same time.
12531 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012532 uint32_t count;
12533 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012534 }
12535 test_platform_thread_join(thread, NULL);
12536
12537 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012538 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012539 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012540 // Add many entries to command buffer from this thread at the same time.
12541 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012542
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012543 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012544 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012545
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012546 m_errorMonitor->SetBailout(NULL);
12547
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012548 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012549
Chia-I Wuf7458c52015-10-26 21:10:41 +080012550 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012551}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012552#endif // GTEST_IS_THREADSAFE
12553#endif // THREADING_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012554
Chris Forbes9f7ff632015-05-25 11:13:08 +120012555#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012556TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012557 TEST_DESCRIPTION(
12558 "Test that an error is produced for a spirv module "
12559 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120012560
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012562
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012563 ASSERT_NO_FATAL_FAILURE(InitState());
12564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12565
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012566 VkShaderModule module;
12567 VkShaderModuleCreateInfo moduleCreateInfo;
12568 struct icd_spv_header spv;
12569
12570 spv.magic = ICD_SPV_MAGIC;
12571 spv.version = ICD_SPV_VERSION;
12572 spv.gen_magic = 0;
12573
12574 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12575 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012576 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012577 moduleCreateInfo.codeSize = 4;
12578 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012579 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012580
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012581 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012582}
12583
Karl Schultz6addd812016-02-02 17:17:23 -070012584TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012585 TEST_DESCRIPTION(
12586 "Test that an error is produced for a spirv module "
12587 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120012588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012590
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012591 ASSERT_NO_FATAL_FAILURE(InitState());
12592 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12593
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012594 VkShaderModule module;
12595 VkShaderModuleCreateInfo moduleCreateInfo;
12596 struct icd_spv_header spv;
12597
12598 spv.magic = ~ICD_SPV_MAGIC;
12599 spv.version = ICD_SPV_VERSION;
12600 spv.gen_magic = 0;
12601
12602 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12603 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012604 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012605 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12606 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012607 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012608
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012609 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012610}
12611
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012612#if 0
12613// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012614TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012616 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012617
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012618 ASSERT_NO_FATAL_FAILURE(InitState());
12619 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12620
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012621 VkShaderModule module;
12622 VkShaderModuleCreateInfo moduleCreateInfo;
12623 struct icd_spv_header spv;
12624
12625 spv.magic = ICD_SPV_MAGIC;
12626 spv.version = ~ICD_SPV_VERSION;
12627 spv.gen_magic = 0;
12628
12629 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12630 moduleCreateInfo.pNext = NULL;
12631
Karl Schultz6addd812016-02-02 17:17:23 -070012632 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012633 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12634 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012635 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012636
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012637 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012638}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012639#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012640
Karl Schultz6addd812016-02-02 17:17:23 -070012641TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012642 TEST_DESCRIPTION(
12643 "Test that a warning is produced for a vertex output that "
12644 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012646
Chris Forbes9f7ff632015-05-25 11:13:08 +120012647 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012648 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012649
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012650 char const *vsSource =
12651 "#version 450\n"
12652 "\n"
12653 "layout(location=0) out float x;\n"
12654 "out gl_PerVertex {\n"
12655 " vec4 gl_Position;\n"
12656 "};\n"
12657 "void main(){\n"
12658 " gl_Position = vec4(1);\n"
12659 " x = 0;\n"
12660 "}\n";
12661 char const *fsSource =
12662 "#version 450\n"
12663 "\n"
12664 "layout(location=0) out vec4 color;\n"
12665 "void main(){\n"
12666 " color = vec4(1);\n"
12667 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012668
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012669 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12670 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012671
12672 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012673 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012674 pipe.AddShader(&vs);
12675 pipe.AddShader(&fs);
12676
Chris Forbes9f7ff632015-05-25 11:13:08 +120012677 VkDescriptorSetObj descriptorSet(m_device);
12678 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012679 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012680
Tony Barbour5781e8f2015-08-04 16:23:11 -060012681 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012682
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012683 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012684}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012685
Mark Mueller098c9cb2016-09-08 09:01:57 -060012686TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12687 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12688
12689 ASSERT_NO_FATAL_FAILURE(InitState());
12690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12691
12692 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012693 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012694
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012695 char const *vsSource =
12696 "#version 450\n"
12697 "\n"
12698 "out gl_PerVertex {\n"
12699 " vec4 gl_Position;\n"
12700 "};\n"
12701 "void main(){\n"
12702 " gl_Position = vec4(1);\n"
12703 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012704
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012705 char const *fsSource =
12706 "#version 450\n"
12707 "\n"
12708 "layout (constant_id = 0) const float r = 0.0f;\n"
12709 "layout(location = 0) out vec4 uFragColor;\n"
12710 "void main(){\n"
12711 " uFragColor = vec4(r,1,0,1);\n"
12712 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012713
12714 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12715 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12716
12717 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12718 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12719
12720 VkPipelineLayout pipeline_layout;
12721 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12722
12723 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12724 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12725 vp_state_create_info.viewportCount = 1;
12726 VkViewport viewport = {};
12727 vp_state_create_info.pViewports = &viewport;
12728 vp_state_create_info.scissorCount = 1;
12729 VkRect2D scissors = {};
12730 vp_state_create_info.pScissors = &scissors;
12731
12732 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12733
12734 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12735 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12736 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12737 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12738
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012739 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060012740
12741 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12742 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12743
12744 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12745 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12746 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12747
12748 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12749 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12750 rasterization_state_create_info.pNext = nullptr;
12751 rasterization_state_create_info.lineWidth = 1.0f;
12752 rasterization_state_create_info.rasterizerDiscardEnable = true;
12753
12754 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12755 color_blend_attachment_state.blendEnable = VK_FALSE;
12756 color_blend_attachment_state.colorWriteMask = 0xf;
12757
12758 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12759 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12760 color_blend_state_create_info.attachmentCount = 1;
12761 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12762
12763 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12764 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12765 graphicspipe_create_info.stageCount = 2;
12766 graphicspipe_create_info.pStages = shader_stage_create_info;
12767 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12768 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12769 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12770 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12771 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12772 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12773 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12774 graphicspipe_create_info.layout = pipeline_layout;
12775 graphicspipe_create_info.renderPass = renderPass();
12776
12777 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12778 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12779
12780 VkPipelineCache pipelineCache;
12781 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12782
12783 // This structure maps constant ids to data locations.
12784 const VkSpecializationMapEntry entry =
12785 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012786 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060012787
12788 uint32_t data = 1;
12789
12790 // Set up the info describing spec map and data
12791 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012792 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060012793 };
12794 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12795
12796 VkPipeline pipeline;
12797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12798 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12799 m_errorMonitor->VerifyFound();
12800
12801 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12802 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12803}
12804
12805TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12806 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12807
12808 ASSERT_NO_FATAL_FAILURE(InitState());
12809 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12810
12811 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12812
12813 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12814 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12815 descriptor_pool_type_count[0].descriptorCount = 1;
12816 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12817 descriptor_pool_type_count[1].descriptorCount = 1;
12818
12819 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12820 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12821 descriptor_pool_create_info.maxSets = 1;
12822 descriptor_pool_create_info.poolSizeCount = 2;
12823 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12824 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12825
12826 VkDescriptorPool descriptorset_pool;
12827 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12828
12829 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12830 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12831 descriptorset_layout_binding.descriptorCount = 1;
12832 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12833
12834 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12835 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12836 descriptorset_layout_create_info.bindingCount = 1;
12837 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12838
12839 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012840 ASSERT_VK_SUCCESS(
12841 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012842
12843 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12844 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12845 descriptorset_allocate_info.descriptorSetCount = 1;
12846 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12847 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12848 VkDescriptorSet descriptorset;
12849 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12850
12851 // Challenge core_validation with a non uniform buffer type.
12852 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12853
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012854 char const *vsSource =
12855 "#version 450\n"
12856 "\n"
12857 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12858 " mat4 mvp;\n"
12859 "} ubuf;\n"
12860 "out gl_PerVertex {\n"
12861 " vec4 gl_Position;\n"
12862 "};\n"
12863 "void main(){\n"
12864 " gl_Position = ubuf.mvp * vec4(1);\n"
12865 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012866
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012867 char const *fsSource =
12868 "#version 450\n"
12869 "\n"
12870 "layout(location = 0) out vec4 uFragColor;\n"
12871 "void main(){\n"
12872 " uFragColor = vec4(0,1,0,1);\n"
12873 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012874
12875 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12876 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12877
12878 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12879 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12880 pipeline_layout_create_info.setLayoutCount = 1;
12881 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12882
12883 VkPipelineLayout pipeline_layout;
12884 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12885
12886 VkPipelineObj pipe(m_device);
12887 pipe.AddColorAttachment();
12888 pipe.AddShader(&vs);
12889 pipe.AddShader(&fs);
12890
12891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12892 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12893 m_errorMonitor->VerifyFound();
12894
12895 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12896 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12897 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12898}
12899
12900TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12901 TEST_DESCRIPTION(
12902 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12903
12904 ASSERT_NO_FATAL_FAILURE(InitState());
12905 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12906
12907 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12908
12909 VkDescriptorPoolSize descriptor_pool_type_count = {};
12910 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12911 descriptor_pool_type_count.descriptorCount = 1;
12912
12913 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12914 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12915 descriptor_pool_create_info.maxSets = 1;
12916 descriptor_pool_create_info.poolSizeCount = 1;
12917 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12918 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12919
12920 VkDescriptorPool descriptorset_pool;
12921 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12922
12923 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12924 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12925 descriptorset_layout_binding.descriptorCount = 1;
12926 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12927 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12928
12929 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12930 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12931 descriptorset_layout_create_info.bindingCount = 1;
12932 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12933
12934 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012935 ASSERT_VK_SUCCESS(
12936 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060012937
12938 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12939 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12940 descriptorset_allocate_info.descriptorSetCount = 1;
12941 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12942 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12943 VkDescriptorSet descriptorset;
12944 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12945
12946 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12947
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012948 char const *vsSource =
12949 "#version 450\n"
12950 "\n"
12951 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12952 " mat4 mvp;\n"
12953 "} ubuf;\n"
12954 "out gl_PerVertex {\n"
12955 " vec4 gl_Position;\n"
12956 "};\n"
12957 "void main(){\n"
12958 " gl_Position = ubuf.mvp * vec4(1);\n"
12959 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012960
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012961 char const *fsSource =
12962 "#version 450\n"
12963 "\n"
12964 "layout(location = 0) out vec4 uFragColor;\n"
12965 "void main(){\n"
12966 " uFragColor = vec4(0,1,0,1);\n"
12967 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012968
12969 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12970 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12971
12972 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12973 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12974 pipeline_layout_create_info.setLayoutCount = 1;
12975 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12976
12977 VkPipelineLayout pipeline_layout;
12978 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12979
12980 VkPipelineObj pipe(m_device);
12981 pipe.AddColorAttachment();
12982 pipe.AddShader(&vs);
12983 pipe.AddShader(&fs);
12984
12985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12986 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12987 m_errorMonitor->VerifyFound();
12988
12989 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12990 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12991 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12992}
12993
12994TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012995 TEST_DESCRIPTION(
12996 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12997 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060012998
12999 ASSERT_NO_FATAL_FAILURE(InitState());
13000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13001
13002 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013003 "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 -060013004
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013005 char const *vsSource =
13006 "#version 450\n"
13007 "\n"
13008 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13009 "out gl_PerVertex {\n"
13010 " vec4 gl_Position;\n"
13011 "};\n"
13012 "void main(){\n"
13013 " gl_Position = vec4(consts.x);\n"
13014 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013015
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013016 char const *fsSource =
13017 "#version 450\n"
13018 "\n"
13019 "layout(location = 0) out vec4 uFragColor;\n"
13020 "void main(){\n"
13021 " uFragColor = vec4(0,1,0,1);\n"
13022 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013023
13024 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13026
13027 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13028 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13029
13030 // Set up a push constant range
13031 VkPushConstantRange push_constant_ranges = {};
13032 // Set to the wrong stage to challenge core_validation
13033 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13034 push_constant_ranges.size = 4;
13035
13036 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13037 pipeline_layout_create_info.pushConstantRangeCount = 1;
13038
13039 VkPipelineLayout pipeline_layout;
13040 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13041
13042 VkPipelineObj pipe(m_device);
13043 pipe.AddColorAttachment();
13044 pipe.AddShader(&vs);
13045 pipe.AddShader(&fs);
13046
13047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13048 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13049 m_errorMonitor->VerifyFound();
13050
13051 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13052}
13053
13054TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13055 TEST_DESCRIPTION(
13056 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13057
13058 ASSERT_NO_FATAL_FAILURE(InitState());
13059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13060
13061 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013062 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013063
13064 // Some awkward steps are required to test with custom device features.
13065 std::vector<const char *> device_extension_names;
13066 auto features = m_device->phy().features();
13067 // Disable support for 64 bit floats
13068 features.shaderFloat64 = false;
13069 // The sacrificial device object
13070 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13071
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013072 char const *vsSource =
13073 "#version 450\n"
13074 "\n"
13075 "out gl_PerVertex {\n"
13076 " vec4 gl_Position;\n"
13077 "};\n"
13078 "void main(){\n"
13079 " gl_Position = vec4(1);\n"
13080 "}\n";
13081 char const *fsSource =
13082 "#version 450\n"
13083 "\n"
13084 "layout(location=0) out vec4 color;\n"
13085 "void main(){\n"
13086 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13087 " color = vec4(green);\n"
13088 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013089
13090 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13091 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13092
13093 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013094
13095 VkPipelineObj pipe(&test_device);
13096 pipe.AddColorAttachment();
13097 pipe.AddShader(&vs);
13098 pipe.AddShader(&fs);
13099
13100 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13101 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13102 VkPipelineLayout pipeline_layout;
13103 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13104
13105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13106 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13107 m_errorMonitor->VerifyFound();
13108
13109 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13110}
13111
13112TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13113 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13114
13115 ASSERT_NO_FATAL_FAILURE(InitState());
13116 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13117
13118 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13119
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013120 char const *vsSource =
13121 "#version 450\n"
13122 "\n"
13123 "out gl_PerVertex {\n"
13124 " vec4 gl_Position;\n"
13125 "};\n"
13126 "layout(xfb_buffer = 1) out;"
13127 "void main(){\n"
13128 " gl_Position = vec4(1);\n"
13129 "}\n";
13130 char const *fsSource =
13131 "#version 450\n"
13132 "\n"
13133 "layout(location=0) out vec4 color;\n"
13134 "void main(){\n"
13135 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13136 " color = vec4(green);\n"
13137 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013138
13139 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13140 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13141
13142 VkPipelineObj pipe(m_device);
13143 pipe.AddColorAttachment();
13144 pipe.AddShader(&vs);
13145 pipe.AddShader(&fs);
13146
13147 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13148 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13149 VkPipelineLayout pipeline_layout;
13150 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13151
13152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13153 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13154 m_errorMonitor->VerifyFound();
13155
13156 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13157}
13158
Karl Schultz6addd812016-02-02 17:17:23 -070013159TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013160 TEST_DESCRIPTION(
13161 "Test that an error is produced for a fragment shader input "
13162 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013165
Chris Forbes59cb88d2015-05-25 11:13:13 +120013166 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013168
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013169 char const *vsSource =
13170 "#version 450\n"
13171 "\n"
13172 "out gl_PerVertex {\n"
13173 " vec4 gl_Position;\n"
13174 "};\n"
13175 "void main(){\n"
13176 " gl_Position = vec4(1);\n"
13177 "}\n";
13178 char const *fsSource =
13179 "#version 450\n"
13180 "\n"
13181 "layout(location=0) in float x;\n"
13182 "layout(location=0) out vec4 color;\n"
13183 "void main(){\n"
13184 " color = vec4(x);\n"
13185 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013186
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013187 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13188 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013189
13190 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013191 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013192 pipe.AddShader(&vs);
13193 pipe.AddShader(&fs);
13194
Chris Forbes59cb88d2015-05-25 11:13:13 +120013195 VkDescriptorSetObj descriptorSet(m_device);
13196 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013197 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013198
Tony Barbour5781e8f2015-08-04 16:23:11 -060013199 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013200
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013201 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013202}
13203
Karl Schultz6addd812016-02-02 17:17:23 -070013204TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013205 TEST_DESCRIPTION(
13206 "Test that an error is produced for a fragment shader input "
13207 "within an interace block, which is not present in the outputs "
13208 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013210
13211 ASSERT_NO_FATAL_FAILURE(InitState());
13212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13213
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013214 char const *vsSource =
13215 "#version 450\n"
13216 "\n"
13217 "out gl_PerVertex {\n"
13218 " vec4 gl_Position;\n"
13219 "};\n"
13220 "void main(){\n"
13221 " gl_Position = vec4(1);\n"
13222 "}\n";
13223 char const *fsSource =
13224 "#version 450\n"
13225 "\n"
13226 "in block { layout(location=0) float x; } ins;\n"
13227 "layout(location=0) out vec4 color;\n"
13228 "void main(){\n"
13229 " color = vec4(ins.x);\n"
13230 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013231
13232 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13233 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13234
13235 VkPipelineObj pipe(m_device);
13236 pipe.AddColorAttachment();
13237 pipe.AddShader(&vs);
13238 pipe.AddShader(&fs);
13239
13240 VkDescriptorSetObj descriptorSet(m_device);
13241 descriptorSet.AppendDummy();
13242 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13243
13244 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13245
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013246 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013247}
13248
Karl Schultz6addd812016-02-02 17:17:23 -070013249TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013250 TEST_DESCRIPTION(
13251 "Test that an error is produced for mismatched array sizes "
13252 "across the vertex->fragment shader interface");
13253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13254 "Type mismatch on location 0.0: 'ptr to "
13255 "output arr[2] of float32' vs 'ptr to "
13256 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013257
13258 ASSERT_NO_FATAL_FAILURE(InitState());
13259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13260
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013261 char const *vsSource =
13262 "#version 450\n"
13263 "\n"
13264 "layout(location=0) out float x[2];\n"
13265 "out gl_PerVertex {\n"
13266 " vec4 gl_Position;\n"
13267 "};\n"
13268 "void main(){\n"
13269 " x[0] = 0; x[1] = 0;\n"
13270 " gl_Position = vec4(1);\n"
13271 "}\n";
13272 char const *fsSource =
13273 "#version 450\n"
13274 "\n"
13275 "layout(location=0) in float x[1];\n"
13276 "layout(location=0) out vec4 color;\n"
13277 "void main(){\n"
13278 " color = vec4(x[0]);\n"
13279 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013280
13281 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13282 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13283
13284 VkPipelineObj pipe(m_device);
13285 pipe.AddColorAttachment();
13286 pipe.AddShader(&vs);
13287 pipe.AddShader(&fs);
13288
13289 VkDescriptorSetObj descriptorSet(m_device);
13290 descriptorSet.AppendDummy();
13291 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13292
13293 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13294
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013295 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013296}
13297
Karl Schultz6addd812016-02-02 17:17:23 -070013298TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013299 TEST_DESCRIPTION(
13300 "Test that an error is produced for mismatched types across "
13301 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013303
Chris Forbesb56af562015-05-25 11:13:17 +120013304 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013305 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013306
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013307 char const *vsSource =
13308 "#version 450\n"
13309 "\n"
13310 "layout(location=0) out int x;\n"
13311 "out gl_PerVertex {\n"
13312 " vec4 gl_Position;\n"
13313 "};\n"
13314 "void main(){\n"
13315 " x = 0;\n"
13316 " gl_Position = vec4(1);\n"
13317 "}\n";
13318 char const *fsSource =
13319 "#version 450\n"
13320 "\n"
13321 "layout(location=0) in float x;\n" /* VS writes int */
13322 "layout(location=0) out vec4 color;\n"
13323 "void main(){\n"
13324 " color = vec4(x);\n"
13325 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013326
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013327 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13328 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013329
13330 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013331 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013332 pipe.AddShader(&vs);
13333 pipe.AddShader(&fs);
13334
Chris Forbesb56af562015-05-25 11:13:17 +120013335 VkDescriptorSetObj descriptorSet(m_device);
13336 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013337 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013338
Tony Barbour5781e8f2015-08-04 16:23:11 -060013339 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013340
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013341 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013342}
13343
Karl Schultz6addd812016-02-02 17:17:23 -070013344TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013345 TEST_DESCRIPTION(
13346 "Test that an error is produced for mismatched types across "
13347 "the vertex->fragment shader interface, when the variable is contained within "
13348 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013350
13351 ASSERT_NO_FATAL_FAILURE(InitState());
13352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13353
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013354 char const *vsSource =
13355 "#version 450\n"
13356 "\n"
13357 "out block { layout(location=0) int x; } outs;\n"
13358 "out gl_PerVertex {\n"
13359 " vec4 gl_Position;\n"
13360 "};\n"
13361 "void main(){\n"
13362 " outs.x = 0;\n"
13363 " gl_Position = vec4(1);\n"
13364 "}\n";
13365 char const *fsSource =
13366 "#version 450\n"
13367 "\n"
13368 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13369 "layout(location=0) out vec4 color;\n"
13370 "void main(){\n"
13371 " color = vec4(ins.x);\n"
13372 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013373
13374 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13375 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13376
13377 VkPipelineObj pipe(m_device);
13378 pipe.AddColorAttachment();
13379 pipe.AddShader(&vs);
13380 pipe.AddShader(&fs);
13381
13382 VkDescriptorSetObj descriptorSet(m_device);
13383 descriptorSet.AppendDummy();
13384 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13385
13386 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13387
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013388 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013389}
13390
13391TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013392 TEST_DESCRIPTION(
13393 "Test that an error is produced for location mismatches across "
13394 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
13395 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013396 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 +130013397
13398 ASSERT_NO_FATAL_FAILURE(InitState());
13399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13400
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013401 char const *vsSource =
13402 "#version 450\n"
13403 "\n"
13404 "out block { layout(location=1) float x; } outs;\n"
13405 "out gl_PerVertex {\n"
13406 " vec4 gl_Position;\n"
13407 "};\n"
13408 "void main(){\n"
13409 " outs.x = 0;\n"
13410 " gl_Position = vec4(1);\n"
13411 "}\n";
13412 char const *fsSource =
13413 "#version 450\n"
13414 "\n"
13415 "in block { layout(location=0) float x; } ins;\n"
13416 "layout(location=0) out vec4 color;\n"
13417 "void main(){\n"
13418 " color = vec4(ins.x);\n"
13419 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013420
13421 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13422 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13423
13424 VkPipelineObj pipe(m_device);
13425 pipe.AddColorAttachment();
13426 pipe.AddShader(&vs);
13427 pipe.AddShader(&fs);
13428
13429 VkDescriptorSetObj descriptorSet(m_device);
13430 descriptorSet.AppendDummy();
13431 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13432
13433 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13434
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013435 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013436}
13437
13438TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013439 TEST_DESCRIPTION(
13440 "Test that an error is produced for component mismatches across the "
13441 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
13442 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013443 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 +130013444
13445 ASSERT_NO_FATAL_FAILURE(InitState());
13446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13447
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013448 char const *vsSource =
13449 "#version 450\n"
13450 "\n"
13451 "out block { layout(location=0, component=0) float x; } outs;\n"
13452 "out gl_PerVertex {\n"
13453 " vec4 gl_Position;\n"
13454 "};\n"
13455 "void main(){\n"
13456 " outs.x = 0;\n"
13457 " gl_Position = vec4(1);\n"
13458 "}\n";
13459 char const *fsSource =
13460 "#version 450\n"
13461 "\n"
13462 "in block { layout(location=0, component=1) float x; } ins;\n"
13463 "layout(location=0) out vec4 color;\n"
13464 "void main(){\n"
13465 " color = vec4(ins.x);\n"
13466 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013467
13468 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13469 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13470
13471 VkPipelineObj pipe(m_device);
13472 pipe.AddColorAttachment();
13473 pipe.AddShader(&vs);
13474 pipe.AddShader(&fs);
13475
13476 VkDescriptorSetObj descriptorSet(m_device);
13477 descriptorSet.AppendDummy();
13478 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13479
13480 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13481
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013482 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013483}
13484
Chris Forbes1f3b0152016-11-30 12:48:40 +130013485TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13486 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13487
13488 ASSERT_NO_FATAL_FAILURE(InitState());
13489 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013491 char const *vsSource =
13492 "#version 450\n"
13493 "layout(location=0) out mediump float x;\n"
13494 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13495 char const *fsSource =
13496 "#version 450\n"
13497 "layout(location=0) in highp float x;\n"
13498 "layout(location=0) out vec4 color;\n"
13499 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130013500
13501 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13502 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13503
13504 VkPipelineObj pipe(m_device);
13505 pipe.AddColorAttachment();
13506 pipe.AddShader(&vs);
13507 pipe.AddShader(&fs);
13508
13509 VkDescriptorSetObj descriptorSet(m_device);
13510 descriptorSet.AppendDummy();
13511 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13512
13513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13514
13515 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13516
13517 m_errorMonitor->VerifyFound();
13518}
13519
Chris Forbes870a39e2016-11-30 12:55:56 +130013520TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13521 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13522
13523 ASSERT_NO_FATAL_FAILURE(InitState());
13524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13525
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013526 char const *vsSource =
13527 "#version 450\n"
13528 "out block { layout(location=0) mediump float x; };\n"
13529 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13530 char const *fsSource =
13531 "#version 450\n"
13532 "in block { layout(location=0) highp float x; };\n"
13533 "layout(location=0) out vec4 color;\n"
13534 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130013535
13536 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13537 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13538
13539 VkPipelineObj pipe(m_device);
13540 pipe.AddColorAttachment();
13541 pipe.AddShader(&vs);
13542 pipe.AddShader(&fs);
13543
13544 VkDescriptorSetObj descriptorSet(m_device);
13545 descriptorSet.AppendDummy();
13546 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13547
13548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13549
13550 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13551
13552 m_errorMonitor->VerifyFound();
13553}
13554
Karl Schultz6addd812016-02-02 17:17:23 -070013555TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013556 TEST_DESCRIPTION(
13557 "Test that a warning is produced for a vertex attribute which is "
13558 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013560
Chris Forbesde136e02015-05-25 11:13:28 +120013561 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013563
13564 VkVertexInputBindingDescription input_binding;
13565 memset(&input_binding, 0, sizeof(input_binding));
13566
13567 VkVertexInputAttributeDescription input_attrib;
13568 memset(&input_attrib, 0, sizeof(input_attrib));
13569 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13570
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013571 char const *vsSource =
13572 "#version 450\n"
13573 "\n"
13574 "out gl_PerVertex {\n"
13575 " vec4 gl_Position;\n"
13576 "};\n"
13577 "void main(){\n"
13578 " gl_Position = vec4(1);\n"
13579 "}\n";
13580 char const *fsSource =
13581 "#version 450\n"
13582 "\n"
13583 "layout(location=0) out vec4 color;\n"
13584 "void main(){\n"
13585 " color = vec4(1);\n"
13586 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013587
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013588 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13589 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013590
13591 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013592 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013593 pipe.AddShader(&vs);
13594 pipe.AddShader(&fs);
13595
13596 pipe.AddVertexInputBindings(&input_binding, 1);
13597 pipe.AddVertexInputAttribs(&input_attrib, 1);
13598
Chris Forbesde136e02015-05-25 11:13:28 +120013599 VkDescriptorSetObj descriptorSet(m_device);
13600 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013601 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013602
Tony Barbour5781e8f2015-08-04 16:23:11 -060013603 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013604
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013605 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013606}
13607
Karl Schultz6addd812016-02-02 17:17:23 -070013608TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013609 TEST_DESCRIPTION(
13610 "Test that a warning is produced for a location mismatch on "
13611 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013613
13614 ASSERT_NO_FATAL_FAILURE(InitState());
13615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13616
13617 VkVertexInputBindingDescription input_binding;
13618 memset(&input_binding, 0, sizeof(input_binding));
13619
13620 VkVertexInputAttributeDescription input_attrib;
13621 memset(&input_attrib, 0, sizeof(input_attrib));
13622 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13623
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013624 char const *vsSource =
13625 "#version 450\n"
13626 "\n"
13627 "layout(location=1) in float x;\n"
13628 "out gl_PerVertex {\n"
13629 " vec4 gl_Position;\n"
13630 "};\n"
13631 "void main(){\n"
13632 " gl_Position = vec4(x);\n"
13633 "}\n";
13634 char const *fsSource =
13635 "#version 450\n"
13636 "\n"
13637 "layout(location=0) out vec4 color;\n"
13638 "void main(){\n"
13639 " color = vec4(1);\n"
13640 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013641
13642 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13643 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13644
13645 VkPipelineObj pipe(m_device);
13646 pipe.AddColorAttachment();
13647 pipe.AddShader(&vs);
13648 pipe.AddShader(&fs);
13649
13650 pipe.AddVertexInputBindings(&input_binding, 1);
13651 pipe.AddVertexInputAttribs(&input_attrib, 1);
13652
13653 VkDescriptorSetObj descriptorSet(m_device);
13654 descriptorSet.AppendDummy();
13655 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13656
13657 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13658
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013659 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013660}
13661
Karl Schultz6addd812016-02-02 17:17:23 -070013662TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013663 TEST_DESCRIPTION(
13664 "Test that an error is produced for a vertex shader input which is not "
13665 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13667 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013668
Chris Forbes62e8e502015-05-25 11:13:29 +120013669 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013670 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013671
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013672 char const *vsSource =
13673 "#version 450\n"
13674 "\n"
13675 "layout(location=0) in vec4 x;\n" /* not provided */
13676 "out gl_PerVertex {\n"
13677 " vec4 gl_Position;\n"
13678 "};\n"
13679 "void main(){\n"
13680 " gl_Position = x;\n"
13681 "}\n";
13682 char const *fsSource =
13683 "#version 450\n"
13684 "\n"
13685 "layout(location=0) out vec4 color;\n"
13686 "void main(){\n"
13687 " color = vec4(1);\n"
13688 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013689
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013690 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13691 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013692
13693 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013694 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013695 pipe.AddShader(&vs);
13696 pipe.AddShader(&fs);
13697
Chris Forbes62e8e502015-05-25 11:13:29 +120013698 VkDescriptorSetObj descriptorSet(m_device);
13699 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013700 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013701
Tony Barbour5781e8f2015-08-04 16:23:11 -060013702 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013703
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013704 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013705}
13706
Karl Schultz6addd812016-02-02 17:17:23 -070013707TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013708 TEST_DESCRIPTION(
13709 "Test that an error is produced for a mismatch between the "
13710 "fundamental type (float/int/uint) of an attribute and the "
13711 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013712 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 -060013713
Chris Forbesc97d98e2015-05-25 11:13:31 +120013714 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013715 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013716
13717 VkVertexInputBindingDescription input_binding;
13718 memset(&input_binding, 0, sizeof(input_binding));
13719
13720 VkVertexInputAttributeDescription input_attrib;
13721 memset(&input_attrib, 0, sizeof(input_attrib));
13722 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13723
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013724 char const *vsSource =
13725 "#version 450\n"
13726 "\n"
13727 "layout(location=0) in int x;\n" /* attrib provided float */
13728 "out gl_PerVertex {\n"
13729 " vec4 gl_Position;\n"
13730 "};\n"
13731 "void main(){\n"
13732 " gl_Position = vec4(x);\n"
13733 "}\n";
13734 char const *fsSource =
13735 "#version 450\n"
13736 "\n"
13737 "layout(location=0) out vec4 color;\n"
13738 "void main(){\n"
13739 " color = vec4(1);\n"
13740 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013741
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013742 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13743 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013744
13745 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013746 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013747 pipe.AddShader(&vs);
13748 pipe.AddShader(&fs);
13749
13750 pipe.AddVertexInputBindings(&input_binding, 1);
13751 pipe.AddVertexInputAttribs(&input_attrib, 1);
13752
Chris Forbesc97d98e2015-05-25 11:13:31 +120013753 VkDescriptorSetObj descriptorSet(m_device);
13754 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013755 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013756
Tony Barbour5781e8f2015-08-04 16:23:11 -060013757 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013758
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013759 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013760}
13761
Chris Forbesc68b43c2016-04-06 11:18:47 +120013762TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013763 TEST_DESCRIPTION(
13764 "Test that an error is produced for a pipeline containing multiple "
13765 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13767 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013768
13769 ASSERT_NO_FATAL_FAILURE(InitState());
13770 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13771
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013772 char const *vsSource =
13773 "#version 450\n"
13774 "\n"
13775 "out gl_PerVertex {\n"
13776 " vec4 gl_Position;\n"
13777 "};\n"
13778 "void main(){\n"
13779 " gl_Position = vec4(1);\n"
13780 "}\n";
13781 char const *fsSource =
13782 "#version 450\n"
13783 "\n"
13784 "layout(location=0) out vec4 color;\n"
13785 "void main(){\n"
13786 " color = vec4(1);\n"
13787 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013788
13789 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13790 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13791
13792 VkPipelineObj pipe(m_device);
13793 pipe.AddColorAttachment();
13794 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013795 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013796 pipe.AddShader(&fs);
13797
13798 VkDescriptorSetObj descriptorSet(m_device);
13799 descriptorSet.AppendDummy();
13800 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13801
13802 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13803
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013804 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013805}
13806
Chris Forbes82ff92a2016-09-09 10:50:24 +120013807TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120013809
13810 ASSERT_NO_FATAL_FAILURE(InitState());
13811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13812
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013813 char const *vsSource =
13814 "#version 450\n"
13815 "out gl_PerVertex {\n"
13816 " vec4 gl_Position;\n"
13817 "};\n"
13818 "void main(){\n"
13819 " gl_Position = vec4(0);\n"
13820 "}\n";
13821 char const *fsSource =
13822 "#version 450\n"
13823 "\n"
13824 "layout(location=0) out vec4 color;\n"
13825 "void main(){\n"
13826 " color = vec4(1);\n"
13827 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120013828
13829 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13830 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13831
13832 VkPipelineObj pipe(m_device);
13833 pipe.AddColorAttachment();
13834 pipe.AddShader(&vs);
13835 pipe.AddShader(&fs);
13836
13837 VkDescriptorSetObj descriptorSet(m_device);
13838 descriptorSet.AppendDummy();
13839 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13840
13841 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13842
13843 m_errorMonitor->VerifyFound();
13844}
13845
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013846TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13848 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13849 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013850
13851 ASSERT_NO_FATAL_FAILURE(InitState());
13852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13853
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013854 char const *vsSource =
13855 "#version 450\n"
13856 "void main(){ gl_Position = vec4(0); }\n";
13857 char const *fsSource =
13858 "#version 450\n"
13859 "\n"
13860 "layout(location=0) out vec4 color;\n"
13861 "void main(){\n"
13862 " color = vec4(1);\n"
13863 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013864
13865 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13866 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13867
13868 VkPipelineObj pipe(m_device);
13869 pipe.AddColorAttachment();
13870 pipe.AddShader(&vs);
13871 pipe.AddShader(&fs);
13872
13873 VkDescriptorSetObj descriptorSet(m_device);
13874 descriptorSet.AppendDummy();
13875 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13876
13877 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013878 {
13879 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13880 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13881 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013882 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013883 {
13884 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13885 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
13886 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013887 },
13888 };
13889 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013890 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013891 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013892 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
13893 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013894 VkRenderPass rp;
13895 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13896 ASSERT_VK_SUCCESS(err);
13897
13898 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13899
13900 m_errorMonitor->VerifyFound();
13901
13902 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13903}
13904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013905TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013906 TEST_DESCRIPTION(
13907 "Test that an error is produced for a variable output from "
13908 "the TCS without the patch decoration, but consumed in the TES "
13909 "with the decoration.");
13910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13911 "is per-vertex in tessellation control shader stage "
13912 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013913
13914 ASSERT_NO_FATAL_FAILURE(InitState());
13915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13916
Chris Forbesc1e852d2016-04-04 19:26:42 +120013917 if (!m_device->phy().features().tessellationShader) {
13918 printf("Device does not support tessellation shaders; skipped.\n");
13919 return;
13920 }
13921
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013922 char const *vsSource =
13923 "#version 450\n"
13924 "void main(){}\n";
13925 char const *tcsSource =
13926 "#version 450\n"
13927 "layout(location=0) out int x[];\n"
13928 "layout(vertices=3) out;\n"
13929 "void main(){\n"
13930 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13931 " gl_TessLevelInner[0] = 1;\n"
13932 " x[gl_InvocationID] = gl_InvocationID;\n"
13933 "}\n";
13934 char const *tesSource =
13935 "#version 450\n"
13936 "layout(triangles, equal_spacing, cw) in;\n"
13937 "layout(location=0) patch in int x;\n"
13938 "out gl_PerVertex { vec4 gl_Position; };\n"
13939 "void main(){\n"
13940 " gl_Position.xyz = gl_TessCoord;\n"
13941 " gl_Position.w = x;\n"
13942 "}\n";
13943 char const *fsSource =
13944 "#version 450\n"
13945 "layout(location=0) out vec4 color;\n"
13946 "void main(){\n"
13947 " color = vec4(1);\n"
13948 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013949
13950 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13951 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13952 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13953 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13954
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013955 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13956 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013958 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013959
13960 VkPipelineObj pipe(m_device);
13961 pipe.SetInputAssembly(&iasci);
13962 pipe.SetTessellation(&tsci);
13963 pipe.AddColorAttachment();
13964 pipe.AddShader(&vs);
13965 pipe.AddShader(&tcs);
13966 pipe.AddShader(&tes);
13967 pipe.AddShader(&fs);
13968
13969 VkDescriptorSetObj descriptorSet(m_device);
13970 descriptorSet.AppendDummy();
13971 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13972
13973 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13974
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013975 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013976}
13977
Karl Schultz6addd812016-02-02 17:17:23 -070013978TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013979 TEST_DESCRIPTION(
13980 "Test that an error is produced for a vertex attribute setup where multiple "
13981 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13983 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013984
Chris Forbes280ba2c2015-06-12 11:16:41 +120013985 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013987
13988 /* Two binding descriptions for binding 0 */
13989 VkVertexInputBindingDescription input_bindings[2];
13990 memset(input_bindings, 0, sizeof(input_bindings));
13991
13992 VkVertexInputAttributeDescription input_attrib;
13993 memset(&input_attrib, 0, sizeof(input_attrib));
13994 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13995
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013996 char const *vsSource =
13997 "#version 450\n"
13998 "\n"
13999 "layout(location=0) in float x;\n" /* attrib provided float */
14000 "out gl_PerVertex {\n"
14001 " vec4 gl_Position;\n"
14002 "};\n"
14003 "void main(){\n"
14004 " gl_Position = vec4(x);\n"
14005 "}\n";
14006 char const *fsSource =
14007 "#version 450\n"
14008 "\n"
14009 "layout(location=0) out vec4 color;\n"
14010 "void main(){\n"
14011 " color = vec4(1);\n"
14012 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014013
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014014 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14015 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014016
14017 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014018 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014019 pipe.AddShader(&vs);
14020 pipe.AddShader(&fs);
14021
14022 pipe.AddVertexInputBindings(input_bindings, 2);
14023 pipe.AddVertexInputAttribs(&input_attrib, 1);
14024
Chris Forbes280ba2c2015-06-12 11:16:41 +120014025 VkDescriptorSetObj descriptorSet(m_device);
14026 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014027 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014028
Tony Barbour5781e8f2015-08-04 16:23:11 -060014029 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014030
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014031 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014032}
Chris Forbes8f68b562015-05-25 11:13:32 +120014033
Karl Schultz6addd812016-02-02 17:17:23 -070014034TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014035 TEST_DESCRIPTION(
14036 "Test that an error is produced for a fragment shader which does not "
14037 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014039
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014040 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014041
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014042 char const *vsSource =
14043 "#version 450\n"
14044 "\n"
14045 "out gl_PerVertex {\n"
14046 " vec4 gl_Position;\n"
14047 "};\n"
14048 "void main(){\n"
14049 " gl_Position = vec4(1);\n"
14050 "}\n";
14051 char const *fsSource =
14052 "#version 450\n"
14053 "\n"
14054 "void main(){\n"
14055 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014056
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014057 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14058 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014059
14060 VkPipelineObj pipe(m_device);
14061 pipe.AddShader(&vs);
14062 pipe.AddShader(&fs);
14063
Chia-I Wu08accc62015-07-07 11:50:03 +080014064 /* set up CB 0, not written */
14065 pipe.AddColorAttachment();
14066 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014067
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014068 VkDescriptorSetObj descriptorSet(m_device);
14069 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014070 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014071
Tony Barbour5781e8f2015-08-04 16:23:11 -060014072 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014073
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014074 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014075}
14076
Karl Schultz6addd812016-02-02 17:17:23 -070014077TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014078 TEST_DESCRIPTION(
14079 "Test that a warning is produced for a fragment shader which provides a spurious "
14080 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014082 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014083
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014084 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014085
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014086 char const *vsSource =
14087 "#version 450\n"
14088 "\n"
14089 "out gl_PerVertex {\n"
14090 " vec4 gl_Position;\n"
14091 "};\n"
14092 "void main(){\n"
14093 " gl_Position = vec4(1);\n"
14094 "}\n";
14095 char const *fsSource =
14096 "#version 450\n"
14097 "\n"
14098 "layout(location=0) out vec4 x;\n"
14099 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14100 "void main(){\n"
14101 " x = vec4(1);\n"
14102 " y = vec4(1);\n"
14103 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014104
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014105 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14106 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014107
14108 VkPipelineObj pipe(m_device);
14109 pipe.AddShader(&vs);
14110 pipe.AddShader(&fs);
14111
Chia-I Wu08accc62015-07-07 11:50:03 +080014112 /* set up CB 0, not written */
14113 pipe.AddColorAttachment();
14114 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014115 /* FS writes CB 1, but we don't configure it */
14116
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014117 VkDescriptorSetObj descriptorSet(m_device);
14118 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014119 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014120
Tony Barbour5781e8f2015-08-04 16:23:11 -060014121 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014122
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014123 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014124}
14125
Karl Schultz6addd812016-02-02 17:17:23 -070014126TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014127 TEST_DESCRIPTION(
14128 "Test that an error is produced for a mismatch between the fundamental "
14129 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014131
Chris Forbesa36d69e2015-05-25 11:13:44 +120014132 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014133
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014134 char const *vsSource =
14135 "#version 450\n"
14136 "\n"
14137 "out gl_PerVertex {\n"
14138 " vec4 gl_Position;\n"
14139 "};\n"
14140 "void main(){\n"
14141 " gl_Position = vec4(1);\n"
14142 "}\n";
14143 char const *fsSource =
14144 "#version 450\n"
14145 "\n"
14146 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14147 "void main(){\n"
14148 " x = ivec4(1);\n"
14149 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014150
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014151 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14152 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014153
14154 VkPipelineObj pipe(m_device);
14155 pipe.AddShader(&vs);
14156 pipe.AddShader(&fs);
14157
Chia-I Wu08accc62015-07-07 11:50:03 +080014158 /* set up CB 0; type is UNORM by default */
14159 pipe.AddColorAttachment();
14160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014161
Chris Forbesa36d69e2015-05-25 11:13:44 +120014162 VkDescriptorSetObj descriptorSet(m_device);
14163 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014165
Tony Barbour5781e8f2015-08-04 16:23:11 -060014166 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014167
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014168 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014169}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014170
Karl Schultz6addd812016-02-02 17:17:23 -070014171TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014172 TEST_DESCRIPTION(
14173 "Test that an error is produced for a shader consuming a uniform "
14174 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014176
Chris Forbes556c76c2015-08-14 12:04:59 +120014177 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014178
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014179 char const *vsSource =
14180 "#version 450\n"
14181 "\n"
14182 "out gl_PerVertex {\n"
14183 " vec4 gl_Position;\n"
14184 "};\n"
14185 "void main(){\n"
14186 " gl_Position = vec4(1);\n"
14187 "}\n";
14188 char const *fsSource =
14189 "#version 450\n"
14190 "\n"
14191 "layout(location=0) out vec4 x;\n"
14192 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14193 "void main(){\n"
14194 " x = vec4(bar.y);\n"
14195 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014196
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014197 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14198 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014199
Chris Forbes556c76c2015-08-14 12:04:59 +120014200 VkPipelineObj pipe(m_device);
14201 pipe.AddShader(&vs);
14202 pipe.AddShader(&fs);
14203
14204 /* set up CB 0; type is UNORM by default */
14205 pipe.AddColorAttachment();
14206 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14207
14208 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014209 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014210
14211 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14212
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014213 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014214}
14215
Chris Forbes5c59e902016-02-26 16:56:09 +130014216TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014217 TEST_DESCRIPTION(
14218 "Test that an error is produced for a shader consuming push constants "
14219 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014221
14222 ASSERT_NO_FATAL_FAILURE(InitState());
14223
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014224 char const *vsSource =
14225 "#version 450\n"
14226 "\n"
14227 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14228 "out gl_PerVertex {\n"
14229 " vec4 gl_Position;\n"
14230 "};\n"
14231 "void main(){\n"
14232 " gl_Position = vec4(consts.x);\n"
14233 "}\n";
14234 char const *fsSource =
14235 "#version 450\n"
14236 "\n"
14237 "layout(location=0) out vec4 x;\n"
14238 "void main(){\n"
14239 " x = vec4(1);\n"
14240 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014241
14242 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14243 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14244
14245 VkPipelineObj pipe(m_device);
14246 pipe.AddShader(&vs);
14247 pipe.AddShader(&fs);
14248
14249 /* set up CB 0; type is UNORM by default */
14250 pipe.AddColorAttachment();
14251 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14252
14253 VkDescriptorSetObj descriptorSet(m_device);
14254 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14255
14256 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14257
14258 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014259 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014260}
14261
Chris Forbes3fb17902016-08-22 14:57:55 +120014262TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014263 TEST_DESCRIPTION(
14264 "Test that an error is produced for a shader consuming an input attachment "
14265 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14267 "consumes input attachment index 0 but not provided in subpass");
14268
14269 ASSERT_NO_FATAL_FAILURE(InitState());
14270
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014271 char const *vsSource =
14272 "#version 450\n"
14273 "\n"
14274 "out gl_PerVertex {\n"
14275 " vec4 gl_Position;\n"
14276 "};\n"
14277 "void main(){\n"
14278 " gl_Position = vec4(1);\n"
14279 "}\n";
14280 char const *fsSource =
14281 "#version 450\n"
14282 "\n"
14283 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14284 "layout(location=0) out vec4 color;\n"
14285 "void main() {\n"
14286 " color = subpassLoad(x);\n"
14287 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014288
14289 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14290 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14291
14292 VkPipelineObj pipe(m_device);
14293 pipe.AddShader(&vs);
14294 pipe.AddShader(&fs);
14295 pipe.AddColorAttachment();
14296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14297
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014298 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14299 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014300 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014301 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014302 ASSERT_VK_SUCCESS(err);
14303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014304 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014305 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014306 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014307 ASSERT_VK_SUCCESS(err);
14308
14309 // error here.
14310 pipe.CreateVKPipeline(pl, renderPass());
14311
14312 m_errorMonitor->VerifyFound();
14313
14314 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14315 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14316}
14317
Chris Forbes5a9a0472016-08-22 16:02:09 +120014318TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014319 TEST_DESCRIPTION(
14320 "Test that an error is produced for a shader consuming an input attachment "
14321 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14323 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14324
14325 ASSERT_NO_FATAL_FAILURE(InitState());
14326
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014327 char const *vsSource =
14328 "#version 450\n"
14329 "\n"
14330 "out gl_PerVertex {\n"
14331 " vec4 gl_Position;\n"
14332 "};\n"
14333 "void main(){\n"
14334 " gl_Position = vec4(1);\n"
14335 "}\n";
14336 char const *fsSource =
14337 "#version 450\n"
14338 "\n"
14339 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14340 "layout(location=0) out vec4 color;\n"
14341 "void main() {\n"
14342 " color = subpassLoad(x);\n"
14343 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014344
14345 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14346 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14347
14348 VkPipelineObj pipe(m_device);
14349 pipe.AddShader(&vs);
14350 pipe.AddShader(&fs);
14351 pipe.AddColorAttachment();
14352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014354 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14355 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014356 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014357 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014358 ASSERT_VK_SUCCESS(err);
14359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014360 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014361 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014362 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014363 ASSERT_VK_SUCCESS(err);
14364
14365 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014366 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14367 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14368 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14369 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14370 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 +120014371 };
14372 VkAttachmentReference color = {
14373 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14374 };
14375 VkAttachmentReference input = {
14376 1, VK_IMAGE_LAYOUT_GENERAL,
14377 };
14378
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014379 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014381 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014382 VkRenderPass rp;
14383 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14384 ASSERT_VK_SUCCESS(err);
14385
14386 // error here.
14387 pipe.CreateVKPipeline(pl, rp);
14388
14389 m_errorMonitor->VerifyFound();
14390
14391 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14392 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14393 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14394}
14395
Chris Forbes541f7b02016-08-22 15:30:27 +120014396TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014397 TEST_DESCRIPTION(
14398 "Test that an error is produced for a shader consuming an input attachment "
14399 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120014400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014401 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014402
14403 ASSERT_NO_FATAL_FAILURE(InitState());
14404
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014405 char const *vsSource =
14406 "#version 450\n"
14407 "\n"
14408 "out gl_PerVertex {\n"
14409 " vec4 gl_Position;\n"
14410 "};\n"
14411 "void main(){\n"
14412 " gl_Position = vec4(1);\n"
14413 "}\n";
14414 char const *fsSource =
14415 "#version 450\n"
14416 "\n"
14417 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
14418 "layout(location=0) out vec4 color;\n"
14419 "void main() {\n"
14420 " color = subpassLoad(xs[0]);\n"
14421 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014422
14423 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14424 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14425
14426 VkPipelineObj pipe(m_device);
14427 pipe.AddShader(&vs);
14428 pipe.AddShader(&fs);
14429 pipe.AddColorAttachment();
14430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014432 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14433 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014434 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014435 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014436 ASSERT_VK_SUCCESS(err);
14437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014438 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014439 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014440 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014441 ASSERT_VK_SUCCESS(err);
14442
14443 // error here.
14444 pipe.CreateVKPipeline(pl, renderPass());
14445
14446 m_errorMonitor->VerifyFound();
14447
14448 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14449 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14450}
14451
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014452TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014453 TEST_DESCRIPTION(
14454 "Test that an error is produced for a compute pipeline consuming a "
14455 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014457
14458 ASSERT_NO_FATAL_FAILURE(InitState());
14459
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014460 char const *csSource =
14461 "#version 450\n"
14462 "\n"
14463 "layout(local_size_x=1) in;\n"
14464 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14465 "void main(){\n"
14466 " x = vec4(1);\n"
14467 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014468
14469 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14470
14471 VkDescriptorSetObj descriptorSet(m_device);
14472 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14473
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014474 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14475 nullptr,
14476 0,
14477 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14478 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14479 descriptorSet.GetPipelineLayout(),
14480 VK_NULL_HANDLE,
14481 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014482
14483 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014484 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014485
14486 m_errorMonitor->VerifyFound();
14487
14488 if (err == VK_SUCCESS) {
14489 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14490 }
14491}
14492
Chris Forbes22a9b092016-07-19 14:34:05 +120014493TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014494 TEST_DESCRIPTION(
14495 "Test that an error is produced for a pipeline consuming a "
14496 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14498 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014499
14500 ASSERT_NO_FATAL_FAILURE(InitState());
14501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014502 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14503 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014504 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014505 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014506 ASSERT_VK_SUCCESS(err);
14507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014508 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014509 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014510 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014511 ASSERT_VK_SUCCESS(err);
14512
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014513 char const *csSource =
14514 "#version 450\n"
14515 "\n"
14516 "layout(local_size_x=1) in;\n"
14517 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14518 "void main() {\n"
14519 " x.x = 1.0f;\n"
14520 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014521 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14522
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014523 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14524 nullptr,
14525 0,
14526 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14527 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14528 pl,
14529 VK_NULL_HANDLE,
14530 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014531
14532 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014533 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014534
14535 m_errorMonitor->VerifyFound();
14536
14537 if (err == VK_SUCCESS) {
14538 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14539 }
14540
14541 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14542 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14543}
14544
Chris Forbes50020592016-07-27 13:52:41 +120014545TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014546 TEST_DESCRIPTION(
14547 "Test that an error is produced when an image view type "
14548 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120014549
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014550 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 +120014551
14552 ASSERT_NO_FATAL_FAILURE(InitState());
14553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14554
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014555 char const *vsSource =
14556 "#version 450\n"
14557 "\n"
14558 "out gl_PerVertex { vec4 gl_Position; };\n"
14559 "void main() { gl_Position = vec4(0); }\n";
14560 char const *fsSource =
14561 "#version 450\n"
14562 "\n"
14563 "layout(set=0, binding=0) uniform sampler3D s;\n"
14564 "layout(location=0) out vec4 color;\n"
14565 "void main() {\n"
14566 " color = texture(s, vec3(0));\n"
14567 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014568 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14569 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14570
14571 VkPipelineObj pipe(m_device);
14572 pipe.AddShader(&vs);
14573 pipe.AddShader(&fs);
14574 pipe.AddColorAttachment();
14575
14576 VkTextureObj texture(m_device, nullptr);
14577 VkSamplerObj sampler(m_device);
14578
14579 VkDescriptorSetObj descriptorSet(m_device);
14580 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14581 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14582
14583 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14584 ASSERT_VK_SUCCESS(err);
14585
Tony Barbour552f6c02016-12-21 14:34:07 -070014586 m_commandBuffer->BeginCommandBuffer();
14587 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014588
14589 m_commandBuffer->BindPipeline(pipe);
14590 m_commandBuffer->BindDescriptorSet(descriptorSet);
14591
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014592 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014593 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014594 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014595 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14596
14597 // error produced here.
14598 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14599
14600 m_errorMonitor->VerifyFound();
14601
Tony Barbour552f6c02016-12-21 14:34:07 -070014602 m_commandBuffer->EndRenderPass();
14603 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014604}
14605
Chris Forbes5533bfc2016-07-27 14:12:34 +120014606TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014607 TEST_DESCRIPTION(
14608 "Test that an error is produced when a multisampled images "
14609 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014610
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014612
14613 ASSERT_NO_FATAL_FAILURE(InitState());
14614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14615
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014616 char const *vsSource =
14617 "#version 450\n"
14618 "\n"
14619 "out gl_PerVertex { vec4 gl_Position; };\n"
14620 "void main() { gl_Position = vec4(0); }\n";
14621 char const *fsSource =
14622 "#version 450\n"
14623 "\n"
14624 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14625 "layout(location=0) out vec4 color;\n"
14626 "void main() {\n"
14627 " color = texelFetch(s, ivec2(0), 0);\n"
14628 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014629 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14630 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14631
14632 VkPipelineObj pipe(m_device);
14633 pipe.AddShader(&vs);
14634 pipe.AddShader(&fs);
14635 pipe.AddColorAttachment();
14636
14637 VkTextureObj texture(m_device, nullptr);
14638 VkSamplerObj sampler(m_device);
14639
14640 VkDescriptorSetObj descriptorSet(m_device);
14641 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14642 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14643
14644 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14645 ASSERT_VK_SUCCESS(err);
14646
Tony Barbour552f6c02016-12-21 14:34:07 -070014647 m_commandBuffer->BeginCommandBuffer();
14648 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014649
14650 m_commandBuffer->BindPipeline(pipe);
14651 m_commandBuffer->BindDescriptorSet(descriptorSet);
14652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014653 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014654 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014655 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014656 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14657
14658 // error produced here.
14659 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14660
14661 m_errorMonitor->VerifyFound();
14662
Tony Barbour552f6c02016-12-21 14:34:07 -070014663 m_commandBuffer->EndRenderPass();
14664 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014665}
14666
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014667#endif // SHADER_CHECKER_TESTS
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014668
14669#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014670TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014672
14673 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014674
14675 // Create an image
14676 VkImage image;
14677
Karl Schultz6addd812016-02-02 17:17:23 -070014678 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14679 const int32_t tex_width = 32;
14680 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014681
14682 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014683 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14684 image_create_info.pNext = NULL;
14685 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14686 image_create_info.format = tex_format;
14687 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014688 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014689 image_create_info.extent.depth = 1;
14690 image_create_info.mipLevels = 1;
14691 image_create_info.arrayLayers = 1;
14692 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14693 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14694 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14695 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014696
14697 // Introduce error by sending down a bogus width extent
14698 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014699 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014700
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014701 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014702}
14703
Mark Youngc48c4c12016-04-11 14:26:49 -060014704TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070014705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060014706
14707 ASSERT_NO_FATAL_FAILURE(InitState());
14708
14709 // Create an image
14710 VkImage image;
14711
14712 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14713 const int32_t tex_width = 32;
14714 const int32_t tex_height = 32;
14715
14716 VkImageCreateInfo image_create_info = {};
14717 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14718 image_create_info.pNext = NULL;
14719 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14720 image_create_info.format = tex_format;
14721 image_create_info.extent.width = tex_width;
14722 image_create_info.extent.height = tex_height;
14723 image_create_info.extent.depth = 1;
14724 image_create_info.mipLevels = 1;
14725 image_create_info.arrayLayers = 1;
14726 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14727 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14728 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14729 image_create_info.flags = 0;
14730
14731 // Introduce error by sending down a bogus width extent
14732 image_create_info.extent.width = 0;
14733 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14734
14735 m_errorMonitor->VerifyFound();
14736}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014737#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014738
Tobin Ehliscde08892015-09-22 10:11:37 -060014739#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014740
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014741TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014742 TEST_DESCRIPTION(
14743 "Create a render pass with an attachment description "
14744 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014745
14746 ASSERT_NO_FATAL_FAILURE(InitState());
14747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014750
14751 VkAttachmentReference color_attach = {};
14752 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14753 color_attach.attachment = 0;
14754 VkSubpassDescription subpass = {};
14755 subpass.colorAttachmentCount = 1;
14756 subpass.pColorAttachments = &color_attach;
14757
14758 VkRenderPassCreateInfo rpci = {};
14759 rpci.subpassCount = 1;
14760 rpci.pSubpasses = &subpass;
14761 rpci.attachmentCount = 1;
14762 VkAttachmentDescription attach_desc = {};
14763 attach_desc.format = VK_FORMAT_UNDEFINED;
14764 rpci.pAttachments = &attach_desc;
14765 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14766 VkRenderPass rp;
14767 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14768
14769 m_errorMonitor->VerifyFound();
14770
14771 if (result == VK_SUCCESS) {
14772 vkDestroyRenderPass(m_device->device(), rp, NULL);
14773 }
14774}
14775
Karl Schultz6addd812016-02-02 17:17:23 -070014776TEST_F(VkLayerTest, InvalidImageView) {
14777 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014778
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014780
Tobin Ehliscde08892015-09-22 10:11:37 -060014781 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014782
Mike Stroyana3082432015-09-25 13:39:21 -060014783 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014784 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014785
Karl Schultz6addd812016-02-02 17:17:23 -070014786 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14787 const int32_t tex_width = 32;
14788 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014789
14790 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014791 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14792 image_create_info.pNext = NULL;
14793 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14794 image_create_info.format = tex_format;
14795 image_create_info.extent.width = tex_width;
14796 image_create_info.extent.height = tex_height;
14797 image_create_info.extent.depth = 1;
14798 image_create_info.mipLevels = 1;
14799 image_create_info.arrayLayers = 1;
14800 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14801 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14802 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14803 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014804
Chia-I Wuf7458c52015-10-26 21:10:41 +080014805 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014806 ASSERT_VK_SUCCESS(err);
14807
14808 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014809 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014810 image_view_create_info.image = image;
14811 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14812 image_view_create_info.format = tex_format;
14813 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014814 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070014815 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014816 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014817
14818 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014819 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014820
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014821 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014822 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014823}
Mike Stroyana3082432015-09-25 13:39:21 -060014824
Mark Youngd339ba32016-05-30 13:28:35 -060014825TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14826 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014828 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014829
14830 ASSERT_NO_FATAL_FAILURE(InitState());
14831
14832 // Create an image and try to create a view with no memory backing the image
14833 VkImage image;
14834
14835 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14836 const int32_t tex_width = 32;
14837 const int32_t tex_height = 32;
14838
14839 VkImageCreateInfo image_create_info = {};
14840 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14841 image_create_info.pNext = NULL;
14842 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14843 image_create_info.format = tex_format;
14844 image_create_info.extent.width = tex_width;
14845 image_create_info.extent.height = tex_height;
14846 image_create_info.extent.depth = 1;
14847 image_create_info.mipLevels = 1;
14848 image_create_info.arrayLayers = 1;
14849 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14850 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14851 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14852 image_create_info.flags = 0;
14853
14854 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14855 ASSERT_VK_SUCCESS(err);
14856
14857 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014858 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014859 image_view_create_info.image = image;
14860 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14861 image_view_create_info.format = tex_format;
14862 image_view_create_info.subresourceRange.layerCount = 1;
14863 image_view_create_info.subresourceRange.baseMipLevel = 0;
14864 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014865 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014866
14867 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014868 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014869
14870 m_errorMonitor->VerifyFound();
14871 vkDestroyImage(m_device->device(), image, NULL);
14872 // If last error is success, it still created the view, so delete it.
14873 if (err == VK_SUCCESS) {
14874 vkDestroyImageView(m_device->device(), view, NULL);
14875 }
Mark Youngd339ba32016-05-30 13:28:35 -060014876}
14877
Karl Schultz6addd812016-02-02 17:17:23 -070014878TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014879 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014881
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014882 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014883
Karl Schultz6addd812016-02-02 17:17:23 -070014884 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014885 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014886 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014887 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014888
14889 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014890 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014891 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014892 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14893 image_view_create_info.format = tex_format;
14894 image_view_create_info.subresourceRange.baseMipLevel = 0;
14895 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014896 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014897 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014898 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014899
14900 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014901 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014902
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014903 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014904}
14905
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014906TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014907 VkResult err;
14908 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014909
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014911
Mike Stroyana3082432015-09-25 13:39:21 -060014912 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014913
14914 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014915 VkImage srcImage;
14916 VkImage dstImage;
14917 VkDeviceMemory srcMem;
14918 VkDeviceMemory destMem;
14919 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014920
14921 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014922 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14923 image_create_info.pNext = NULL;
14924 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14925 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14926 image_create_info.extent.width = 32;
14927 image_create_info.extent.height = 32;
14928 image_create_info.extent.depth = 1;
14929 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014930 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014931 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14932 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14933 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14934 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014936 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014937 ASSERT_VK_SUCCESS(err);
14938
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014939 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014940 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014941 ASSERT_VK_SUCCESS(err);
14942
14943 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014944 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014945 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14946 memAlloc.pNext = NULL;
14947 memAlloc.allocationSize = 0;
14948 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014949
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014950 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014951 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014952 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014953 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014954 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014955 ASSERT_VK_SUCCESS(err);
14956
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014957 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014958 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014959 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014960 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014961 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014962 ASSERT_VK_SUCCESS(err);
14963
14964 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14965 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014966 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014967 ASSERT_VK_SUCCESS(err);
14968
Tony Barbour552f6c02016-12-21 14:34:07 -070014969 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014970 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014971 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014972 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014973 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014974 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014975 copyRegion.srcOffset.x = 0;
14976 copyRegion.srcOffset.y = 0;
14977 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014978 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014979 copyRegion.dstSubresource.mipLevel = 0;
14980 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014981 // Introduce failure by forcing the dst layerCount to differ from src
14982 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014983 copyRegion.dstOffset.x = 0;
14984 copyRegion.dstOffset.y = 0;
14985 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014986 copyRegion.extent.width = 1;
14987 copyRegion.extent.height = 1;
14988 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014989 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070014990 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014991
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014992 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014993
Chia-I Wuf7458c52015-10-26 21:10:41 +080014994 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014995 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014996 vkFreeMemory(m_device->device(), srcMem, NULL);
14997 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014998}
14999
Tony Barbourd6673642016-05-05 14:46:39 -060015000TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015001 TEST_DESCRIPTION("Creating images with unsuported formats ");
15002
15003 ASSERT_NO_FATAL_FAILURE(InitState());
15004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15005 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015006 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 -060015007 VK_IMAGE_TILING_OPTIMAL, 0);
15008 ASSERT_TRUE(image.initialized());
15009
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015010 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015011 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015012 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015013 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15014 image_create_info.format = VK_FORMAT_UNDEFINED;
15015 image_create_info.extent.width = 32;
15016 image_create_info.extent.height = 32;
15017 image_create_info.extent.depth = 1;
15018 image_create_info.mipLevels = 1;
15019 image_create_info.arrayLayers = 1;
15020 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15021 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15022 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15025 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015026
15027 VkImage localImage;
15028 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15029 m_errorMonitor->VerifyFound();
15030
Tony Barbourd6673642016-05-05 14:46:39 -060015031 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015032 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015033 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15034 VkFormat format = static_cast<VkFormat>(f);
15035 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015036 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015037 unsupported = format;
15038 break;
15039 }
15040 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015041
Tony Barbourd6673642016-05-05 14:46:39 -060015042 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015043 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015045
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015046 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015047 m_errorMonitor->VerifyFound();
15048 }
15049}
15050
15051TEST_F(VkLayerTest, ImageLayerViewTests) {
15052 VkResult ret;
15053 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15054
15055 ASSERT_NO_FATAL_FAILURE(InitState());
15056
15057 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015058 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 -060015059 VK_IMAGE_TILING_OPTIMAL, 0);
15060 ASSERT_TRUE(image.initialized());
15061
15062 VkImageView imgView;
15063 VkImageViewCreateInfo imgViewInfo = {};
15064 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15065 imgViewInfo.image = image.handle();
15066 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15067 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15068 imgViewInfo.subresourceRange.layerCount = 1;
15069 imgViewInfo.subresourceRange.baseMipLevel = 0;
15070 imgViewInfo.subresourceRange.levelCount = 1;
15071 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15072
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015074 // View can't have baseMipLevel >= image's mipLevels - Expect
15075 // VIEW_CREATE_ERROR
15076 imgViewInfo.subresourceRange.baseMipLevel = 1;
15077 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15078 m_errorMonitor->VerifyFound();
15079 imgViewInfo.subresourceRange.baseMipLevel = 0;
15080
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015082 // View can't have baseArrayLayer >= image's arraySize - Expect
15083 // VIEW_CREATE_ERROR
15084 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15085 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15086 m_errorMonitor->VerifyFound();
15087 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15088
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015090 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15091 imgViewInfo.subresourceRange.levelCount = 0;
15092 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15093 m_errorMonitor->VerifyFound();
15094 imgViewInfo.subresourceRange.levelCount = 1;
15095
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015096 m_errorMonitor->SetDesiredFailureMsg(
15097 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15098 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015099 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15100 imgViewInfo.subresourceRange.layerCount = 0;
15101 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15102 m_errorMonitor->VerifyFound();
15103 imgViewInfo.subresourceRange.layerCount = 1;
15104
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15106 "Formats MUST be IDENTICAL unless "
15107 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15108 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015109 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15110 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15111 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15112 m_errorMonitor->VerifyFound();
15113 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15114
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015116 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15117 // VIEW_CREATE_ERROR
15118 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15119 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15120 m_errorMonitor->VerifyFound();
15121 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15122
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015124 // TODO: Update framework to easily passing mutable flag into ImageObj init
15125 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015126 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15127 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15128 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015129 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15130 // VIEW_CREATE_ERROR
15131 VkImageCreateInfo mutImgInfo = image.create_info();
15132 VkImage mutImage;
15133 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015134 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015135 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15136 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15137 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15138 ASSERT_VK_SUCCESS(ret);
15139 imgViewInfo.image = mutImage;
15140 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15141 m_errorMonitor->VerifyFound();
15142 imgViewInfo.image = image.handle();
15143 vkDestroyImage(m_device->handle(), mutImage, NULL);
15144}
15145
15146TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060015147 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15148
15149 ASSERT_NO_FATAL_FAILURE(InitState());
15150
Rene Lindsay135204f2016-12-22 17:11:09 -070015151 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060015152 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070015153 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 -070015154 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060015155 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060015156 vk_testing::Buffer buffer;
15157 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070015158 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060015159 VkBufferImageCopy region = {};
15160 region.bufferRowLength = 128;
15161 region.bufferImageHeight = 128;
15162 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15163 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070015164 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015165 region.imageExtent.height = 4;
15166 region.imageExtent.width = 4;
15167 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070015168
15169 VkImageObj image2(m_device);
15170 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 -070015171 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070015172 ASSERT_TRUE(image2.initialized());
15173 vk_testing::Buffer buffer2;
15174 VkMemoryPropertyFlags reqs2 = 0;
15175 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
15176 VkBufferImageCopy region2 = {};
15177 region2.bufferRowLength = 128;
15178 region2.bufferImageHeight = 128;
15179 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15180 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15181 region2.imageSubresource.layerCount = 1;
15182 region2.imageExtent.height = 4;
15183 region2.imageExtent.width = 4;
15184 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015185 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060015186
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015187 // Image must have offset.z of 0 and extent.depth of 1
15188 // Introduce failure by setting imageExtent.depth to 0
15189 region.imageExtent.depth = 0;
15190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15191 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015192 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015193 m_errorMonitor->VerifyFound();
15194
15195 region.imageExtent.depth = 1;
15196
15197 // Image must have offset.z of 0 and extent.depth of 1
15198 // Introduce failure by setting imageOffset.z to 4
15199 region.imageOffset.z = 4;
15200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15201 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015202 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015203 m_errorMonitor->VerifyFound();
15204
15205 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015206 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15207 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070015208 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015210 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15211 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015212 m_errorMonitor->VerifyFound();
15213
15214 // BufferOffset must be a multiple of 4
15215 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070015216 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070015218 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
15219 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015220 m_errorMonitor->VerifyFound();
15221
15222 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15223 region.bufferOffset = 0;
15224 region.imageExtent.height = 128;
15225 region.imageExtent.width = 128;
15226 // Introduce failure by setting bufferRowLength > 0 but less than width
15227 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015229 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15230 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015231 m_errorMonitor->VerifyFound();
15232
15233 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15234 region.bufferRowLength = 128;
15235 // Introduce failure by setting bufferRowHeight > 0 but less than height
15236 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015238 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15239 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015240 m_errorMonitor->VerifyFound();
15241
15242 region.bufferImageHeight = 128;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15244 "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015245 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060015246 // Expect INVALID_FILTER
15247 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015248 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
15249 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015250 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015251 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15252 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015253 VkImageBlit blitRegion = {};
15254 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15255 blitRegion.srcSubresource.baseArrayLayer = 0;
15256 blitRegion.srcSubresource.layerCount = 1;
15257 blitRegion.srcSubresource.mipLevel = 0;
15258 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15259 blitRegion.dstSubresource.baseArrayLayer = 0;
15260 blitRegion.dstSubresource.layerCount = 1;
15261 blitRegion.dstSubresource.mipLevel = 0;
15262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015263 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015264 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060015265 m_errorMonitor->VerifyFound();
15266
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015267 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
15269 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15270 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015271 m_errorMonitor->VerifyFound();
15272
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060015274 VkImageMemoryBarrier img_barrier;
15275 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15276 img_barrier.pNext = NULL;
15277 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15278 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15279 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15280 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15281 img_barrier.image = image.handle();
15282 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15283 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15284 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15285 img_barrier.subresourceRange.baseArrayLayer = 0;
15286 img_barrier.subresourceRange.baseMipLevel = 0;
15287 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15288 img_barrier.subresourceRange.layerCount = 0;
15289 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015290 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15291 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015292 m_errorMonitor->VerifyFound();
15293 img_barrier.subresourceRange.layerCount = 1;
15294}
15295
15296TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060015297 TEST_DESCRIPTION("Exceed the limits of image format ");
15298
Cody Northropc31a84f2016-08-22 10:41:47 -060015299 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015301 VkImageCreateInfo image_create_info = {};
15302 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15303 image_create_info.pNext = NULL;
15304 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15305 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15306 image_create_info.extent.width = 32;
15307 image_create_info.extent.height = 32;
15308 image_create_info.extent.depth = 1;
15309 image_create_info.mipLevels = 1;
15310 image_create_info.arrayLayers = 1;
15311 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15312 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15313 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15314 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15315 image_create_info.flags = 0;
15316
15317 VkImage nullImg;
15318 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015319 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15320 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015321 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015322 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15323 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15324 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015325 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015328 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15329 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15330 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15331 m_errorMonitor->VerifyFound();
15332 image_create_info.mipLevels = 1;
15333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015335 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15336 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15337 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15338 m_errorMonitor->VerifyFound();
15339 image_create_info.arrayLayers = 1;
15340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015342 int samples = imgFmtProps.sampleCounts >> 1;
15343 image_create_info.samples = (VkSampleCountFlagBits)samples;
15344 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15345 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15346 m_errorMonitor->VerifyFound();
15347 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15348
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15350 "pCreateInfo->initialLayout, must be "
15351 "VK_IMAGE_LAYOUT_UNDEFINED or "
15352 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015353 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15354 // Expect INVALID_LAYOUT
15355 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15356 m_errorMonitor->VerifyFound();
15357 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15358}
15359
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015360TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015361 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015363
15364 ASSERT_NO_FATAL_FAILURE(InitState());
15365
15366 VkImageObj src_image(m_device);
15367 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15368 VkImageObj dst_image(m_device);
15369 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15370
Tony Barbour552f6c02016-12-21 14:34:07 -070015371 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015372 VkImageCopy copy_region;
15373 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15374 copy_region.srcSubresource.mipLevel = 0;
15375 copy_region.srcSubresource.baseArrayLayer = 0;
15376 copy_region.srcSubresource.layerCount = 0;
15377 copy_region.srcOffset.x = 0;
15378 copy_region.srcOffset.y = 0;
15379 copy_region.srcOffset.z = 0;
15380 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15381 copy_region.dstSubresource.mipLevel = 0;
15382 copy_region.dstSubresource.baseArrayLayer = 0;
15383 copy_region.dstSubresource.layerCount = 0;
15384 copy_region.dstOffset.x = 0;
15385 copy_region.dstOffset.y = 0;
15386 copy_region.dstOffset.z = 0;
15387 copy_region.extent.width = 64;
15388 copy_region.extent.height = 64;
15389 copy_region.extent.depth = 1;
15390 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15391 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015392 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015393
15394 m_errorMonitor->VerifyFound();
15395}
15396
15397TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015398 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015400
15401 ASSERT_NO_FATAL_FAILURE(InitState());
15402
15403 VkImageObj src_image(m_device);
15404 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15405 VkImageObj dst_image(m_device);
15406 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15407
Tony Barbour552f6c02016-12-21 14:34:07 -070015408 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015409 VkImageCopy copy_region;
15410 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15411 copy_region.srcSubresource.mipLevel = 0;
15412 copy_region.srcSubresource.baseArrayLayer = 0;
15413 copy_region.srcSubresource.layerCount = 0;
15414 copy_region.srcOffset.x = 0;
15415 copy_region.srcOffset.y = 0;
15416 copy_region.srcOffset.z = 0;
15417 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15418 copy_region.dstSubresource.mipLevel = 0;
15419 copy_region.dstSubresource.baseArrayLayer = 0;
15420 copy_region.dstSubresource.layerCount = 0;
15421 copy_region.dstOffset.x = 0;
15422 copy_region.dstOffset.y = 0;
15423 copy_region.dstOffset.z = 0;
15424 copy_region.extent.width = 64;
15425 copy_region.extent.height = 64;
15426 copy_region.extent.depth = 1;
15427 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15428 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015429 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015430
15431 m_errorMonitor->VerifyFound();
15432}
15433
Karl Schultz6addd812016-02-02 17:17:23 -070015434TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015435 VkResult err;
15436 bool pass;
15437
15438 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015440
15441 ASSERT_NO_FATAL_FAILURE(InitState());
15442
15443 // Create two images of different types and try to copy between them
15444 VkImage srcImage;
15445 VkImage dstImage;
15446 VkDeviceMemory srcMem;
15447 VkDeviceMemory destMem;
15448 VkMemoryRequirements memReqs;
15449
15450 VkImageCreateInfo image_create_info = {};
15451 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15452 image_create_info.pNext = NULL;
15453 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15454 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15455 image_create_info.extent.width = 32;
15456 image_create_info.extent.height = 32;
15457 image_create_info.extent.depth = 1;
15458 image_create_info.mipLevels = 1;
15459 image_create_info.arrayLayers = 1;
15460 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15461 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15462 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15463 image_create_info.flags = 0;
15464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015465 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015466 ASSERT_VK_SUCCESS(err);
15467
15468 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15469 // Introduce failure by creating second image with a different-sized format.
15470 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15471
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015472 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015473 ASSERT_VK_SUCCESS(err);
15474
15475 // Allocate memory
15476 VkMemoryAllocateInfo memAlloc = {};
15477 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15478 memAlloc.pNext = NULL;
15479 memAlloc.allocationSize = 0;
15480 memAlloc.memoryTypeIndex = 0;
15481
15482 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15483 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015484 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015485 ASSERT_TRUE(pass);
15486 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15487 ASSERT_VK_SUCCESS(err);
15488
15489 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15490 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015491 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015492 ASSERT_TRUE(pass);
15493 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15494 ASSERT_VK_SUCCESS(err);
15495
15496 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15497 ASSERT_VK_SUCCESS(err);
15498 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15499 ASSERT_VK_SUCCESS(err);
15500
Tony Barbour552f6c02016-12-21 14:34:07 -070015501 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015502 VkImageCopy copyRegion;
15503 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15504 copyRegion.srcSubresource.mipLevel = 0;
15505 copyRegion.srcSubresource.baseArrayLayer = 0;
15506 copyRegion.srcSubresource.layerCount = 0;
15507 copyRegion.srcOffset.x = 0;
15508 copyRegion.srcOffset.y = 0;
15509 copyRegion.srcOffset.z = 0;
15510 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15511 copyRegion.dstSubresource.mipLevel = 0;
15512 copyRegion.dstSubresource.baseArrayLayer = 0;
15513 copyRegion.dstSubresource.layerCount = 0;
15514 copyRegion.dstOffset.x = 0;
15515 copyRegion.dstOffset.y = 0;
15516 copyRegion.dstOffset.z = 0;
15517 copyRegion.extent.width = 1;
15518 copyRegion.extent.height = 1;
15519 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015520 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015521 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015522
15523 m_errorMonitor->VerifyFound();
15524
15525 vkDestroyImage(m_device->device(), srcImage, NULL);
15526 vkDestroyImage(m_device->device(), dstImage, NULL);
15527 vkFreeMemory(m_device->device(), srcMem, NULL);
15528 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015529}
15530
Karl Schultz6addd812016-02-02 17:17:23 -070015531TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15532 VkResult err;
15533 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015534
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015535 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15537 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015538
Mike Stroyana3082432015-09-25 13:39:21 -060015539 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015540
15541 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015542 VkImage srcImage;
15543 VkImage dstImage;
15544 VkDeviceMemory srcMem;
15545 VkDeviceMemory destMem;
15546 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015547
15548 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015549 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15550 image_create_info.pNext = NULL;
15551 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15552 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15553 image_create_info.extent.width = 32;
15554 image_create_info.extent.height = 32;
15555 image_create_info.extent.depth = 1;
15556 image_create_info.mipLevels = 1;
15557 image_create_info.arrayLayers = 1;
15558 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15559 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15560 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15561 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015562
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015563 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015564 ASSERT_VK_SUCCESS(err);
15565
Karl Schultzbdb75952016-04-19 11:36:49 -060015566 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15567
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015568 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015569 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015570 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015571 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015572
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015573 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015574 ASSERT_VK_SUCCESS(err);
15575
15576 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015577 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015578 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15579 memAlloc.pNext = NULL;
15580 memAlloc.allocationSize = 0;
15581 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015582
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015583 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015584 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015585 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015586 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015587 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015588 ASSERT_VK_SUCCESS(err);
15589
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015590 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015591 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015592 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015593 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015594 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015595 ASSERT_VK_SUCCESS(err);
15596
15597 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15598 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015599 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015600 ASSERT_VK_SUCCESS(err);
15601
Tony Barbour552f6c02016-12-21 14:34:07 -070015602 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015603 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015604 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015605 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015606 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015607 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015608 copyRegion.srcOffset.x = 0;
15609 copyRegion.srcOffset.y = 0;
15610 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015611 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015612 copyRegion.dstSubresource.mipLevel = 0;
15613 copyRegion.dstSubresource.baseArrayLayer = 0;
15614 copyRegion.dstSubresource.layerCount = 0;
15615 copyRegion.dstOffset.x = 0;
15616 copyRegion.dstOffset.y = 0;
15617 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015618 copyRegion.extent.width = 1;
15619 copyRegion.extent.height = 1;
15620 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015621 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015622 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015623
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015624 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015625
Chia-I Wuf7458c52015-10-26 21:10:41 +080015626 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015627 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015628 vkFreeMemory(m_device->device(), srcMem, NULL);
15629 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015630}
15631
Karl Schultz6addd812016-02-02 17:17:23 -070015632TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15633 VkResult err;
15634 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015635
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15637 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015638
Mike Stroyana3082432015-09-25 13:39:21 -060015639 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015640
15641 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015642 VkImage srcImage;
15643 VkImage dstImage;
15644 VkDeviceMemory srcMem;
15645 VkDeviceMemory destMem;
15646 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015647
15648 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015649 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15650 image_create_info.pNext = NULL;
15651 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15652 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15653 image_create_info.extent.width = 32;
15654 image_create_info.extent.height = 1;
15655 image_create_info.extent.depth = 1;
15656 image_create_info.mipLevels = 1;
15657 image_create_info.arrayLayers = 1;
15658 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15659 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15660 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15661 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015663 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015664 ASSERT_VK_SUCCESS(err);
15665
Karl Schultz6addd812016-02-02 17:17:23 -070015666 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015667
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015668 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015669 ASSERT_VK_SUCCESS(err);
15670
15671 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015672 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015673 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15674 memAlloc.pNext = NULL;
15675 memAlloc.allocationSize = 0;
15676 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015677
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015678 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015679 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015680 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015681 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015682 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015683 ASSERT_VK_SUCCESS(err);
15684
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015685 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015686 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015687 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015688 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015689 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015690 ASSERT_VK_SUCCESS(err);
15691
15692 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15693 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015694 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015695 ASSERT_VK_SUCCESS(err);
15696
Tony Barbour552f6c02016-12-21 14:34:07 -070015697 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015698 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015699 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15700 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015701 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015702 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015703 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015704 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015705 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015706 resolveRegion.srcOffset.x = 0;
15707 resolveRegion.srcOffset.y = 0;
15708 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015709 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015710 resolveRegion.dstSubresource.mipLevel = 0;
15711 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015712 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015713 resolveRegion.dstOffset.x = 0;
15714 resolveRegion.dstOffset.y = 0;
15715 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015716 resolveRegion.extent.width = 1;
15717 resolveRegion.extent.height = 1;
15718 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015719 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015720 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015721
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015722 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015723
Chia-I Wuf7458c52015-10-26 21:10:41 +080015724 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015725 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015726 vkFreeMemory(m_device->device(), srcMem, NULL);
15727 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015728}
15729
Karl Schultz6addd812016-02-02 17:17:23 -070015730TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15731 VkResult err;
15732 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15735 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015736
Mike Stroyana3082432015-09-25 13:39:21 -060015737 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015738
Chris Forbesa7530692016-05-08 12:35:39 +120015739 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015740 VkImage srcImage;
15741 VkImage dstImage;
15742 VkDeviceMemory srcMem;
15743 VkDeviceMemory destMem;
15744 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015745
15746 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015747 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15748 image_create_info.pNext = NULL;
15749 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15750 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15751 image_create_info.extent.width = 32;
15752 image_create_info.extent.height = 1;
15753 image_create_info.extent.depth = 1;
15754 image_create_info.mipLevels = 1;
15755 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015756 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015757 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15758 // Note: Some implementations expect color attachment usage for any
15759 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015760 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015761 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015762
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015763 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015764 ASSERT_VK_SUCCESS(err);
15765
Karl Schultz6addd812016-02-02 17:17:23 -070015766 // Note: Some implementations expect color attachment usage for any
15767 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015768 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015770 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015771 ASSERT_VK_SUCCESS(err);
15772
15773 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015774 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015775 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15776 memAlloc.pNext = NULL;
15777 memAlloc.allocationSize = 0;
15778 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015779
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015780 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015781 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015782 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015783 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015784 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015785 ASSERT_VK_SUCCESS(err);
15786
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015787 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015788 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015789 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015790 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015791 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015792 ASSERT_VK_SUCCESS(err);
15793
15794 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15795 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015796 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015797 ASSERT_VK_SUCCESS(err);
15798
Tony Barbour552f6c02016-12-21 14:34:07 -070015799 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015800 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015801 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15802 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015803 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015804 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015805 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015806 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015807 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015808 resolveRegion.srcOffset.x = 0;
15809 resolveRegion.srcOffset.y = 0;
15810 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015811 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015812 resolveRegion.dstSubresource.mipLevel = 0;
15813 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015814 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015815 resolveRegion.dstOffset.x = 0;
15816 resolveRegion.dstOffset.y = 0;
15817 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015818 resolveRegion.extent.width = 1;
15819 resolveRegion.extent.height = 1;
15820 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015821 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015822 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015823
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015824 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015825
Chia-I Wuf7458c52015-10-26 21:10:41 +080015826 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015827 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015828 vkFreeMemory(m_device->device(), srcMem, NULL);
15829 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015830}
15831
Karl Schultz6addd812016-02-02 17:17:23 -070015832TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15833 VkResult err;
15834 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015835
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15837 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015838
Mike Stroyana3082432015-09-25 13:39:21 -060015839 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015840
15841 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015842 VkImage srcImage;
15843 VkImage dstImage;
15844 VkDeviceMemory srcMem;
15845 VkDeviceMemory destMem;
15846 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015847
15848 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015849 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15850 image_create_info.pNext = NULL;
15851 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15852 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15853 image_create_info.extent.width = 32;
15854 image_create_info.extent.height = 1;
15855 image_create_info.extent.depth = 1;
15856 image_create_info.mipLevels = 1;
15857 image_create_info.arrayLayers = 1;
15858 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15859 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15860 // Note: Some implementations expect color attachment usage for any
15861 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015862 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015863 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015865 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015866 ASSERT_VK_SUCCESS(err);
15867
Karl Schultz6addd812016-02-02 17:17:23 -070015868 // Set format to something other than source image
15869 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15870 // Note: Some implementations expect color attachment usage for any
15871 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015872 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015873 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015874
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015875 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015876 ASSERT_VK_SUCCESS(err);
15877
15878 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015879 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015880 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15881 memAlloc.pNext = NULL;
15882 memAlloc.allocationSize = 0;
15883 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015884
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015885 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015886 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015887 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015888 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015889 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015890 ASSERT_VK_SUCCESS(err);
15891
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015892 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015893 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015894 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015895 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015896 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015897 ASSERT_VK_SUCCESS(err);
15898
15899 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15900 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015901 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015902 ASSERT_VK_SUCCESS(err);
15903
Tony Barbour552f6c02016-12-21 14:34:07 -070015904 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015905 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015906 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15907 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015908 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015909 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015910 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015911 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015912 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015913 resolveRegion.srcOffset.x = 0;
15914 resolveRegion.srcOffset.y = 0;
15915 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015916 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015917 resolveRegion.dstSubresource.mipLevel = 0;
15918 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015919 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015920 resolveRegion.dstOffset.x = 0;
15921 resolveRegion.dstOffset.y = 0;
15922 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015923 resolveRegion.extent.width = 1;
15924 resolveRegion.extent.height = 1;
15925 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015926 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015927 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015928
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015929 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015930
Chia-I Wuf7458c52015-10-26 21:10:41 +080015931 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015932 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015933 vkFreeMemory(m_device->device(), srcMem, NULL);
15934 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015935}
15936
Karl Schultz6addd812016-02-02 17:17:23 -070015937TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15938 VkResult err;
15939 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15942 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015943
Mike Stroyana3082432015-09-25 13:39:21 -060015944 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015945
15946 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015947 VkImage srcImage;
15948 VkImage dstImage;
15949 VkDeviceMemory srcMem;
15950 VkDeviceMemory destMem;
15951 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015952
15953 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015954 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15955 image_create_info.pNext = NULL;
15956 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15957 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15958 image_create_info.extent.width = 32;
15959 image_create_info.extent.height = 1;
15960 image_create_info.extent.depth = 1;
15961 image_create_info.mipLevels = 1;
15962 image_create_info.arrayLayers = 1;
15963 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15964 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15965 // Note: Some implementations expect color attachment usage for any
15966 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015967 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015968 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015969
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015970 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015971 ASSERT_VK_SUCCESS(err);
15972
Karl Schultz6addd812016-02-02 17:17:23 -070015973 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15974 // Note: Some implementations expect color attachment usage for any
15975 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015976 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015977 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015979 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015980 ASSERT_VK_SUCCESS(err);
15981
15982 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015983 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015984 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15985 memAlloc.pNext = NULL;
15986 memAlloc.allocationSize = 0;
15987 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015988
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015989 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015990 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015991 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015992 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015993 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015994 ASSERT_VK_SUCCESS(err);
15995
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015996 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015997 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015998 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015999 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016000 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016001 ASSERT_VK_SUCCESS(err);
16002
16003 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16004 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016005 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016006 ASSERT_VK_SUCCESS(err);
16007
Tony Barbour552f6c02016-12-21 14:34:07 -070016008 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016009 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016010 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16011 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016012 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016013 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016014 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016015 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016016 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016017 resolveRegion.srcOffset.x = 0;
16018 resolveRegion.srcOffset.y = 0;
16019 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016020 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016021 resolveRegion.dstSubresource.mipLevel = 0;
16022 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016023 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016024 resolveRegion.dstOffset.x = 0;
16025 resolveRegion.dstOffset.y = 0;
16026 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016027 resolveRegion.extent.width = 1;
16028 resolveRegion.extent.height = 1;
16029 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016030 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016031 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016032
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016033 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016034
Chia-I Wuf7458c52015-10-26 21:10:41 +080016035 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016036 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016037 vkFreeMemory(m_device->device(), srcMem, NULL);
16038 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016039}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016040
Karl Schultz6addd812016-02-02 17:17:23 -070016041TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016042 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016043 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16044 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016045 // The image format check comes 2nd in validation so we trigger it first,
16046 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016047 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16050 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016051
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016053
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016054 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016055 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16056 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016057
16058 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016059 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16060 ds_pool_ci.pNext = NULL;
16061 ds_pool_ci.maxSets = 1;
16062 ds_pool_ci.poolSizeCount = 1;
16063 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016064
16065 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016066 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016067 ASSERT_VK_SUCCESS(err);
16068
16069 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016070 dsl_binding.binding = 0;
16071 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16072 dsl_binding.descriptorCount = 1;
16073 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16074 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016075
16076 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016077 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16078 ds_layout_ci.pNext = NULL;
16079 ds_layout_ci.bindingCount = 1;
16080 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016081 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016082 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016083 ASSERT_VK_SUCCESS(err);
16084
16085 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016086 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016087 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016088 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016089 alloc_info.descriptorPool = ds_pool;
16090 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016091 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016092 ASSERT_VK_SUCCESS(err);
16093
Karl Schultz6addd812016-02-02 17:17:23 -070016094 VkImage image_bad;
16095 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016096 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016097 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016098 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016099 const int32_t tex_width = 32;
16100 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016101
16102 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016103 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16104 image_create_info.pNext = NULL;
16105 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16106 image_create_info.format = tex_format_bad;
16107 image_create_info.extent.width = tex_width;
16108 image_create_info.extent.height = tex_height;
16109 image_create_info.extent.depth = 1;
16110 image_create_info.mipLevels = 1;
16111 image_create_info.arrayLayers = 1;
16112 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16113 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016114 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016115 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016116
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016117 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016118 ASSERT_VK_SUCCESS(err);
16119 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016120 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16121 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016122 ASSERT_VK_SUCCESS(err);
16123
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016124 // ---Bind image memory---
16125 VkMemoryRequirements img_mem_reqs;
16126 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
16127 VkMemoryAllocateInfo image_alloc_info = {};
16128 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16129 image_alloc_info.pNext = NULL;
16130 image_alloc_info.memoryTypeIndex = 0;
16131 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016132 bool pass =
16133 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 -070016134 ASSERT_TRUE(pass);
16135 VkDeviceMemory mem;
16136 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
16137 ASSERT_VK_SUCCESS(err);
16138 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
16139 ASSERT_VK_SUCCESS(err);
16140 // -----------------------
16141
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016142 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016143 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016144 image_view_create_info.image = image_bad;
16145 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16146 image_view_create_info.format = tex_format_bad;
16147 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16148 image_view_create_info.subresourceRange.baseMipLevel = 0;
16149 image_view_create_info.subresourceRange.layerCount = 1;
16150 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016151 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016152
16153 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016154 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016155
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016156 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016157
Chia-I Wuf7458c52015-10-26 21:10:41 +080016158 vkDestroyImage(m_device->device(), image_bad, NULL);
16159 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016160 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16161 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016162
16163 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016164}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016165
16166TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016167 TEST_DESCRIPTION(
16168 "Call ClearColorImage w/ a depth|stencil image and "
16169 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016170
16171 ASSERT_NO_FATAL_FAILURE(InitState());
16172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16173
Tony Barbour552f6c02016-12-21 14:34:07 -070016174 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016175
16176 // Color image
16177 VkClearColorValue clear_color;
16178 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16179 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16180 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16181 const int32_t img_width = 32;
16182 const int32_t img_height = 32;
16183 VkImageCreateInfo image_create_info = {};
16184 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16185 image_create_info.pNext = NULL;
16186 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16187 image_create_info.format = color_format;
16188 image_create_info.extent.width = img_width;
16189 image_create_info.extent.height = img_height;
16190 image_create_info.extent.depth = 1;
16191 image_create_info.mipLevels = 1;
16192 image_create_info.arrayLayers = 1;
16193 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16194 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16195 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16196
16197 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016198 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016200 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016201
16202 // Depth/Stencil image
16203 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016204 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016205 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16206 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16207 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16208 ds_image_create_info.extent.width = 64;
16209 ds_image_create_info.extent.height = 64;
16210 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016211 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 -060016212
16213 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016214 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016215
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016216 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 -060016217
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016220 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016221 &color_range);
16222
16223 m_errorMonitor->VerifyFound();
16224
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16226 "vkCmdClearColorImage called with "
16227 "image created without "
16228 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016229
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016230 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016231 &color_range);
16232
16233 m_errorMonitor->VerifyFound();
16234
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016235 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16237 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016238
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016239 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
16240 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016241
16242 m_errorMonitor->VerifyFound();
16243}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016244#endif // IMAGE_TESTS
Tobin Ehliscde08892015-09-22 10:11:37 -060016245
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016246// WSI Enabled Tests
16247//
Chris Forbes09368e42016-10-13 11:59:22 +130016248#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016249TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
16250
16251#if defined(VK_USE_PLATFORM_XCB_KHR)
16252 VkSurfaceKHR surface = VK_NULL_HANDLE;
16253
16254 VkResult err;
16255 bool pass;
16256 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
16257 VkSwapchainCreateInfoKHR swapchain_create_info = {};
16258 // uint32_t swapchain_image_count = 0;
16259 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
16260 // uint32_t image_index = 0;
16261 // VkPresentInfoKHR present_info = {};
16262
16263 ASSERT_NO_FATAL_FAILURE(InitState());
16264
16265 // Use the create function from one of the VK_KHR_*_surface extension in
16266 // order to create a surface, testing all known errors in the process,
16267 // before successfully creating a surface:
16268 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
16269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
16270 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
16271 pass = (err != VK_SUCCESS);
16272 ASSERT_TRUE(pass);
16273 m_errorMonitor->VerifyFound();
16274
16275 // Next, try to create a surface with the wrong
16276 // VkXcbSurfaceCreateInfoKHR::sType:
16277 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
16278 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16280 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16281 pass = (err != VK_SUCCESS);
16282 ASSERT_TRUE(pass);
16283 m_errorMonitor->VerifyFound();
16284
16285 // Create a native window, and then correctly create a surface:
16286 xcb_connection_t *connection;
16287 xcb_screen_t *screen;
16288 xcb_window_t xcb_window;
16289 xcb_intern_atom_reply_t *atom_wm_delete_window;
16290
16291 const xcb_setup_t *setup;
16292 xcb_screen_iterator_t iter;
16293 int scr;
16294 uint32_t value_mask, value_list[32];
16295 int width = 1;
16296 int height = 1;
16297
16298 connection = xcb_connect(NULL, &scr);
16299 ASSERT_TRUE(connection != NULL);
16300 setup = xcb_get_setup(connection);
16301 iter = xcb_setup_roots_iterator(setup);
16302 while (scr-- > 0)
16303 xcb_screen_next(&iter);
16304 screen = iter.data;
16305
16306 xcb_window = xcb_generate_id(connection);
16307
16308 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16309 value_list[0] = screen->black_pixel;
16310 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16311
16312 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16313 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16314
16315 /* Magic code that will send notification when window is destroyed */
16316 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16317 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16318
16319 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16320 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16321 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16322 free(reply);
16323
16324 xcb_map_window(connection, xcb_window);
16325
16326 // Force the x/y coordinates to 100,100 results are identical in consecutive
16327 // runs
16328 const uint32_t coords[] = { 100, 100 };
16329 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16330
16331 // Finally, try to correctly create a surface:
16332 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16333 xcb_create_info.pNext = NULL;
16334 xcb_create_info.flags = 0;
16335 xcb_create_info.connection = connection;
16336 xcb_create_info.window = xcb_window;
16337 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16338 pass = (err == VK_SUCCESS);
16339 ASSERT_TRUE(pass);
16340
16341 // Check if surface supports presentation:
16342
16343 // 1st, do so without having queried the queue families:
16344 VkBool32 supported = false;
16345 // TODO: Get the following error to come out:
16346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16347 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16348 "function");
16349 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16350 pass = (err != VK_SUCCESS);
16351 // ASSERT_TRUE(pass);
16352 // m_errorMonitor->VerifyFound();
16353
16354 // Next, query a queue family index that's too large:
16355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16356 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16357 pass = (err != VK_SUCCESS);
16358 ASSERT_TRUE(pass);
16359 m_errorMonitor->VerifyFound();
16360
16361 // Finally, do so correctly:
16362 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16363 // SUPPORTED
16364 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16365 pass = (err == VK_SUCCESS);
16366 ASSERT_TRUE(pass);
16367
16368 // Before proceeding, try to create a swapchain without having called
16369 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16370 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16371 swapchain_create_info.pNext = NULL;
16372 swapchain_create_info.flags = 0;
16373 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16374 swapchain_create_info.surface = surface;
16375 swapchain_create_info.imageArrayLayers = 1;
16376 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16377 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16379 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16380 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16381 pass = (err != VK_SUCCESS);
16382 ASSERT_TRUE(pass);
16383 m_errorMonitor->VerifyFound();
16384
16385 // Get the surface capabilities:
16386 VkSurfaceCapabilitiesKHR surface_capabilities;
16387
16388 // Do so correctly (only error logged by this entrypoint is if the
16389 // extension isn't enabled):
16390 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16391 pass = (err == VK_SUCCESS);
16392 ASSERT_TRUE(pass);
16393
16394 // Get the surface formats:
16395 uint32_t surface_format_count;
16396
16397 // First, try without a pointer to surface_format_count:
16398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16399 "specified as NULL");
16400 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16401 pass = (err == VK_SUCCESS);
16402 ASSERT_TRUE(pass);
16403 m_errorMonitor->VerifyFound();
16404
16405 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16406 // correctly done a 1st try (to get the count):
16407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16408 surface_format_count = 0;
16409 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16410 pass = (err == VK_SUCCESS);
16411 ASSERT_TRUE(pass);
16412 m_errorMonitor->VerifyFound();
16413
16414 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16415 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16416 pass = (err == VK_SUCCESS);
16417 ASSERT_TRUE(pass);
16418
16419 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16420 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16421
16422 // Next, do a 2nd try with surface_format_count being set too high:
16423 surface_format_count += 5;
16424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16425 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16426 pass = (err == VK_SUCCESS);
16427 ASSERT_TRUE(pass);
16428 m_errorMonitor->VerifyFound();
16429
16430 // Finally, do a correct 1st and 2nd try:
16431 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16432 pass = (err == VK_SUCCESS);
16433 ASSERT_TRUE(pass);
16434 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16435 pass = (err == VK_SUCCESS);
16436 ASSERT_TRUE(pass);
16437
16438 // Get the surface present modes:
16439 uint32_t surface_present_mode_count;
16440
16441 // First, try without a pointer to surface_format_count:
16442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16443 "specified as NULL");
16444
16445 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16446 pass = (err == VK_SUCCESS);
16447 ASSERT_TRUE(pass);
16448 m_errorMonitor->VerifyFound();
16449
16450 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16451 // correctly done a 1st try (to get the count):
16452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16453 surface_present_mode_count = 0;
16454 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16455 (VkPresentModeKHR *)&surface_present_mode_count);
16456 pass = (err == VK_SUCCESS);
16457 ASSERT_TRUE(pass);
16458 m_errorMonitor->VerifyFound();
16459
16460 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16461 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16462 pass = (err == VK_SUCCESS);
16463 ASSERT_TRUE(pass);
16464
16465 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16466 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16467
16468 // Next, do a 2nd try with surface_format_count being set too high:
16469 surface_present_mode_count += 5;
16470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16471 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16472 pass = (err == VK_SUCCESS);
16473 ASSERT_TRUE(pass);
16474 m_errorMonitor->VerifyFound();
16475
16476 // Finally, do a correct 1st and 2nd try:
16477 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16478 pass = (err == VK_SUCCESS);
16479 ASSERT_TRUE(pass);
16480 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16481 pass = (err == VK_SUCCESS);
16482 ASSERT_TRUE(pass);
16483
16484 // Create a swapchain:
16485
16486 // First, try without a pointer to swapchain_create_info:
16487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16488 "specified as NULL");
16489
16490 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16491 pass = (err != VK_SUCCESS);
16492 ASSERT_TRUE(pass);
16493 m_errorMonitor->VerifyFound();
16494
16495 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16496 // sType:
16497 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16499
16500 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16501 pass = (err != VK_SUCCESS);
16502 ASSERT_TRUE(pass);
16503 m_errorMonitor->VerifyFound();
16504
16505 // Next, call with a NULL swapchain pointer:
16506 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16507 swapchain_create_info.pNext = NULL;
16508 swapchain_create_info.flags = 0;
16509 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16510 "specified as NULL");
16511
16512 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16513 pass = (err != VK_SUCCESS);
16514 ASSERT_TRUE(pass);
16515 m_errorMonitor->VerifyFound();
16516
16517 // TODO: Enhance swapchain layer so that
16518 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16519
16520 // Next, call with a queue family index that's too large:
16521 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16522 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16523 swapchain_create_info.queueFamilyIndexCount = 2;
16524 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16526 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16527 pass = (err != VK_SUCCESS);
16528 ASSERT_TRUE(pass);
16529 m_errorMonitor->VerifyFound();
16530
16531 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16532 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16533 swapchain_create_info.queueFamilyIndexCount = 1;
16534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16535 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16536 "pCreateInfo->pQueueFamilyIndices).");
16537 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16538 pass = (err != VK_SUCCESS);
16539 ASSERT_TRUE(pass);
16540 m_errorMonitor->VerifyFound();
16541
16542 // Next, call with an invalid imageSharingMode:
16543 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16544 swapchain_create_info.queueFamilyIndexCount = 1;
16545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16546 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16547 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16548 pass = (err != VK_SUCCESS);
16549 ASSERT_TRUE(pass);
16550 m_errorMonitor->VerifyFound();
16551 // Fix for the future:
16552 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16553 // SUPPORTED
16554 swapchain_create_info.queueFamilyIndexCount = 0;
16555 queueFamilyIndex[0] = 0;
16556 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16557
16558 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16559 // Get the images from a swapchain:
16560 // Acquire an image from a swapchain:
16561 // Present an image to a swapchain:
16562 // Destroy the swapchain:
16563
16564 // TODOs:
16565 //
16566 // - Try destroying the device without first destroying the swapchain
16567 //
16568 // - Try destroying the device without first destroying the surface
16569 //
16570 // - Try destroying the surface without first destroying the swapchain
16571
16572 // Destroy the surface:
16573 vkDestroySurfaceKHR(instance(), surface, NULL);
16574
16575 // Tear down the window:
16576 xcb_destroy_window(connection, xcb_window);
16577 xcb_disconnect(connection);
16578
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016579#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016580 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016581#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016582}
Chris Forbes09368e42016-10-13 11:59:22 +130016583#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016584
16585//
16586// POSITIVE VALIDATION TESTS
16587//
16588// These tests do not expect to encounter ANY validation errors pass only if this is true
16589
Tobin Ehlise0006882016-11-03 10:14:28 -060016590TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016591 TEST_DESCRIPTION(
16592 "Perform an image layout transition in a secondary command buffer followed "
16593 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060016594 VkResult err;
16595 m_errorMonitor->ExpectSuccess();
16596 ASSERT_NO_FATAL_FAILURE(InitState());
16597 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16598 // Allocate a secondary and primary cmd buffer
16599 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16600 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16601 command_buffer_allocate_info.commandPool = m_commandPool;
16602 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16603 command_buffer_allocate_info.commandBufferCount = 1;
16604
16605 VkCommandBuffer secondary_command_buffer;
16606 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16607 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16608 VkCommandBuffer primary_command_buffer;
16609 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16610 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16611 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16612 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16613 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16614 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16615 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16616
16617 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16618 ASSERT_VK_SUCCESS(err);
16619 VkImageObj image(m_device);
16620 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16621 ASSERT_TRUE(image.initialized());
16622 VkImageMemoryBarrier img_barrier = {};
16623 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16624 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16625 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16626 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16627 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16628 img_barrier.image = image.handle();
16629 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16630 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16631 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16632 img_barrier.subresourceRange.baseArrayLayer = 0;
16633 img_barrier.subresourceRange.baseMipLevel = 0;
16634 img_barrier.subresourceRange.layerCount = 1;
16635 img_barrier.subresourceRange.levelCount = 1;
16636 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16637 0, nullptr, 1, &img_barrier);
16638 err = vkEndCommandBuffer(secondary_command_buffer);
16639 ASSERT_VK_SUCCESS(err);
16640
16641 // Now update primary cmd buffer to execute secondary and transitions image
16642 command_buffer_begin_info.pInheritanceInfo = nullptr;
16643 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16644 ASSERT_VK_SUCCESS(err);
16645 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16646 VkImageMemoryBarrier img_barrier2 = {};
16647 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16648 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16649 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16650 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16651 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16652 img_barrier2.image = image.handle();
16653 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16654 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16655 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16656 img_barrier2.subresourceRange.baseArrayLayer = 0;
16657 img_barrier2.subresourceRange.baseMipLevel = 0;
16658 img_barrier2.subresourceRange.layerCount = 1;
16659 img_barrier2.subresourceRange.levelCount = 1;
16660 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16661 nullptr, 1, &img_barrier2);
16662 err = vkEndCommandBuffer(primary_command_buffer);
16663 ASSERT_VK_SUCCESS(err);
16664 VkSubmitInfo submit_info = {};
16665 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16666 submit_info.commandBufferCount = 1;
16667 submit_info.pCommandBuffers = &primary_command_buffer;
16668 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16669 ASSERT_VK_SUCCESS(err);
16670 m_errorMonitor->VerifyNotFound();
16671 err = vkDeviceWaitIdle(m_device->device());
16672 ASSERT_VK_SUCCESS(err);
16673 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16674 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16675}
16676
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016677// This is a positive test. No failures are expected.
16678TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016679 TEST_DESCRIPTION(
16680 "Ensure that the vkUpdateDescriptorSets validation code "
16681 "is ignoring VkWriteDescriptorSet members that are not "
16682 "related to the descriptor type specified by "
16683 "VkWriteDescriptorSet::descriptorType. Correct "
16684 "validation behavior will result in the test running to "
16685 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016686
16687 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16688
16689 ASSERT_NO_FATAL_FAILURE(InitState());
16690
16691 // Image Case
16692 {
16693 m_errorMonitor->ExpectSuccess();
16694
16695 VkImage image;
16696 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16697 const int32_t tex_width = 32;
16698 const int32_t tex_height = 32;
16699 VkImageCreateInfo image_create_info = {};
16700 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16701 image_create_info.pNext = NULL;
16702 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16703 image_create_info.format = tex_format;
16704 image_create_info.extent.width = tex_width;
16705 image_create_info.extent.height = tex_height;
16706 image_create_info.extent.depth = 1;
16707 image_create_info.mipLevels = 1;
16708 image_create_info.arrayLayers = 1;
16709 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16710 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16711 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16712 image_create_info.flags = 0;
16713 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16714 ASSERT_VK_SUCCESS(err);
16715
16716 VkMemoryRequirements memory_reqs;
16717 VkDeviceMemory image_memory;
16718 bool pass;
16719 VkMemoryAllocateInfo memory_info = {};
16720 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16721 memory_info.pNext = NULL;
16722 memory_info.allocationSize = 0;
16723 memory_info.memoryTypeIndex = 0;
16724 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16725 memory_info.allocationSize = memory_reqs.size;
16726 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16727 ASSERT_TRUE(pass);
16728 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16729 ASSERT_VK_SUCCESS(err);
16730 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16731 ASSERT_VK_SUCCESS(err);
16732
16733 VkImageViewCreateInfo image_view_create_info = {};
16734 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16735 image_view_create_info.image = image;
16736 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16737 image_view_create_info.format = tex_format;
16738 image_view_create_info.subresourceRange.layerCount = 1;
16739 image_view_create_info.subresourceRange.baseMipLevel = 0;
16740 image_view_create_info.subresourceRange.levelCount = 1;
16741 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16742
16743 VkImageView view;
16744 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16745 ASSERT_VK_SUCCESS(err);
16746
16747 VkDescriptorPoolSize ds_type_count = {};
16748 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16749 ds_type_count.descriptorCount = 1;
16750
16751 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16752 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16753 ds_pool_ci.pNext = NULL;
16754 ds_pool_ci.maxSets = 1;
16755 ds_pool_ci.poolSizeCount = 1;
16756 ds_pool_ci.pPoolSizes = &ds_type_count;
16757
16758 VkDescriptorPool ds_pool;
16759 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16760 ASSERT_VK_SUCCESS(err);
16761
16762 VkDescriptorSetLayoutBinding dsl_binding = {};
16763 dsl_binding.binding = 0;
16764 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16765 dsl_binding.descriptorCount = 1;
16766 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16767 dsl_binding.pImmutableSamplers = NULL;
16768
16769 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16770 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16771 ds_layout_ci.pNext = NULL;
16772 ds_layout_ci.bindingCount = 1;
16773 ds_layout_ci.pBindings = &dsl_binding;
16774 VkDescriptorSetLayout ds_layout;
16775 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16776 ASSERT_VK_SUCCESS(err);
16777
16778 VkDescriptorSet descriptor_set;
16779 VkDescriptorSetAllocateInfo alloc_info = {};
16780 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16781 alloc_info.descriptorSetCount = 1;
16782 alloc_info.descriptorPool = ds_pool;
16783 alloc_info.pSetLayouts = &ds_layout;
16784 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16785 ASSERT_VK_SUCCESS(err);
16786
16787 VkDescriptorImageInfo image_info = {};
16788 image_info.imageView = view;
16789 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16790
16791 VkWriteDescriptorSet descriptor_write;
16792 memset(&descriptor_write, 0, sizeof(descriptor_write));
16793 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16794 descriptor_write.dstSet = descriptor_set;
16795 descriptor_write.dstBinding = 0;
16796 descriptor_write.descriptorCount = 1;
16797 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16798 descriptor_write.pImageInfo = &image_info;
16799
16800 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16801 // be
16802 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16803 // This will most likely produce a crash if the parameter_validation
16804 // layer
16805 // does not correctly ignore pBufferInfo.
16806 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16807 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16808
16809 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16810
16811 m_errorMonitor->VerifyNotFound();
16812
16813 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16814 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16815 vkDestroyImageView(m_device->device(), view, NULL);
16816 vkDestroyImage(m_device->device(), image, NULL);
16817 vkFreeMemory(m_device->device(), image_memory, NULL);
16818 }
16819
16820 // Buffer Case
16821 {
16822 m_errorMonitor->ExpectSuccess();
16823
16824 VkBuffer buffer;
16825 uint32_t queue_family_index = 0;
16826 VkBufferCreateInfo buffer_create_info = {};
16827 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16828 buffer_create_info.size = 1024;
16829 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16830 buffer_create_info.queueFamilyIndexCount = 1;
16831 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16832
16833 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16834 ASSERT_VK_SUCCESS(err);
16835
16836 VkMemoryRequirements memory_reqs;
16837 VkDeviceMemory buffer_memory;
16838 bool pass;
16839 VkMemoryAllocateInfo memory_info = {};
16840 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16841 memory_info.pNext = NULL;
16842 memory_info.allocationSize = 0;
16843 memory_info.memoryTypeIndex = 0;
16844
16845 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16846 memory_info.allocationSize = memory_reqs.size;
16847 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16848 ASSERT_TRUE(pass);
16849
16850 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16851 ASSERT_VK_SUCCESS(err);
16852 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16853 ASSERT_VK_SUCCESS(err);
16854
16855 VkDescriptorPoolSize ds_type_count = {};
16856 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16857 ds_type_count.descriptorCount = 1;
16858
16859 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16860 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16861 ds_pool_ci.pNext = NULL;
16862 ds_pool_ci.maxSets = 1;
16863 ds_pool_ci.poolSizeCount = 1;
16864 ds_pool_ci.pPoolSizes = &ds_type_count;
16865
16866 VkDescriptorPool ds_pool;
16867 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16868 ASSERT_VK_SUCCESS(err);
16869
16870 VkDescriptorSetLayoutBinding dsl_binding = {};
16871 dsl_binding.binding = 0;
16872 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16873 dsl_binding.descriptorCount = 1;
16874 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16875 dsl_binding.pImmutableSamplers = NULL;
16876
16877 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16878 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16879 ds_layout_ci.pNext = NULL;
16880 ds_layout_ci.bindingCount = 1;
16881 ds_layout_ci.pBindings = &dsl_binding;
16882 VkDescriptorSetLayout ds_layout;
16883 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16884 ASSERT_VK_SUCCESS(err);
16885
16886 VkDescriptorSet descriptor_set;
16887 VkDescriptorSetAllocateInfo alloc_info = {};
16888 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16889 alloc_info.descriptorSetCount = 1;
16890 alloc_info.descriptorPool = ds_pool;
16891 alloc_info.pSetLayouts = &ds_layout;
16892 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16893 ASSERT_VK_SUCCESS(err);
16894
16895 VkDescriptorBufferInfo buffer_info = {};
16896 buffer_info.buffer = buffer;
16897 buffer_info.offset = 0;
16898 buffer_info.range = 1024;
16899
16900 VkWriteDescriptorSet descriptor_write;
16901 memset(&descriptor_write, 0, sizeof(descriptor_write));
16902 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16903 descriptor_write.dstSet = descriptor_set;
16904 descriptor_write.dstBinding = 0;
16905 descriptor_write.descriptorCount = 1;
16906 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16907 descriptor_write.pBufferInfo = &buffer_info;
16908
16909 // Set pImageInfo and pTexelBufferView to invalid values, which should
16910 // be
16911 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16912 // This will most likely produce a crash if the parameter_validation
16913 // layer
16914 // does not correctly ignore pImageInfo.
16915 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16916 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16917
16918 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16919
16920 m_errorMonitor->VerifyNotFound();
16921
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016922 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16923 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16924 vkDestroyBuffer(m_device->device(), buffer, NULL);
16925 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16926 }
16927
16928 // Texel Buffer Case
16929 {
16930 m_errorMonitor->ExpectSuccess();
16931
16932 VkBuffer buffer;
16933 uint32_t queue_family_index = 0;
16934 VkBufferCreateInfo buffer_create_info = {};
16935 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16936 buffer_create_info.size = 1024;
16937 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16938 buffer_create_info.queueFamilyIndexCount = 1;
16939 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16940
16941 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16942 ASSERT_VK_SUCCESS(err);
16943
16944 VkMemoryRequirements memory_reqs;
16945 VkDeviceMemory buffer_memory;
16946 bool pass;
16947 VkMemoryAllocateInfo memory_info = {};
16948 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16949 memory_info.pNext = NULL;
16950 memory_info.allocationSize = 0;
16951 memory_info.memoryTypeIndex = 0;
16952
16953 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16954 memory_info.allocationSize = memory_reqs.size;
16955 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16956 ASSERT_TRUE(pass);
16957
16958 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16959 ASSERT_VK_SUCCESS(err);
16960 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16961 ASSERT_VK_SUCCESS(err);
16962
16963 VkBufferViewCreateInfo buff_view_ci = {};
16964 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16965 buff_view_ci.buffer = buffer;
16966 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16967 buff_view_ci.range = VK_WHOLE_SIZE;
16968 VkBufferView buffer_view;
16969 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16970
16971 VkDescriptorPoolSize ds_type_count = {};
16972 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16973 ds_type_count.descriptorCount = 1;
16974
16975 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16976 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16977 ds_pool_ci.pNext = NULL;
16978 ds_pool_ci.maxSets = 1;
16979 ds_pool_ci.poolSizeCount = 1;
16980 ds_pool_ci.pPoolSizes = &ds_type_count;
16981
16982 VkDescriptorPool ds_pool;
16983 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16984 ASSERT_VK_SUCCESS(err);
16985
16986 VkDescriptorSetLayoutBinding dsl_binding = {};
16987 dsl_binding.binding = 0;
16988 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16989 dsl_binding.descriptorCount = 1;
16990 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16991 dsl_binding.pImmutableSamplers = NULL;
16992
16993 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16994 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16995 ds_layout_ci.pNext = NULL;
16996 ds_layout_ci.bindingCount = 1;
16997 ds_layout_ci.pBindings = &dsl_binding;
16998 VkDescriptorSetLayout ds_layout;
16999 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17000 ASSERT_VK_SUCCESS(err);
17001
17002 VkDescriptorSet descriptor_set;
17003 VkDescriptorSetAllocateInfo alloc_info = {};
17004 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17005 alloc_info.descriptorSetCount = 1;
17006 alloc_info.descriptorPool = ds_pool;
17007 alloc_info.pSetLayouts = &ds_layout;
17008 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17009 ASSERT_VK_SUCCESS(err);
17010
17011 VkWriteDescriptorSet descriptor_write;
17012 memset(&descriptor_write, 0, sizeof(descriptor_write));
17013 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17014 descriptor_write.dstSet = descriptor_set;
17015 descriptor_write.dstBinding = 0;
17016 descriptor_write.descriptorCount = 1;
17017 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17018 descriptor_write.pTexelBufferView = &buffer_view;
17019
17020 // Set pImageInfo and pBufferInfo to invalid values, which should be
17021 // ignored for descriptorType ==
17022 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
17023 // This will most likely produce a crash if the parameter_validation
17024 // layer
17025 // does not correctly ignore pImageInfo and pBufferInfo.
17026 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17027 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17028
17029 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17030
17031 m_errorMonitor->VerifyNotFound();
17032
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017033 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17034 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17035 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
17036 vkDestroyBuffer(m_device->device(), buffer, NULL);
17037 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17038 }
17039}
17040
Tobin Ehlisf7428442016-10-25 07:58:24 -060017041TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
17042 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
17043
17044 ASSERT_NO_FATAL_FAILURE(InitState());
17045 // Create layout where two binding #s are "1"
17046 static const uint32_t NUM_BINDINGS = 3;
17047 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17048 dsl_binding[0].binding = 1;
17049 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17050 dsl_binding[0].descriptorCount = 1;
17051 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17052 dsl_binding[0].pImmutableSamplers = NULL;
17053 dsl_binding[1].binding = 0;
17054 dsl_binding[1].descriptorCount = 1;
17055 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17056 dsl_binding[1].descriptorCount = 1;
17057 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17058 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017059 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060017060 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17061 dsl_binding[2].descriptorCount = 1;
17062 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17063 dsl_binding[2].pImmutableSamplers = NULL;
17064
17065 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17066 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17067 ds_layout_ci.pNext = NULL;
17068 ds_layout_ci.bindingCount = NUM_BINDINGS;
17069 ds_layout_ci.pBindings = dsl_binding;
17070 VkDescriptorSetLayout ds_layout;
17071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
17072 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17073 m_errorMonitor->VerifyFound();
17074}
17075
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017076TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017077 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
17078
17079 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017080
Tony Barbour552f6c02016-12-21 14:34:07 -070017081 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017082
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017083 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
17084
17085 {
17086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
17087 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
17088 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17089 m_errorMonitor->VerifyFound();
17090 }
17091
17092 {
17093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
17094 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
17095 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17096 m_errorMonitor->VerifyFound();
17097 }
17098
17099 {
17100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17101 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
17102 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17103 m_errorMonitor->VerifyFound();
17104 }
17105
17106 {
17107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17108 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
17109 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17110 m_errorMonitor->VerifyFound();
17111 }
17112
17113 {
17114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
17115 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
17116 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17117 m_errorMonitor->VerifyFound();
17118 }
17119
17120 {
17121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
17122 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
17123 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17124 m_errorMonitor->VerifyFound();
17125 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017126
17127 {
17128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17129 VkRect2D scissor = {{-1, 0}, {16, 16}};
17130 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17131 m_errorMonitor->VerifyFound();
17132 }
17133
17134 {
17135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17136 VkRect2D scissor = {{0, -2}, {16, 16}};
17137 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17138 m_errorMonitor->VerifyFound();
17139 }
17140
17141 {
17142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
17143 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
17144 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17145 m_errorMonitor->VerifyFound();
17146 }
17147
17148 {
17149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
17150 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
17151 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17152 m_errorMonitor->VerifyFound();
17153 }
17154
Tony Barbour552f6c02016-12-21 14:34:07 -070017155 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017156}
17157
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017158// This is a positive test. No failures are expected.
17159TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
17160 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
17161 VkResult err;
17162
17163 ASSERT_NO_FATAL_FAILURE(InitState());
17164 m_errorMonitor->ExpectSuccess();
17165 VkDescriptorPoolSize ds_type_count = {};
17166 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17167 ds_type_count.descriptorCount = 2;
17168
17169 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17170 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17171 ds_pool_ci.pNext = NULL;
17172 ds_pool_ci.maxSets = 1;
17173 ds_pool_ci.poolSizeCount = 1;
17174 ds_pool_ci.pPoolSizes = &ds_type_count;
17175
17176 VkDescriptorPool ds_pool;
17177 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17178 ASSERT_VK_SUCCESS(err);
17179
17180 // Create layout with two uniform buffer descriptors w/ empty binding between them
17181 static const uint32_t NUM_BINDINGS = 3;
17182 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17183 dsl_binding[0].binding = 0;
17184 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17185 dsl_binding[0].descriptorCount = 1;
17186 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
17187 dsl_binding[0].pImmutableSamplers = NULL;
17188 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017189 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017190 dsl_binding[2].binding = 2;
17191 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17192 dsl_binding[2].descriptorCount = 1;
17193 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
17194 dsl_binding[2].pImmutableSamplers = NULL;
17195
17196 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17197 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17198 ds_layout_ci.pNext = NULL;
17199 ds_layout_ci.bindingCount = NUM_BINDINGS;
17200 ds_layout_ci.pBindings = dsl_binding;
17201 VkDescriptorSetLayout ds_layout;
17202 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17203 ASSERT_VK_SUCCESS(err);
17204
17205 VkDescriptorSet descriptor_set = {};
17206 VkDescriptorSetAllocateInfo alloc_info = {};
17207 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17208 alloc_info.descriptorSetCount = 1;
17209 alloc_info.descriptorPool = ds_pool;
17210 alloc_info.pSetLayouts = &ds_layout;
17211 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17212 ASSERT_VK_SUCCESS(err);
17213
17214 // Create a buffer to be used for update
17215 VkBufferCreateInfo buff_ci = {};
17216 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17217 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17218 buff_ci.size = 256;
17219 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17220 VkBuffer buffer;
17221 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
17222 ASSERT_VK_SUCCESS(err);
17223 // Have to bind memory to buffer before descriptor update
17224 VkMemoryAllocateInfo mem_alloc = {};
17225 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17226 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017227 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017228 mem_alloc.memoryTypeIndex = 0;
17229
17230 VkMemoryRequirements mem_reqs;
17231 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17232 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
17233 if (!pass) {
17234 vkDestroyBuffer(m_device->device(), buffer, NULL);
17235 return;
17236 }
17237
17238 VkDeviceMemory mem;
17239 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17240 ASSERT_VK_SUCCESS(err);
17241 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17242 ASSERT_VK_SUCCESS(err);
17243
17244 // Only update the descriptor at binding 2
17245 VkDescriptorBufferInfo buff_info = {};
17246 buff_info.buffer = buffer;
17247 buff_info.offset = 0;
17248 buff_info.range = VK_WHOLE_SIZE;
17249 VkWriteDescriptorSet descriptor_write = {};
17250 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17251 descriptor_write.dstBinding = 2;
17252 descriptor_write.descriptorCount = 1;
17253 descriptor_write.pTexelBufferView = nullptr;
17254 descriptor_write.pBufferInfo = &buff_info;
17255 descriptor_write.pImageInfo = nullptr;
17256 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17257 descriptor_write.dstSet = descriptor_set;
17258
17259 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17260
17261 m_errorMonitor->VerifyNotFound();
17262 // Cleanup
17263 vkFreeMemory(m_device->device(), mem, NULL);
17264 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17265 vkDestroyBuffer(m_device->device(), buffer, NULL);
17266 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17267}
17268
17269// This is a positive test. No failures are expected.
17270TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
17271 VkResult err;
17272 bool pass;
17273
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017274 TEST_DESCRIPTION(
17275 "Create a buffer, allocate memory, bind memory, destroy "
17276 "the buffer, create an image, and bind the same memory to "
17277 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017278
17279 m_errorMonitor->ExpectSuccess();
17280
17281 ASSERT_NO_FATAL_FAILURE(InitState());
17282
17283 VkBuffer buffer;
17284 VkImage image;
17285 VkDeviceMemory mem;
17286 VkMemoryRequirements mem_reqs;
17287
17288 VkBufferCreateInfo buf_info = {};
17289 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17290 buf_info.pNext = NULL;
17291 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17292 buf_info.size = 256;
17293 buf_info.queueFamilyIndexCount = 0;
17294 buf_info.pQueueFamilyIndices = NULL;
17295 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17296 buf_info.flags = 0;
17297 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17298 ASSERT_VK_SUCCESS(err);
17299
17300 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17301
17302 VkMemoryAllocateInfo alloc_info = {};
17303 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17304 alloc_info.pNext = NULL;
17305 alloc_info.memoryTypeIndex = 0;
17306
17307 // Ensure memory is big enough for both bindings
17308 alloc_info.allocationSize = 0x10000;
17309
17310 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17311 if (!pass) {
17312 vkDestroyBuffer(m_device->device(), buffer, NULL);
17313 return;
17314 }
17315
17316 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17317 ASSERT_VK_SUCCESS(err);
17318
17319 uint8_t *pData;
17320 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17321 ASSERT_VK_SUCCESS(err);
17322
17323 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17324
17325 vkUnmapMemory(m_device->device(), mem);
17326
17327 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17328 ASSERT_VK_SUCCESS(err);
17329
17330 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17331 // memory. In fact, it was never used by the GPU.
17332 // Just be be sure, wait for idle.
17333 vkDestroyBuffer(m_device->device(), buffer, NULL);
17334 vkDeviceWaitIdle(m_device->device());
17335
Tobin Ehlis6a005702016-12-28 15:25:56 -070017336 // Use optimal as some platforms report linear support but then fail image creation
17337 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17338 VkImageFormatProperties image_format_properties;
17339 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17340 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17341 if (image_format_properties.maxExtent.width == 0) {
17342 printf("Image format not supported; skipped.\n");
17343 vkFreeMemory(m_device->device(), mem, NULL);
17344 return;
17345 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017346 VkImageCreateInfo image_create_info = {};
17347 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17348 image_create_info.pNext = NULL;
17349 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17350 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17351 image_create_info.extent.width = 64;
17352 image_create_info.extent.height = 64;
17353 image_create_info.extent.depth = 1;
17354 image_create_info.mipLevels = 1;
17355 image_create_info.arrayLayers = 1;
17356 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017357 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017358 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17359 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17360 image_create_info.queueFamilyIndexCount = 0;
17361 image_create_info.pQueueFamilyIndices = NULL;
17362 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17363 image_create_info.flags = 0;
17364
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017365 /* Create a mappable image. It will be the texture if linear images are ok
17366 * to be textures or it will be the staging image if they are not.
17367 */
17368 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17369 ASSERT_VK_SUCCESS(err);
17370
17371 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17372
Tobin Ehlis6a005702016-12-28 15:25:56 -070017373 VkMemoryAllocateInfo mem_alloc = {};
17374 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17375 mem_alloc.pNext = NULL;
17376 mem_alloc.allocationSize = 0;
17377 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017378 mem_alloc.allocationSize = mem_reqs.size;
17379
17380 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17381 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017382 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017383 vkDestroyImage(m_device->device(), image, NULL);
17384 return;
17385 }
17386
17387 // VALIDATION FAILURE:
17388 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17389 ASSERT_VK_SUCCESS(err);
17390
17391 m_errorMonitor->VerifyNotFound();
17392
17393 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017394 vkDestroyImage(m_device->device(), image, NULL);
17395}
17396
Tobin Ehlis953e8392016-11-17 10:54:13 -070017397TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17398 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17399 // We previously had a bug where dynamic offset of inactive bindings was still being used
17400 VkResult err;
17401 m_errorMonitor->ExpectSuccess();
17402
17403 ASSERT_NO_FATAL_FAILURE(InitState());
17404 ASSERT_NO_FATAL_FAILURE(InitViewport());
17405 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17406
17407 VkDescriptorPoolSize ds_type_count = {};
17408 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17409 ds_type_count.descriptorCount = 3;
17410
17411 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17412 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17413 ds_pool_ci.pNext = NULL;
17414 ds_pool_ci.maxSets = 1;
17415 ds_pool_ci.poolSizeCount = 1;
17416 ds_pool_ci.pPoolSizes = &ds_type_count;
17417
17418 VkDescriptorPool ds_pool;
17419 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17420 ASSERT_VK_SUCCESS(err);
17421
17422 const uint32_t BINDING_COUNT = 3;
17423 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017424 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017425 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17426 dsl_binding[0].descriptorCount = 1;
17427 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17428 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017429 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017430 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17431 dsl_binding[1].descriptorCount = 1;
17432 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17433 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017434 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017435 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17436 dsl_binding[2].descriptorCount = 1;
17437 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17438 dsl_binding[2].pImmutableSamplers = NULL;
17439
17440 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17441 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17442 ds_layout_ci.pNext = NULL;
17443 ds_layout_ci.bindingCount = BINDING_COUNT;
17444 ds_layout_ci.pBindings = dsl_binding;
17445 VkDescriptorSetLayout ds_layout;
17446 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17447 ASSERT_VK_SUCCESS(err);
17448
17449 VkDescriptorSet descriptor_set;
17450 VkDescriptorSetAllocateInfo alloc_info = {};
17451 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17452 alloc_info.descriptorSetCount = 1;
17453 alloc_info.descriptorPool = ds_pool;
17454 alloc_info.pSetLayouts = &ds_layout;
17455 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17456 ASSERT_VK_SUCCESS(err);
17457
17458 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17459 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17460 pipeline_layout_ci.pNext = NULL;
17461 pipeline_layout_ci.setLayoutCount = 1;
17462 pipeline_layout_ci.pSetLayouts = &ds_layout;
17463
17464 VkPipelineLayout pipeline_layout;
17465 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17466 ASSERT_VK_SUCCESS(err);
17467
17468 // Create two buffers to update the descriptors with
17469 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17470 uint32_t qfi = 0;
17471 VkBufferCreateInfo buffCI = {};
17472 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17473 buffCI.size = 2048;
17474 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17475 buffCI.queueFamilyIndexCount = 1;
17476 buffCI.pQueueFamilyIndices = &qfi;
17477
17478 VkBuffer dyub1;
17479 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17480 ASSERT_VK_SUCCESS(err);
17481 // buffer2
17482 buffCI.size = 1024;
17483 VkBuffer dyub2;
17484 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17485 ASSERT_VK_SUCCESS(err);
17486 // Allocate memory and bind to buffers
17487 VkMemoryAllocateInfo mem_alloc[2] = {};
17488 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17489 mem_alloc[0].pNext = NULL;
17490 mem_alloc[0].memoryTypeIndex = 0;
17491 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17492 mem_alloc[1].pNext = NULL;
17493 mem_alloc[1].memoryTypeIndex = 0;
17494
17495 VkMemoryRequirements mem_reqs1;
17496 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17497 VkMemoryRequirements mem_reqs2;
17498 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17499 mem_alloc[0].allocationSize = mem_reqs1.size;
17500 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17501 mem_alloc[1].allocationSize = mem_reqs2.size;
17502 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17503 if (!pass) {
17504 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17505 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17506 return;
17507 }
17508
17509 VkDeviceMemory mem1;
17510 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17511 ASSERT_VK_SUCCESS(err);
17512 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17513 ASSERT_VK_SUCCESS(err);
17514 VkDeviceMemory mem2;
17515 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17516 ASSERT_VK_SUCCESS(err);
17517 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17518 ASSERT_VK_SUCCESS(err);
17519 // Update descriptors
17520 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17521 buff_info[0].buffer = dyub1;
17522 buff_info[0].offset = 0;
17523 buff_info[0].range = 256;
17524 buff_info[1].buffer = dyub1;
17525 buff_info[1].offset = 256;
17526 buff_info[1].range = 512;
17527 buff_info[2].buffer = dyub2;
17528 buff_info[2].offset = 0;
17529 buff_info[2].range = 512;
17530
17531 VkWriteDescriptorSet descriptor_write;
17532 memset(&descriptor_write, 0, sizeof(descriptor_write));
17533 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17534 descriptor_write.dstSet = descriptor_set;
17535 descriptor_write.dstBinding = 0;
17536 descriptor_write.descriptorCount = BINDING_COUNT;
17537 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17538 descriptor_write.pBufferInfo = buff_info;
17539
17540 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17541
Tony Barbour552f6c02016-12-21 14:34:07 -070017542 m_commandBuffer->BeginCommandBuffer();
17543 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017544
17545 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017546 char const *vsSource =
17547 "#version 450\n"
17548 "\n"
17549 "out gl_PerVertex { \n"
17550 " vec4 gl_Position;\n"
17551 "};\n"
17552 "void main(){\n"
17553 " gl_Position = vec4(1);\n"
17554 "}\n";
17555 char const *fsSource =
17556 "#version 450\n"
17557 "\n"
17558 "layout(location=0) out vec4 x;\n"
17559 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17560 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17561 "void main(){\n"
17562 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17563 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070017564 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17565 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17566 VkPipelineObj pipe(m_device);
17567 pipe.SetViewport(m_viewports);
17568 pipe.SetScissor(m_scissors);
17569 pipe.AddShader(&vs);
17570 pipe.AddShader(&fs);
17571 pipe.AddColorAttachment();
17572 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17573
17574 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17575 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17576 // we used to have a bug in this case.
17577 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17578 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17579 &descriptor_set, BINDING_COUNT, dyn_off);
17580 Draw(1, 0, 0, 0);
17581 m_errorMonitor->VerifyNotFound();
17582
17583 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17584 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17585 vkFreeMemory(m_device->device(), mem1, NULL);
17586 vkFreeMemory(m_device->device(), mem2, NULL);
17587
17588 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17589 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17590 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17591}
17592
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017593TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017594 TEST_DESCRIPTION(
17595 "Ensure that validations handling of non-coherent memory "
17596 "mapping while using VK_WHOLE_SIZE does not cause access "
17597 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017598 VkResult err;
17599 uint8_t *pData;
17600 ASSERT_NO_FATAL_FAILURE(InitState());
17601
17602 VkDeviceMemory mem;
17603 VkMemoryRequirements mem_reqs;
17604 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017605 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017606 VkMemoryAllocateInfo alloc_info = {};
17607 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17608 alloc_info.pNext = NULL;
17609 alloc_info.memoryTypeIndex = 0;
17610
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017611 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017612 alloc_info.allocationSize = allocation_size;
17613
17614 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17615 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 -070017616 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017617 if (!pass) {
17618 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017619 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17620 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017621 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017622 pass = m_device->phy().set_memory_type(
17623 mem_reqs.memoryTypeBits, &alloc_info,
17624 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17625 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017626 if (!pass) {
17627 return;
17628 }
17629 }
17630 }
17631
17632 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17633 ASSERT_VK_SUCCESS(err);
17634
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017635 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017636 m_errorMonitor->ExpectSuccess();
17637 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17638 ASSERT_VK_SUCCESS(err);
17639 VkMappedMemoryRange mmr = {};
17640 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17641 mmr.memory = mem;
17642 mmr.offset = 0;
17643 mmr.size = VK_WHOLE_SIZE;
17644 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17645 ASSERT_VK_SUCCESS(err);
17646 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17647 ASSERT_VK_SUCCESS(err);
17648 m_errorMonitor->VerifyNotFound();
17649 vkUnmapMemory(m_device->device(), mem);
17650
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017651 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017652 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017653 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017654 ASSERT_VK_SUCCESS(err);
17655 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17656 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017657 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017658 mmr.size = VK_WHOLE_SIZE;
17659 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17660 ASSERT_VK_SUCCESS(err);
17661 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17662 ASSERT_VK_SUCCESS(err);
17663 m_errorMonitor->VerifyNotFound();
17664 vkUnmapMemory(m_device->device(), mem);
17665
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017666 // Map with offset and size
17667 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017668 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017669 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017670 ASSERT_VK_SUCCESS(err);
17671 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17672 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017673 mmr.offset = 4 * atom_size;
17674 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017675 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17676 ASSERT_VK_SUCCESS(err);
17677 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17678 ASSERT_VK_SUCCESS(err);
17679 m_errorMonitor->VerifyNotFound();
17680 vkUnmapMemory(m_device->device(), mem);
17681
17682 // Map without offset and flush WHOLE_SIZE with two separate offsets
17683 m_errorMonitor->ExpectSuccess();
17684 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17685 ASSERT_VK_SUCCESS(err);
17686 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17687 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017688 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017689 mmr.size = VK_WHOLE_SIZE;
17690 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17691 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017692 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017693 mmr.size = VK_WHOLE_SIZE;
17694 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17695 ASSERT_VK_SUCCESS(err);
17696 m_errorMonitor->VerifyNotFound();
17697 vkUnmapMemory(m_device->device(), mem);
17698
17699 vkFreeMemory(m_device->device(), mem, NULL);
17700}
17701
17702// This is a positive test. We used to expect error in this case but spec now allows it
17703TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17704 m_errorMonitor->ExpectSuccess();
17705 vk_testing::Fence testFence;
17706 VkFenceCreateInfo fenceInfo = {};
17707 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17708 fenceInfo.pNext = NULL;
17709
17710 ASSERT_NO_FATAL_FAILURE(InitState());
17711 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017712 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017713 VkResult result = vkResetFences(m_device->device(), 1, fences);
17714 ASSERT_VK_SUCCESS(result);
17715
17716 m_errorMonitor->VerifyNotFound();
17717}
17718
17719TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17720 m_errorMonitor->ExpectSuccess();
17721
17722 ASSERT_NO_FATAL_FAILURE(InitState());
17723 VkResult err;
17724
17725 // Record (empty!) command buffer that can be submitted multiple times
17726 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017727 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17728 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017729 m_commandBuffer->BeginCommandBuffer(&cbbi);
17730 m_commandBuffer->EndCommandBuffer();
17731
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017732 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017733 VkFence fence;
17734 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17735 ASSERT_VK_SUCCESS(err);
17736
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017737 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017738 VkSemaphore s1, s2;
17739 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17740 ASSERT_VK_SUCCESS(err);
17741 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17742 ASSERT_VK_SUCCESS(err);
17743
17744 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017745 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017746 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17747 ASSERT_VK_SUCCESS(err);
17748
17749 // Submit CB again, signaling s2.
17750 si.pSignalSemaphores = &s2;
17751 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17752 ASSERT_VK_SUCCESS(err);
17753
17754 // Wait for fence.
17755 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17756 ASSERT_VK_SUCCESS(err);
17757
17758 // CB is still in flight from second submission, but semaphore s1 is no
17759 // longer in flight. delete it.
17760 vkDestroySemaphore(m_device->device(), s1, nullptr);
17761
17762 m_errorMonitor->VerifyNotFound();
17763
17764 // Force device idle and clean up remaining objects
17765 vkDeviceWaitIdle(m_device->device());
17766 vkDestroySemaphore(m_device->device(), s2, nullptr);
17767 vkDestroyFence(m_device->device(), fence, nullptr);
17768}
17769
17770TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17771 m_errorMonitor->ExpectSuccess();
17772
17773 ASSERT_NO_FATAL_FAILURE(InitState());
17774 VkResult err;
17775
17776 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017777 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017778 VkFence f1;
17779 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17780 ASSERT_VK_SUCCESS(err);
17781
17782 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017783 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017784 VkFence f2;
17785 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17786 ASSERT_VK_SUCCESS(err);
17787
17788 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017789 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017790 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17791
17792 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017793 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017794 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17795
17796 // Should have both retired!
17797 vkDestroyFence(m_device->device(), f1, nullptr);
17798 vkDestroyFence(m_device->device(), f2, nullptr);
17799
17800 m_errorMonitor->VerifyNotFound();
17801}
17802
17803TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017804 TEST_DESCRIPTION(
17805 "Verify that creating an image view from an image with valid usage "
17806 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017807
17808 ASSERT_NO_FATAL_FAILURE(InitState());
17809
17810 m_errorMonitor->ExpectSuccess();
17811 // Verify that we can create a view with usage INPUT_ATTACHMENT
17812 VkImageObj image(m_device);
17813 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17814 ASSERT_TRUE(image.initialized());
17815 VkImageView imageView;
17816 VkImageViewCreateInfo ivci = {};
17817 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17818 ivci.image = image.handle();
17819 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17820 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17821 ivci.subresourceRange.layerCount = 1;
17822 ivci.subresourceRange.baseMipLevel = 0;
17823 ivci.subresourceRange.levelCount = 1;
17824 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17825
17826 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17827 m_errorMonitor->VerifyNotFound();
17828 vkDestroyImageView(m_device->device(), imageView, NULL);
17829}
17830
17831// This is a positive test. No failures are expected.
17832TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017833 TEST_DESCRIPTION(
17834 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17835 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017836
17837 ASSERT_NO_FATAL_FAILURE(InitState());
17838
17839 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017840 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017841
17842 m_errorMonitor->ExpectSuccess();
17843
17844 VkImage image;
17845 VkImageCreateInfo image_create_info = {};
17846 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17847 image_create_info.pNext = NULL;
17848 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17849 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17850 image_create_info.extent.width = 64;
17851 image_create_info.extent.height = 64;
17852 image_create_info.extent.depth = 1;
17853 image_create_info.mipLevels = 1;
17854 image_create_info.arrayLayers = 1;
17855 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17856 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17857 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17858 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17859 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17860 ASSERT_VK_SUCCESS(err);
17861
17862 VkMemoryRequirements memory_reqs;
17863 VkDeviceMemory memory_one, memory_two;
17864 bool pass;
17865 VkMemoryAllocateInfo memory_info = {};
17866 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17867 memory_info.pNext = NULL;
17868 memory_info.allocationSize = 0;
17869 memory_info.memoryTypeIndex = 0;
17870 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17871 // Find an image big enough to allow sparse mapping of 2 memory regions
17872 // Increase the image size until it is at least twice the
17873 // size of the required alignment, to ensure we can bind both
17874 // allocated memory blocks to the image on aligned offsets.
17875 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17876 vkDestroyImage(m_device->device(), image, nullptr);
17877 image_create_info.extent.width *= 2;
17878 image_create_info.extent.height *= 2;
17879 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17880 ASSERT_VK_SUCCESS(err);
17881 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17882 }
17883 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17884 // at the end of the first
17885 memory_info.allocationSize = memory_reqs.alignment;
17886 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17887 ASSERT_TRUE(pass);
17888 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17889 ASSERT_VK_SUCCESS(err);
17890 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17891 ASSERT_VK_SUCCESS(err);
17892 VkSparseMemoryBind binds[2];
17893 binds[0].flags = 0;
17894 binds[0].memory = memory_one;
17895 binds[0].memoryOffset = 0;
17896 binds[0].resourceOffset = 0;
17897 binds[0].size = memory_info.allocationSize;
17898 binds[1].flags = 0;
17899 binds[1].memory = memory_two;
17900 binds[1].memoryOffset = 0;
17901 binds[1].resourceOffset = memory_info.allocationSize;
17902 binds[1].size = memory_info.allocationSize;
17903
17904 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17905 opaqueBindInfo.image = image;
17906 opaqueBindInfo.bindCount = 2;
17907 opaqueBindInfo.pBinds = binds;
17908
17909 VkFence fence = VK_NULL_HANDLE;
17910 VkBindSparseInfo bindSparseInfo = {};
17911 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17912 bindSparseInfo.imageOpaqueBindCount = 1;
17913 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17914
17915 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17916 vkQueueWaitIdle(m_device->m_queue);
17917 vkDestroyImage(m_device->device(), image, NULL);
17918 vkFreeMemory(m_device->device(), memory_one, NULL);
17919 vkFreeMemory(m_device->device(), memory_two, NULL);
17920 m_errorMonitor->VerifyNotFound();
17921}
17922
17923TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017924 TEST_DESCRIPTION(
17925 "Ensure that CmdBeginRenderPass with an attachment's "
17926 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17927 "the command buffer has prior knowledge of that "
17928 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017929
17930 m_errorMonitor->ExpectSuccess();
17931
17932 ASSERT_NO_FATAL_FAILURE(InitState());
17933
17934 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017935 VkAttachmentDescription attachment = {0,
17936 VK_FORMAT_R8G8B8A8_UNORM,
17937 VK_SAMPLE_COUNT_1_BIT,
17938 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17939 VK_ATTACHMENT_STORE_OP_STORE,
17940 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17941 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17942 VK_IMAGE_LAYOUT_UNDEFINED,
17943 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017944
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017945 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017946
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017947 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017948
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017949 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017950
17951 VkRenderPass rp;
17952 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17953 ASSERT_VK_SUCCESS(err);
17954
17955 // A compatible framebuffer.
17956 VkImageObj image(m_device);
17957 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17958 ASSERT_TRUE(image.initialized());
17959
17960 VkImageViewCreateInfo ivci = {
17961 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17962 nullptr,
17963 0,
17964 image.handle(),
17965 VK_IMAGE_VIEW_TYPE_2D,
17966 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017967 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17968 VK_COMPONENT_SWIZZLE_IDENTITY},
17969 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017970 };
17971 VkImageView view;
17972 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17973 ASSERT_VK_SUCCESS(err);
17974
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017975 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017976 VkFramebuffer fb;
17977 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17978 ASSERT_VK_SUCCESS(err);
17979
17980 // Record a single command buffer which uses this renderpass twice. The
17981 // bug is triggered at the beginning of the second renderpass, when the
17982 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017983 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 -070017984 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017985 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17986 vkCmdEndRenderPass(m_commandBuffer->handle());
17987 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17988
17989 m_errorMonitor->VerifyNotFound();
17990
17991 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017992 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017993
17994 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17995 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17996 vkDestroyImageView(m_device->device(), view, nullptr);
17997}
17998
17999TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018000 TEST_DESCRIPTION(
18001 "This test should pass. Create a Framebuffer and "
18002 "command buffer, bind them together, then destroy "
18003 "command pool and framebuffer and verify there are no "
18004 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018005
18006 m_errorMonitor->ExpectSuccess();
18007
18008 ASSERT_NO_FATAL_FAILURE(InitState());
18009
18010 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018011 VkAttachmentDescription attachment = {0,
18012 VK_FORMAT_R8G8B8A8_UNORM,
18013 VK_SAMPLE_COUNT_1_BIT,
18014 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18015 VK_ATTACHMENT_STORE_OP_STORE,
18016 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18017 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18018 VK_IMAGE_LAYOUT_UNDEFINED,
18019 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018020
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018021 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018022
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018023 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018024
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018025 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018026
18027 VkRenderPass rp;
18028 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18029 ASSERT_VK_SUCCESS(err);
18030
18031 // A compatible framebuffer.
18032 VkImageObj image(m_device);
18033 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18034 ASSERT_TRUE(image.initialized());
18035
18036 VkImageViewCreateInfo ivci = {
18037 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18038 nullptr,
18039 0,
18040 image.handle(),
18041 VK_IMAGE_VIEW_TYPE_2D,
18042 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018043 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18044 VK_COMPONENT_SWIZZLE_IDENTITY},
18045 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018046 };
18047 VkImageView view;
18048 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18049 ASSERT_VK_SUCCESS(err);
18050
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018051 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018052 VkFramebuffer fb;
18053 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18054 ASSERT_VK_SUCCESS(err);
18055
18056 // Explicitly create a command buffer to bind the FB to so that we can then
18057 // destroy the command pool in order to implicitly free command buffer
18058 VkCommandPool command_pool;
18059 VkCommandPoolCreateInfo pool_create_info{};
18060 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18061 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18062 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18063 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18064
18065 VkCommandBuffer command_buffer;
18066 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18067 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18068 command_buffer_allocate_info.commandPool = command_pool;
18069 command_buffer_allocate_info.commandBufferCount = 1;
18070 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18071 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18072
18073 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018074 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 -060018075 VkCommandBufferBeginInfo begin_info{};
18076 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18077 vkBeginCommandBuffer(command_buffer, &begin_info);
18078
18079 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18080 vkCmdEndRenderPass(command_buffer);
18081 vkEndCommandBuffer(command_buffer);
18082 vkDestroyImageView(m_device->device(), view, nullptr);
18083 // Destroy command pool to implicitly free command buffer
18084 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18085 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18086 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18087 m_errorMonitor->VerifyNotFound();
18088}
18089
18090TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018091 TEST_DESCRIPTION(
18092 "Ensure that CmdBeginRenderPass applies the layout "
18093 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018094
18095 m_errorMonitor->ExpectSuccess();
18096
18097 ASSERT_NO_FATAL_FAILURE(InitState());
18098
18099 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018100 VkAttachmentDescription attachment = {0,
18101 VK_FORMAT_R8G8B8A8_UNORM,
18102 VK_SAMPLE_COUNT_1_BIT,
18103 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18104 VK_ATTACHMENT_STORE_OP_STORE,
18105 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18106 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18107 VK_IMAGE_LAYOUT_UNDEFINED,
18108 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018109
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018110 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018111
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018112 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018113
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018114 VkSubpassDependency dep = {0,
18115 0,
18116 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18117 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18118 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18119 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18120 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018121
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018122 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018123
18124 VkResult err;
18125 VkRenderPass rp;
18126 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18127 ASSERT_VK_SUCCESS(err);
18128
18129 // A compatible framebuffer.
18130 VkImageObj image(m_device);
18131 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18132 ASSERT_TRUE(image.initialized());
18133
18134 VkImageViewCreateInfo ivci = {
18135 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18136 nullptr,
18137 0,
18138 image.handle(),
18139 VK_IMAGE_VIEW_TYPE_2D,
18140 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018141 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18142 VK_COMPONENT_SWIZZLE_IDENTITY},
18143 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018144 };
18145 VkImageView view;
18146 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18147 ASSERT_VK_SUCCESS(err);
18148
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018149 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018150 VkFramebuffer fb;
18151 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18152 ASSERT_VK_SUCCESS(err);
18153
18154 // Record a single command buffer which issues a pipeline barrier w/
18155 // image memory barrier for the attachment. This detects the previously
18156 // missing tracking of the subpass layout by throwing a validation error
18157 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018158 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 -070018159 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018160 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18161
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018162 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
18163 nullptr,
18164 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18165 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18166 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18167 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18168 VK_QUEUE_FAMILY_IGNORED,
18169 VK_QUEUE_FAMILY_IGNORED,
18170 image.handle(),
18171 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018172 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018173 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18174 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018175
18176 vkCmdEndRenderPass(m_commandBuffer->handle());
18177 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018178 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018179
18180 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18181 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18182 vkDestroyImageView(m_device->device(), view, nullptr);
18183}
18184
18185TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018186 TEST_DESCRIPTION(
18187 "Validate that when an imageView of a depth/stencil image "
18188 "is used as a depth/stencil framebuffer attachment, the "
18189 "aspectMask is ignored and both depth and stencil image "
18190 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018191
18192 VkFormatProperties format_properties;
18193 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
18194 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
18195 return;
18196 }
18197
18198 m_errorMonitor->ExpectSuccess();
18199
18200 ASSERT_NO_FATAL_FAILURE(InitState());
18201
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018202 VkAttachmentDescription attachment = {0,
18203 VK_FORMAT_D32_SFLOAT_S8_UINT,
18204 VK_SAMPLE_COUNT_1_BIT,
18205 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18206 VK_ATTACHMENT_STORE_OP_STORE,
18207 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18208 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18209 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
18210 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018211
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018212 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018213
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018214 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018215
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018216 VkSubpassDependency dep = {0,
18217 0,
18218 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18219 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18220 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18221 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18222 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018223
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018224 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018225
18226 VkResult err;
18227 VkRenderPass rp;
18228 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18229 ASSERT_VK_SUCCESS(err);
18230
18231 VkImageObj image(m_device);
18232 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018233 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018234 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018235 ASSERT_TRUE(image.initialized());
18236 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
18237
18238 VkImageViewCreateInfo ivci = {
18239 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18240 nullptr,
18241 0,
18242 image.handle(),
18243 VK_IMAGE_VIEW_TYPE_2D,
18244 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018245 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
18246 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018247 };
18248 VkImageView view;
18249 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18250 ASSERT_VK_SUCCESS(err);
18251
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018252 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018253 VkFramebuffer fb;
18254 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18255 ASSERT_VK_SUCCESS(err);
18256
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018257 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 -070018258 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018259 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18260
18261 VkImageMemoryBarrier imb = {};
18262 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18263 imb.pNext = nullptr;
18264 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18265 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18266 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18267 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18268 imb.srcQueueFamilyIndex = 0;
18269 imb.dstQueueFamilyIndex = 0;
18270 imb.image = image.handle();
18271 imb.subresourceRange.aspectMask = 0x6;
18272 imb.subresourceRange.baseMipLevel = 0;
18273 imb.subresourceRange.levelCount = 0x1;
18274 imb.subresourceRange.baseArrayLayer = 0;
18275 imb.subresourceRange.layerCount = 0x1;
18276
18277 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018278 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18279 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018280
18281 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018282 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018283 QueueCommandBuffer(false);
18284 m_errorMonitor->VerifyNotFound();
18285
18286 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18287 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18288 vkDestroyImageView(m_device->device(), view, nullptr);
18289}
18290
18291TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018292 TEST_DESCRIPTION(
18293 "Ensure that layout transitions work correctly without "
18294 "errors, when an attachment reference is "
18295 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018296
18297 m_errorMonitor->ExpectSuccess();
18298
18299 ASSERT_NO_FATAL_FAILURE(InitState());
18300
18301 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018302 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018303
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018304 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018305
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018306 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018307
18308 VkRenderPass rp;
18309 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18310 ASSERT_VK_SUCCESS(err);
18311
18312 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018313 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018314 VkFramebuffer fb;
18315 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18316 ASSERT_VK_SUCCESS(err);
18317
18318 // Record a command buffer which just begins and ends the renderpass. The
18319 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018320 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 -070018321 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018322 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18323 vkCmdEndRenderPass(m_commandBuffer->handle());
18324 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018325 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018326
18327 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18328 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18329}
18330
18331// This is a positive test. No errors are expected.
18332TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018333 TEST_DESCRIPTION(
18334 "Create a stencil-only attachment with a LOAD_OP set to "
18335 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018336 VkResult result = VK_SUCCESS;
18337 VkImageFormatProperties formatProps;
18338 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018339 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18340 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018341 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18342 return;
18343 }
18344
18345 ASSERT_NO_FATAL_FAILURE(InitState());
18346 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18347 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018348 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018349 VkAttachmentDescription att = {};
18350 VkAttachmentReference ref = {};
18351 att.format = depth_stencil_fmt;
18352 att.samples = VK_SAMPLE_COUNT_1_BIT;
18353 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18354 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18355 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18356 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18357 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18358 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18359
18360 VkClearValue clear;
18361 clear.depthStencil.depth = 1.0;
18362 clear.depthStencil.stencil = 0;
18363 ref.attachment = 0;
18364 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18365
18366 VkSubpassDescription subpass = {};
18367 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18368 subpass.flags = 0;
18369 subpass.inputAttachmentCount = 0;
18370 subpass.pInputAttachments = NULL;
18371 subpass.colorAttachmentCount = 0;
18372 subpass.pColorAttachments = NULL;
18373 subpass.pResolveAttachments = NULL;
18374 subpass.pDepthStencilAttachment = &ref;
18375 subpass.preserveAttachmentCount = 0;
18376 subpass.pPreserveAttachments = NULL;
18377
18378 VkRenderPass rp;
18379 VkRenderPassCreateInfo rp_info = {};
18380 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18381 rp_info.attachmentCount = 1;
18382 rp_info.pAttachments = &att;
18383 rp_info.subpassCount = 1;
18384 rp_info.pSubpasses = &subpass;
18385 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18386 ASSERT_VK_SUCCESS(result);
18387
18388 VkImageView *depthView = m_depthStencil->BindInfo();
18389 VkFramebufferCreateInfo fb_info = {};
18390 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18391 fb_info.pNext = NULL;
18392 fb_info.renderPass = rp;
18393 fb_info.attachmentCount = 1;
18394 fb_info.pAttachments = depthView;
18395 fb_info.width = 100;
18396 fb_info.height = 100;
18397 fb_info.layers = 1;
18398 VkFramebuffer fb;
18399 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18400 ASSERT_VK_SUCCESS(result);
18401
18402 VkRenderPassBeginInfo rpbinfo = {};
18403 rpbinfo.clearValueCount = 1;
18404 rpbinfo.pClearValues = &clear;
18405 rpbinfo.pNext = NULL;
18406 rpbinfo.renderPass = rp;
18407 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18408 rpbinfo.renderArea.extent.width = 100;
18409 rpbinfo.renderArea.extent.height = 100;
18410 rpbinfo.renderArea.offset.x = 0;
18411 rpbinfo.renderArea.offset.y = 0;
18412 rpbinfo.framebuffer = fb;
18413
18414 VkFence fence = {};
18415 VkFenceCreateInfo fence_ci = {};
18416 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18417 fence_ci.pNext = nullptr;
18418 fence_ci.flags = 0;
18419 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18420 ASSERT_VK_SUCCESS(result);
18421
18422 m_commandBuffer->BeginCommandBuffer();
18423 m_commandBuffer->BeginRenderPass(rpbinfo);
18424 m_commandBuffer->EndRenderPass();
18425 m_commandBuffer->EndCommandBuffer();
18426 m_commandBuffer->QueueCommandBuffer(fence);
18427
18428 VkImageObj destImage(m_device);
18429 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 -070018430 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018431 VkImageMemoryBarrier barrier = {};
18432 VkImageSubresourceRange range;
18433 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18434 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18435 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18436 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18437 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18438 barrier.image = m_depthStencil->handle();
18439 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18440 range.baseMipLevel = 0;
18441 range.levelCount = 1;
18442 range.baseArrayLayer = 0;
18443 range.layerCount = 1;
18444 barrier.subresourceRange = range;
18445 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18446 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18447 cmdbuf.BeginCommandBuffer();
18448 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 -070018449 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018450 barrier.srcAccessMask = 0;
18451 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18452 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18453 barrier.image = destImage.handle();
18454 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18455 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 -070018456 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018457 VkImageCopy cregion;
18458 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18459 cregion.srcSubresource.mipLevel = 0;
18460 cregion.srcSubresource.baseArrayLayer = 0;
18461 cregion.srcSubresource.layerCount = 1;
18462 cregion.srcOffset.x = 0;
18463 cregion.srcOffset.y = 0;
18464 cregion.srcOffset.z = 0;
18465 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18466 cregion.dstSubresource.mipLevel = 0;
18467 cregion.dstSubresource.baseArrayLayer = 0;
18468 cregion.dstSubresource.layerCount = 1;
18469 cregion.dstOffset.x = 0;
18470 cregion.dstOffset.y = 0;
18471 cregion.dstOffset.z = 0;
18472 cregion.extent.width = 100;
18473 cregion.extent.height = 100;
18474 cregion.extent.depth = 1;
18475 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018476 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018477 cmdbuf.EndCommandBuffer();
18478
18479 VkSubmitInfo submit_info;
18480 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18481 submit_info.pNext = NULL;
18482 submit_info.waitSemaphoreCount = 0;
18483 submit_info.pWaitSemaphores = NULL;
18484 submit_info.pWaitDstStageMask = NULL;
18485 submit_info.commandBufferCount = 1;
18486 submit_info.pCommandBuffers = &cmdbuf.handle();
18487 submit_info.signalSemaphoreCount = 0;
18488 submit_info.pSignalSemaphores = NULL;
18489
18490 m_errorMonitor->ExpectSuccess();
18491 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18492 m_errorMonitor->VerifyNotFound();
18493
18494 vkQueueWaitIdle(m_device->m_queue);
18495 vkDestroyFence(m_device->device(), fence, nullptr);
18496 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18497 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18498}
18499
18500// This is a positive test. No errors should be generated.
18501TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18502 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18503
18504 m_errorMonitor->ExpectSuccess();
18505 ASSERT_NO_FATAL_FAILURE(InitState());
18506
18507 VkEvent event;
18508 VkEventCreateInfo event_create_info{};
18509 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18510 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18511
18512 VkCommandPool command_pool;
18513 VkCommandPoolCreateInfo pool_create_info{};
18514 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18515 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18516 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18517 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18518
18519 VkCommandBuffer command_buffer;
18520 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18521 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18522 command_buffer_allocate_info.commandPool = command_pool;
18523 command_buffer_allocate_info.commandBufferCount = 1;
18524 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18525 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18526
18527 VkQueue queue = VK_NULL_HANDLE;
18528 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18529
18530 {
18531 VkCommandBufferBeginInfo begin_info{};
18532 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18533 vkBeginCommandBuffer(command_buffer, &begin_info);
18534
18535 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 -070018536 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018537 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18538 vkEndCommandBuffer(command_buffer);
18539 }
18540 {
18541 VkSubmitInfo submit_info{};
18542 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18543 submit_info.commandBufferCount = 1;
18544 submit_info.pCommandBuffers = &command_buffer;
18545 submit_info.signalSemaphoreCount = 0;
18546 submit_info.pSignalSemaphores = nullptr;
18547 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18548 }
18549 { vkSetEvent(m_device->device(), event); }
18550
18551 vkQueueWaitIdle(queue);
18552
18553 vkDestroyEvent(m_device->device(), event, nullptr);
18554 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18555 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18556
18557 m_errorMonitor->VerifyNotFound();
18558}
18559// This is a positive test. No errors should be generated.
18560TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18561 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18562
18563 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018564 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018565
18566 m_errorMonitor->ExpectSuccess();
18567
18568 VkQueryPool query_pool;
18569 VkQueryPoolCreateInfo query_pool_create_info{};
18570 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18571 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18572 query_pool_create_info.queryCount = 1;
18573 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18574
18575 VkCommandPool command_pool;
18576 VkCommandPoolCreateInfo pool_create_info{};
18577 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18578 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18579 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18580 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18581
18582 VkCommandBuffer command_buffer;
18583 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18584 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18585 command_buffer_allocate_info.commandPool = command_pool;
18586 command_buffer_allocate_info.commandBufferCount = 1;
18587 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18588 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18589
18590 VkCommandBuffer secondary_command_buffer;
18591 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18592 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18593
18594 VkQueue queue = VK_NULL_HANDLE;
18595 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18596
18597 uint32_t qfi = 0;
18598 VkBufferCreateInfo buff_create_info = {};
18599 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18600 buff_create_info.size = 1024;
18601 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18602 buff_create_info.queueFamilyIndexCount = 1;
18603 buff_create_info.pQueueFamilyIndices = &qfi;
18604
18605 VkResult err;
18606 VkBuffer buffer;
18607 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18608 ASSERT_VK_SUCCESS(err);
18609 VkMemoryAllocateInfo mem_alloc = {};
18610 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18611 mem_alloc.pNext = NULL;
18612 mem_alloc.allocationSize = 1024;
18613 mem_alloc.memoryTypeIndex = 0;
18614
18615 VkMemoryRequirements memReqs;
18616 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18617 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18618 if (!pass) {
18619 vkDestroyBuffer(m_device->device(), buffer, NULL);
18620 return;
18621 }
18622
18623 VkDeviceMemory mem;
18624 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18625 ASSERT_VK_SUCCESS(err);
18626 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18627 ASSERT_VK_SUCCESS(err);
18628
18629 VkCommandBufferInheritanceInfo hinfo = {};
18630 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18631 hinfo.renderPass = VK_NULL_HANDLE;
18632 hinfo.subpass = 0;
18633 hinfo.framebuffer = VK_NULL_HANDLE;
18634 hinfo.occlusionQueryEnable = VK_FALSE;
18635 hinfo.queryFlags = 0;
18636 hinfo.pipelineStatistics = 0;
18637
18638 {
18639 VkCommandBufferBeginInfo begin_info{};
18640 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18641 begin_info.pInheritanceInfo = &hinfo;
18642 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18643
18644 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18645 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18646
18647 vkEndCommandBuffer(secondary_command_buffer);
18648
18649 begin_info.pInheritanceInfo = nullptr;
18650 vkBeginCommandBuffer(command_buffer, &begin_info);
18651
18652 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18653 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18654
18655 vkEndCommandBuffer(command_buffer);
18656 }
18657 {
18658 VkSubmitInfo submit_info{};
18659 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18660 submit_info.commandBufferCount = 1;
18661 submit_info.pCommandBuffers = &command_buffer;
18662 submit_info.signalSemaphoreCount = 0;
18663 submit_info.pSignalSemaphores = nullptr;
18664 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18665 }
18666
18667 vkQueueWaitIdle(queue);
18668
18669 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18670 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18671 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18672 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18673 vkDestroyBuffer(m_device->device(), buffer, NULL);
18674 vkFreeMemory(m_device->device(), mem, NULL);
18675
18676 m_errorMonitor->VerifyNotFound();
18677}
18678
18679// This is a positive test. No errors should be generated.
18680TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18681 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18682
18683 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018684 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018685
18686 m_errorMonitor->ExpectSuccess();
18687
18688 VkQueryPool query_pool;
18689 VkQueryPoolCreateInfo query_pool_create_info{};
18690 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18691 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18692 query_pool_create_info.queryCount = 1;
18693 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18694
18695 VkCommandPool command_pool;
18696 VkCommandPoolCreateInfo pool_create_info{};
18697 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18698 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18699 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18700 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18701
18702 VkCommandBuffer command_buffer[2];
18703 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18704 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18705 command_buffer_allocate_info.commandPool = command_pool;
18706 command_buffer_allocate_info.commandBufferCount = 2;
18707 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18708 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18709
18710 VkQueue queue = VK_NULL_HANDLE;
18711 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18712
18713 uint32_t qfi = 0;
18714 VkBufferCreateInfo buff_create_info = {};
18715 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18716 buff_create_info.size = 1024;
18717 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18718 buff_create_info.queueFamilyIndexCount = 1;
18719 buff_create_info.pQueueFamilyIndices = &qfi;
18720
18721 VkResult err;
18722 VkBuffer buffer;
18723 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18724 ASSERT_VK_SUCCESS(err);
18725 VkMemoryAllocateInfo mem_alloc = {};
18726 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18727 mem_alloc.pNext = NULL;
18728 mem_alloc.allocationSize = 1024;
18729 mem_alloc.memoryTypeIndex = 0;
18730
18731 VkMemoryRequirements memReqs;
18732 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18733 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18734 if (!pass) {
18735 vkDestroyBuffer(m_device->device(), buffer, NULL);
18736 return;
18737 }
18738
18739 VkDeviceMemory mem;
18740 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18741 ASSERT_VK_SUCCESS(err);
18742 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18743 ASSERT_VK_SUCCESS(err);
18744
18745 {
18746 VkCommandBufferBeginInfo begin_info{};
18747 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18748 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18749
18750 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18751 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18752
18753 vkEndCommandBuffer(command_buffer[0]);
18754
18755 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18756
18757 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18758
18759 vkEndCommandBuffer(command_buffer[1]);
18760 }
18761 {
18762 VkSubmitInfo submit_info{};
18763 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18764 submit_info.commandBufferCount = 2;
18765 submit_info.pCommandBuffers = command_buffer;
18766 submit_info.signalSemaphoreCount = 0;
18767 submit_info.pSignalSemaphores = nullptr;
18768 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18769 }
18770
18771 vkQueueWaitIdle(queue);
18772
18773 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18774 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18775 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18776 vkDestroyBuffer(m_device->device(), buffer, NULL);
18777 vkFreeMemory(m_device->device(), mem, NULL);
18778
18779 m_errorMonitor->VerifyNotFound();
18780}
18781
Tony Barbourc46924f2016-11-04 11:49:52 -060018782TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018783 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18784
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018785 ASSERT_NO_FATAL_FAILURE(InitState());
18786 VkEvent event;
18787 VkEventCreateInfo event_create_info{};
18788 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18789 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18790
18791 VkCommandPool command_pool;
18792 VkCommandPoolCreateInfo pool_create_info{};
18793 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18794 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18795 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18796 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18797
18798 VkCommandBuffer command_buffer;
18799 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18800 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18801 command_buffer_allocate_info.commandPool = command_pool;
18802 command_buffer_allocate_info.commandBufferCount = 1;
18803 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18804 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18805
18806 VkQueue queue = VK_NULL_HANDLE;
18807 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18808
18809 {
18810 VkCommandBufferBeginInfo begin_info{};
18811 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18812 vkBeginCommandBuffer(command_buffer, &begin_info);
18813
18814 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018815 vkEndCommandBuffer(command_buffer);
18816 }
18817 {
18818 VkSubmitInfo submit_info{};
18819 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18820 submit_info.commandBufferCount = 1;
18821 submit_info.pCommandBuffers = &command_buffer;
18822 submit_info.signalSemaphoreCount = 0;
18823 submit_info.pSignalSemaphores = nullptr;
18824 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18825 }
18826 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18828 "that is already in use by a "
18829 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018830 vkSetEvent(m_device->device(), event);
18831 m_errorMonitor->VerifyFound();
18832 }
18833
18834 vkQueueWaitIdle(queue);
18835
18836 vkDestroyEvent(m_device->device(), event, nullptr);
18837 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18838 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18839}
18840
18841// This is a positive test. No errors should be generated.
18842TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018843 TEST_DESCRIPTION(
18844 "Two command buffers with two separate fences are each "
18845 "run through a Submit & WaitForFences cycle 3 times. This "
18846 "previously revealed a bug so running this positive test "
18847 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018848 m_errorMonitor->ExpectSuccess();
18849
18850 ASSERT_NO_FATAL_FAILURE(InitState());
18851 VkQueue queue = VK_NULL_HANDLE;
18852 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18853
18854 static const uint32_t NUM_OBJECTS = 2;
18855 static const uint32_t NUM_FRAMES = 3;
18856 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18857 VkFence fences[NUM_OBJECTS] = {};
18858
18859 VkCommandPool cmd_pool;
18860 VkCommandPoolCreateInfo cmd_pool_ci = {};
18861 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18862 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18863 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18864 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18865 ASSERT_VK_SUCCESS(err);
18866
18867 VkCommandBufferAllocateInfo cmd_buf_info = {};
18868 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18869 cmd_buf_info.commandPool = cmd_pool;
18870 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18871 cmd_buf_info.commandBufferCount = 1;
18872
18873 VkFenceCreateInfo fence_ci = {};
18874 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18875 fence_ci.pNext = nullptr;
18876 fence_ci.flags = 0;
18877
18878 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18879 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18880 ASSERT_VK_SUCCESS(err);
18881 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18882 ASSERT_VK_SUCCESS(err);
18883 }
18884
18885 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18886 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18887 // Create empty cmd buffer
18888 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18889 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18890
18891 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18892 ASSERT_VK_SUCCESS(err);
18893 err = vkEndCommandBuffer(cmd_buffers[obj]);
18894 ASSERT_VK_SUCCESS(err);
18895
18896 VkSubmitInfo submit_info = {};
18897 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18898 submit_info.commandBufferCount = 1;
18899 submit_info.pCommandBuffers = &cmd_buffers[obj];
18900 // Submit cmd buffer and wait for fence
18901 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18902 ASSERT_VK_SUCCESS(err);
18903 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18904 ASSERT_VK_SUCCESS(err);
18905 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18906 ASSERT_VK_SUCCESS(err);
18907 }
18908 }
18909 m_errorMonitor->VerifyNotFound();
18910 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18911 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18912 vkDestroyFence(m_device->device(), fences[i], nullptr);
18913 }
18914}
18915// This is a positive test. No errors should be generated.
18916TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018917 TEST_DESCRIPTION(
18918 "Two command buffers, each in a separate QueueSubmit call "
18919 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018920
18921 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018922 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018923
18924 m_errorMonitor->ExpectSuccess();
18925
18926 VkSemaphore semaphore;
18927 VkSemaphoreCreateInfo semaphore_create_info{};
18928 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18929 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18930
18931 VkCommandPool command_pool;
18932 VkCommandPoolCreateInfo pool_create_info{};
18933 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18934 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18935 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18936 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18937
18938 VkCommandBuffer command_buffer[2];
18939 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18940 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18941 command_buffer_allocate_info.commandPool = command_pool;
18942 command_buffer_allocate_info.commandBufferCount = 2;
18943 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18944 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18945
18946 VkQueue queue = VK_NULL_HANDLE;
18947 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18948
18949 {
18950 VkCommandBufferBeginInfo begin_info{};
18951 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18952 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18953
18954 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 -070018955 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018956
18957 VkViewport viewport{};
18958 viewport.maxDepth = 1.0f;
18959 viewport.minDepth = 0.0f;
18960 viewport.width = 512;
18961 viewport.height = 512;
18962 viewport.x = 0;
18963 viewport.y = 0;
18964 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18965 vkEndCommandBuffer(command_buffer[0]);
18966 }
18967 {
18968 VkCommandBufferBeginInfo begin_info{};
18969 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18970 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18971
18972 VkViewport viewport{};
18973 viewport.maxDepth = 1.0f;
18974 viewport.minDepth = 0.0f;
18975 viewport.width = 512;
18976 viewport.height = 512;
18977 viewport.x = 0;
18978 viewport.y = 0;
18979 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18980 vkEndCommandBuffer(command_buffer[1]);
18981 }
18982 {
18983 VkSubmitInfo submit_info{};
18984 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18985 submit_info.commandBufferCount = 1;
18986 submit_info.pCommandBuffers = &command_buffer[0];
18987 submit_info.signalSemaphoreCount = 1;
18988 submit_info.pSignalSemaphores = &semaphore;
18989 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18990 }
18991 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018992 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018993 VkSubmitInfo submit_info{};
18994 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18995 submit_info.commandBufferCount = 1;
18996 submit_info.pCommandBuffers = &command_buffer[1];
18997 submit_info.waitSemaphoreCount = 1;
18998 submit_info.pWaitSemaphores = &semaphore;
18999 submit_info.pWaitDstStageMask = flags;
19000 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19001 }
19002
19003 vkQueueWaitIdle(m_device->m_queue);
19004
19005 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19006 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19007 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19008
19009 m_errorMonitor->VerifyNotFound();
19010}
19011
19012// This is a positive test. No errors should be generated.
19013TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019014 TEST_DESCRIPTION(
19015 "Two command buffers, each in a separate QueueSubmit call "
19016 "submitted on separate queues, the second having a fence"
19017 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019018
19019 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019020 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019021
19022 m_errorMonitor->ExpectSuccess();
19023
19024 VkFence fence;
19025 VkFenceCreateInfo fence_create_info{};
19026 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19027 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19028
19029 VkSemaphore semaphore;
19030 VkSemaphoreCreateInfo semaphore_create_info{};
19031 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19032 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19033
19034 VkCommandPool command_pool;
19035 VkCommandPoolCreateInfo pool_create_info{};
19036 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19037 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19038 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19039 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19040
19041 VkCommandBuffer command_buffer[2];
19042 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19043 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19044 command_buffer_allocate_info.commandPool = command_pool;
19045 command_buffer_allocate_info.commandBufferCount = 2;
19046 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19047 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19048
19049 VkQueue queue = VK_NULL_HANDLE;
19050 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19051
19052 {
19053 VkCommandBufferBeginInfo begin_info{};
19054 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19055 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19056
19057 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 -070019058 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019059
19060 VkViewport viewport{};
19061 viewport.maxDepth = 1.0f;
19062 viewport.minDepth = 0.0f;
19063 viewport.width = 512;
19064 viewport.height = 512;
19065 viewport.x = 0;
19066 viewport.y = 0;
19067 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19068 vkEndCommandBuffer(command_buffer[0]);
19069 }
19070 {
19071 VkCommandBufferBeginInfo begin_info{};
19072 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19073 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19074
19075 VkViewport viewport{};
19076 viewport.maxDepth = 1.0f;
19077 viewport.minDepth = 0.0f;
19078 viewport.width = 512;
19079 viewport.height = 512;
19080 viewport.x = 0;
19081 viewport.y = 0;
19082 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19083 vkEndCommandBuffer(command_buffer[1]);
19084 }
19085 {
19086 VkSubmitInfo submit_info{};
19087 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19088 submit_info.commandBufferCount = 1;
19089 submit_info.pCommandBuffers = &command_buffer[0];
19090 submit_info.signalSemaphoreCount = 1;
19091 submit_info.pSignalSemaphores = &semaphore;
19092 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19093 }
19094 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019095 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019096 VkSubmitInfo submit_info{};
19097 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19098 submit_info.commandBufferCount = 1;
19099 submit_info.pCommandBuffers = &command_buffer[1];
19100 submit_info.waitSemaphoreCount = 1;
19101 submit_info.pWaitSemaphores = &semaphore;
19102 submit_info.pWaitDstStageMask = flags;
19103 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19104 }
19105
19106 vkQueueWaitIdle(m_device->m_queue);
19107
19108 vkDestroyFence(m_device->device(), fence, nullptr);
19109 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19110 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19111 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19112
19113 m_errorMonitor->VerifyNotFound();
19114}
19115
19116// This is a positive test. No errors should be generated.
19117TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019118 TEST_DESCRIPTION(
19119 "Two command buffers, each in a separate QueueSubmit call "
19120 "submitted on separate queues, the second having a fence"
19121 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019122
19123 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019124 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019125
19126 m_errorMonitor->ExpectSuccess();
19127
19128 VkFence fence;
19129 VkFenceCreateInfo fence_create_info{};
19130 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19131 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19132
19133 VkSemaphore semaphore;
19134 VkSemaphoreCreateInfo semaphore_create_info{};
19135 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19136 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19137
19138 VkCommandPool command_pool;
19139 VkCommandPoolCreateInfo pool_create_info{};
19140 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19141 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19142 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19143 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19144
19145 VkCommandBuffer command_buffer[2];
19146 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19147 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19148 command_buffer_allocate_info.commandPool = command_pool;
19149 command_buffer_allocate_info.commandBufferCount = 2;
19150 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19151 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19152
19153 VkQueue queue = VK_NULL_HANDLE;
19154 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19155
19156 {
19157 VkCommandBufferBeginInfo begin_info{};
19158 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19159 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19160
19161 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 -070019162 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019163
19164 VkViewport viewport{};
19165 viewport.maxDepth = 1.0f;
19166 viewport.minDepth = 0.0f;
19167 viewport.width = 512;
19168 viewport.height = 512;
19169 viewport.x = 0;
19170 viewport.y = 0;
19171 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19172 vkEndCommandBuffer(command_buffer[0]);
19173 }
19174 {
19175 VkCommandBufferBeginInfo begin_info{};
19176 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19177 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19178
19179 VkViewport viewport{};
19180 viewport.maxDepth = 1.0f;
19181 viewport.minDepth = 0.0f;
19182 viewport.width = 512;
19183 viewport.height = 512;
19184 viewport.x = 0;
19185 viewport.y = 0;
19186 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19187 vkEndCommandBuffer(command_buffer[1]);
19188 }
19189 {
19190 VkSubmitInfo submit_info{};
19191 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19192 submit_info.commandBufferCount = 1;
19193 submit_info.pCommandBuffers = &command_buffer[0];
19194 submit_info.signalSemaphoreCount = 1;
19195 submit_info.pSignalSemaphores = &semaphore;
19196 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19197 }
19198 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019199 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019200 VkSubmitInfo submit_info{};
19201 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19202 submit_info.commandBufferCount = 1;
19203 submit_info.pCommandBuffers = &command_buffer[1];
19204 submit_info.waitSemaphoreCount = 1;
19205 submit_info.pWaitSemaphores = &semaphore;
19206 submit_info.pWaitDstStageMask = flags;
19207 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19208 }
19209
19210 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19211 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19212
19213 vkDestroyFence(m_device->device(), fence, nullptr);
19214 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19215 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19216 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19217
19218 m_errorMonitor->VerifyNotFound();
19219}
19220
19221TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019222 ASSERT_NO_FATAL_FAILURE(InitState());
19223 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
19224 printf("Test requires two queues, skipping\n");
19225 return;
19226 }
19227
19228 VkResult err;
19229
19230 m_errorMonitor->ExpectSuccess();
19231
19232 VkQueue q0 = m_device->m_queue;
19233 VkQueue q1 = nullptr;
19234 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
19235 ASSERT_NE(q1, nullptr);
19236
19237 // An (empty) command buffer. We must have work in the first submission --
19238 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019239 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019240 VkCommandPool pool;
19241 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
19242 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019243 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
19244 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019245 VkCommandBuffer cb;
19246 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
19247 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019248 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019249 err = vkBeginCommandBuffer(cb, &cbbi);
19250 ASSERT_VK_SUCCESS(err);
19251 err = vkEndCommandBuffer(cb);
19252 ASSERT_VK_SUCCESS(err);
19253
19254 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019255 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019256 VkSemaphore s;
19257 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
19258 ASSERT_VK_SUCCESS(err);
19259
19260 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019261 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019262
19263 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
19264 ASSERT_VK_SUCCESS(err);
19265
19266 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019267 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019268 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019269
19270 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
19271 ASSERT_VK_SUCCESS(err);
19272
19273 // Wait for q0 idle
19274 err = vkQueueWaitIdle(q0);
19275 ASSERT_VK_SUCCESS(err);
19276
19277 // Command buffer should have been completed (it was on q0); reset the pool.
19278 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
19279
19280 m_errorMonitor->VerifyNotFound();
19281
19282 // Force device completely idle and clean up resources
19283 vkDeviceWaitIdle(m_device->device());
19284 vkDestroyCommandPool(m_device->device(), pool, nullptr);
19285 vkDestroySemaphore(m_device->device(), s, nullptr);
19286}
19287
19288// This is a positive test. No errors should be generated.
19289TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019290 TEST_DESCRIPTION(
19291 "Two command buffers, each in a separate QueueSubmit call "
19292 "submitted on separate queues, the second having a fence, "
19293 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019294
19295 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019296 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019297
19298 m_errorMonitor->ExpectSuccess();
19299
19300 ASSERT_NO_FATAL_FAILURE(InitState());
19301 VkFence fence;
19302 VkFenceCreateInfo fence_create_info{};
19303 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19304 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19305
19306 VkSemaphore semaphore;
19307 VkSemaphoreCreateInfo semaphore_create_info{};
19308 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19309 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19310
19311 VkCommandPool command_pool;
19312 VkCommandPoolCreateInfo pool_create_info{};
19313 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19314 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19315 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19316 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19317
19318 VkCommandBuffer command_buffer[2];
19319 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19320 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19321 command_buffer_allocate_info.commandPool = command_pool;
19322 command_buffer_allocate_info.commandBufferCount = 2;
19323 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19324 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19325
19326 VkQueue queue = VK_NULL_HANDLE;
19327 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19328
19329 {
19330 VkCommandBufferBeginInfo begin_info{};
19331 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19332 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19333
19334 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 -070019335 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019336
19337 VkViewport viewport{};
19338 viewport.maxDepth = 1.0f;
19339 viewport.minDepth = 0.0f;
19340 viewport.width = 512;
19341 viewport.height = 512;
19342 viewport.x = 0;
19343 viewport.y = 0;
19344 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19345 vkEndCommandBuffer(command_buffer[0]);
19346 }
19347 {
19348 VkCommandBufferBeginInfo begin_info{};
19349 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19350 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19351
19352 VkViewport viewport{};
19353 viewport.maxDepth = 1.0f;
19354 viewport.minDepth = 0.0f;
19355 viewport.width = 512;
19356 viewport.height = 512;
19357 viewport.x = 0;
19358 viewport.y = 0;
19359 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19360 vkEndCommandBuffer(command_buffer[1]);
19361 }
19362 {
19363 VkSubmitInfo submit_info{};
19364 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19365 submit_info.commandBufferCount = 1;
19366 submit_info.pCommandBuffers = &command_buffer[0];
19367 submit_info.signalSemaphoreCount = 1;
19368 submit_info.pSignalSemaphores = &semaphore;
19369 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19370 }
19371 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019372 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019373 VkSubmitInfo submit_info{};
19374 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19375 submit_info.commandBufferCount = 1;
19376 submit_info.pCommandBuffers = &command_buffer[1];
19377 submit_info.waitSemaphoreCount = 1;
19378 submit_info.pWaitSemaphores = &semaphore;
19379 submit_info.pWaitDstStageMask = flags;
19380 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19381 }
19382
19383 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19384
19385 vkDestroyFence(m_device->device(), fence, nullptr);
19386 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19387 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19388 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19389
19390 m_errorMonitor->VerifyNotFound();
19391}
19392
19393// This is a positive test. No errors should be generated.
19394TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019395 TEST_DESCRIPTION(
19396 "Two command buffers, each in a separate QueueSubmit call "
19397 "on the same queue, sharing a signal/wait semaphore, the "
19398 "second having a fence, "
19399 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019400
19401 m_errorMonitor->ExpectSuccess();
19402
19403 ASSERT_NO_FATAL_FAILURE(InitState());
19404 VkFence fence;
19405 VkFenceCreateInfo fence_create_info{};
19406 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19407 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19408
19409 VkSemaphore semaphore;
19410 VkSemaphoreCreateInfo semaphore_create_info{};
19411 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19412 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19413
19414 VkCommandPool command_pool;
19415 VkCommandPoolCreateInfo pool_create_info{};
19416 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19417 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19418 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19419 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19420
19421 VkCommandBuffer command_buffer[2];
19422 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19423 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19424 command_buffer_allocate_info.commandPool = command_pool;
19425 command_buffer_allocate_info.commandBufferCount = 2;
19426 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19427 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19428
19429 {
19430 VkCommandBufferBeginInfo begin_info{};
19431 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19432 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19433
19434 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 -070019435 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019436
19437 VkViewport viewport{};
19438 viewport.maxDepth = 1.0f;
19439 viewport.minDepth = 0.0f;
19440 viewport.width = 512;
19441 viewport.height = 512;
19442 viewport.x = 0;
19443 viewport.y = 0;
19444 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19445 vkEndCommandBuffer(command_buffer[0]);
19446 }
19447 {
19448 VkCommandBufferBeginInfo begin_info{};
19449 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19450 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19451
19452 VkViewport viewport{};
19453 viewport.maxDepth = 1.0f;
19454 viewport.minDepth = 0.0f;
19455 viewport.width = 512;
19456 viewport.height = 512;
19457 viewport.x = 0;
19458 viewport.y = 0;
19459 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19460 vkEndCommandBuffer(command_buffer[1]);
19461 }
19462 {
19463 VkSubmitInfo submit_info{};
19464 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19465 submit_info.commandBufferCount = 1;
19466 submit_info.pCommandBuffers = &command_buffer[0];
19467 submit_info.signalSemaphoreCount = 1;
19468 submit_info.pSignalSemaphores = &semaphore;
19469 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19470 }
19471 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019472 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019473 VkSubmitInfo submit_info{};
19474 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19475 submit_info.commandBufferCount = 1;
19476 submit_info.pCommandBuffers = &command_buffer[1];
19477 submit_info.waitSemaphoreCount = 1;
19478 submit_info.pWaitSemaphores = &semaphore;
19479 submit_info.pWaitDstStageMask = flags;
19480 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19481 }
19482
19483 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19484
19485 vkDestroyFence(m_device->device(), fence, nullptr);
19486 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19487 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19488 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19489
19490 m_errorMonitor->VerifyNotFound();
19491}
19492
19493// This is a positive test. No errors should be generated.
19494TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019495 TEST_DESCRIPTION(
19496 "Two command buffers, each in a separate QueueSubmit call "
19497 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19498 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019499
19500 m_errorMonitor->ExpectSuccess();
19501
19502 ASSERT_NO_FATAL_FAILURE(InitState());
19503 VkFence fence;
19504 VkFenceCreateInfo fence_create_info{};
19505 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19506 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19507
19508 VkCommandPool command_pool;
19509 VkCommandPoolCreateInfo pool_create_info{};
19510 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19511 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19512 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19513 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19514
19515 VkCommandBuffer command_buffer[2];
19516 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19517 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19518 command_buffer_allocate_info.commandPool = command_pool;
19519 command_buffer_allocate_info.commandBufferCount = 2;
19520 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19521 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19522
19523 {
19524 VkCommandBufferBeginInfo begin_info{};
19525 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19526 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19527
19528 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 -070019529 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019530
19531 VkViewport viewport{};
19532 viewport.maxDepth = 1.0f;
19533 viewport.minDepth = 0.0f;
19534 viewport.width = 512;
19535 viewport.height = 512;
19536 viewport.x = 0;
19537 viewport.y = 0;
19538 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19539 vkEndCommandBuffer(command_buffer[0]);
19540 }
19541 {
19542 VkCommandBufferBeginInfo begin_info{};
19543 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19544 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19545
19546 VkViewport viewport{};
19547 viewport.maxDepth = 1.0f;
19548 viewport.minDepth = 0.0f;
19549 viewport.width = 512;
19550 viewport.height = 512;
19551 viewport.x = 0;
19552 viewport.y = 0;
19553 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19554 vkEndCommandBuffer(command_buffer[1]);
19555 }
19556 {
19557 VkSubmitInfo submit_info{};
19558 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19559 submit_info.commandBufferCount = 1;
19560 submit_info.pCommandBuffers = &command_buffer[0];
19561 submit_info.signalSemaphoreCount = 0;
19562 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19563 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19564 }
19565 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019566 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019567 VkSubmitInfo submit_info{};
19568 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19569 submit_info.commandBufferCount = 1;
19570 submit_info.pCommandBuffers = &command_buffer[1];
19571 submit_info.waitSemaphoreCount = 0;
19572 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19573 submit_info.pWaitDstStageMask = flags;
19574 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19575 }
19576
19577 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19578
19579 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19580 ASSERT_VK_SUCCESS(err);
19581
19582 vkDestroyFence(m_device->device(), fence, nullptr);
19583 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19584 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19585
19586 m_errorMonitor->VerifyNotFound();
19587}
19588
19589// This is a positive test. No errors should be generated.
19590TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019591 TEST_DESCRIPTION(
19592 "Two command buffers, each in a separate QueueSubmit call "
19593 "on the same queue, the second having a fence, followed "
19594 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019595
19596 m_errorMonitor->ExpectSuccess();
19597
19598 ASSERT_NO_FATAL_FAILURE(InitState());
19599 VkFence fence;
19600 VkFenceCreateInfo fence_create_info{};
19601 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19602 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19603
19604 VkCommandPool command_pool;
19605 VkCommandPoolCreateInfo pool_create_info{};
19606 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19607 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19608 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19609 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19610
19611 VkCommandBuffer command_buffer[2];
19612 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19613 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19614 command_buffer_allocate_info.commandPool = command_pool;
19615 command_buffer_allocate_info.commandBufferCount = 2;
19616 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19617 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19618
19619 {
19620 VkCommandBufferBeginInfo begin_info{};
19621 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19622 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19623
19624 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 -070019625 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019626
19627 VkViewport viewport{};
19628 viewport.maxDepth = 1.0f;
19629 viewport.minDepth = 0.0f;
19630 viewport.width = 512;
19631 viewport.height = 512;
19632 viewport.x = 0;
19633 viewport.y = 0;
19634 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19635 vkEndCommandBuffer(command_buffer[0]);
19636 }
19637 {
19638 VkCommandBufferBeginInfo begin_info{};
19639 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19640 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19641
19642 VkViewport viewport{};
19643 viewport.maxDepth = 1.0f;
19644 viewport.minDepth = 0.0f;
19645 viewport.width = 512;
19646 viewport.height = 512;
19647 viewport.x = 0;
19648 viewport.y = 0;
19649 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19650 vkEndCommandBuffer(command_buffer[1]);
19651 }
19652 {
19653 VkSubmitInfo submit_info{};
19654 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19655 submit_info.commandBufferCount = 1;
19656 submit_info.pCommandBuffers = &command_buffer[0];
19657 submit_info.signalSemaphoreCount = 0;
19658 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19659 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19660 }
19661 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019662 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019663 VkSubmitInfo submit_info{};
19664 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19665 submit_info.commandBufferCount = 1;
19666 submit_info.pCommandBuffers = &command_buffer[1];
19667 submit_info.waitSemaphoreCount = 0;
19668 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19669 submit_info.pWaitDstStageMask = flags;
19670 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19671 }
19672
19673 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19674
19675 vkDestroyFence(m_device->device(), fence, nullptr);
19676 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19677 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19678
19679 m_errorMonitor->VerifyNotFound();
19680}
19681
19682// This is a positive test. No errors should be generated.
19683TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019684 TEST_DESCRIPTION(
19685 "Two command buffers each in a separate SubmitInfo sent in a single "
19686 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019687 ASSERT_NO_FATAL_FAILURE(InitState());
19688
19689 m_errorMonitor->ExpectSuccess();
19690
19691 VkFence fence;
19692 VkFenceCreateInfo fence_create_info{};
19693 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19694 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19695
19696 VkSemaphore semaphore;
19697 VkSemaphoreCreateInfo semaphore_create_info{};
19698 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19699 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19700
19701 VkCommandPool command_pool;
19702 VkCommandPoolCreateInfo pool_create_info{};
19703 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19704 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19705 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19706 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19707
19708 VkCommandBuffer command_buffer[2];
19709 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19710 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19711 command_buffer_allocate_info.commandPool = command_pool;
19712 command_buffer_allocate_info.commandBufferCount = 2;
19713 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19714 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19715
19716 {
19717 VkCommandBufferBeginInfo begin_info{};
19718 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19719 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19720
19721 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 -070019722 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019723
19724 VkViewport viewport{};
19725 viewport.maxDepth = 1.0f;
19726 viewport.minDepth = 0.0f;
19727 viewport.width = 512;
19728 viewport.height = 512;
19729 viewport.x = 0;
19730 viewport.y = 0;
19731 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19732 vkEndCommandBuffer(command_buffer[0]);
19733 }
19734 {
19735 VkCommandBufferBeginInfo begin_info{};
19736 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19737 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19738
19739 VkViewport viewport{};
19740 viewport.maxDepth = 1.0f;
19741 viewport.minDepth = 0.0f;
19742 viewport.width = 512;
19743 viewport.height = 512;
19744 viewport.x = 0;
19745 viewport.y = 0;
19746 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19747 vkEndCommandBuffer(command_buffer[1]);
19748 }
19749 {
19750 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019751 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019752
19753 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19754 submit_info[0].pNext = NULL;
19755 submit_info[0].commandBufferCount = 1;
19756 submit_info[0].pCommandBuffers = &command_buffer[0];
19757 submit_info[0].signalSemaphoreCount = 1;
19758 submit_info[0].pSignalSemaphores = &semaphore;
19759 submit_info[0].waitSemaphoreCount = 0;
19760 submit_info[0].pWaitSemaphores = NULL;
19761 submit_info[0].pWaitDstStageMask = 0;
19762
19763 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19764 submit_info[1].pNext = NULL;
19765 submit_info[1].commandBufferCount = 1;
19766 submit_info[1].pCommandBuffers = &command_buffer[1];
19767 submit_info[1].waitSemaphoreCount = 1;
19768 submit_info[1].pWaitSemaphores = &semaphore;
19769 submit_info[1].pWaitDstStageMask = flags;
19770 submit_info[1].signalSemaphoreCount = 0;
19771 submit_info[1].pSignalSemaphores = NULL;
19772 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19773 }
19774
19775 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19776
19777 vkDestroyFence(m_device->device(), fence, nullptr);
19778 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19779 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19780 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19781
19782 m_errorMonitor->VerifyNotFound();
19783}
19784
19785TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19786 m_errorMonitor->ExpectSuccess();
19787
19788 ASSERT_NO_FATAL_FAILURE(InitState());
19789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19790
Tony Barbour552f6c02016-12-21 14:34:07 -070019791 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019792
19793 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19794 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19795 m_errorMonitor->VerifyNotFound();
19796 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19797 m_errorMonitor->VerifyNotFound();
19798 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19799 m_errorMonitor->VerifyNotFound();
19800
19801 m_commandBuffer->EndCommandBuffer();
19802 m_errorMonitor->VerifyNotFound();
19803}
19804
19805TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019806 TEST_DESCRIPTION(
19807 "Positive test where we create a renderpass with an "
19808 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19809 "has a valid layout, and a second subpass then uses a "
19810 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019811 m_errorMonitor->ExpectSuccess();
19812 ASSERT_NO_FATAL_FAILURE(InitState());
19813
19814 VkAttachmentReference attach[2] = {};
19815 attach[0].attachment = 0;
19816 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19817 attach[1].attachment = 0;
19818 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19819 VkSubpassDescription subpasses[2] = {};
19820 // First subpass clears DS attach on load
19821 subpasses[0].pDepthStencilAttachment = &attach[0];
19822 // 2nd subpass reads in DS as input attachment
19823 subpasses[1].inputAttachmentCount = 1;
19824 subpasses[1].pInputAttachments = &attach[1];
19825 VkAttachmentDescription attach_desc = {};
19826 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19827 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19828 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19829 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19830 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19831 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19832 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19833 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19834 VkRenderPassCreateInfo rpci = {};
19835 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19836 rpci.attachmentCount = 1;
19837 rpci.pAttachments = &attach_desc;
19838 rpci.subpassCount = 2;
19839 rpci.pSubpasses = subpasses;
19840
19841 // Now create RenderPass and verify no errors
19842 VkRenderPass rp;
19843 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19844 m_errorMonitor->VerifyNotFound();
19845
19846 vkDestroyRenderPass(m_device->device(), rp, NULL);
19847}
19848
19849TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019850 TEST_DESCRIPTION(
19851 "Test that pipeline validation accepts matrices passed "
19852 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019853 m_errorMonitor->ExpectSuccess();
19854
19855 ASSERT_NO_FATAL_FAILURE(InitState());
19856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19857
19858 VkVertexInputBindingDescription input_binding;
19859 memset(&input_binding, 0, sizeof(input_binding));
19860
19861 VkVertexInputAttributeDescription input_attribs[2];
19862 memset(input_attribs, 0, sizeof(input_attribs));
19863
19864 for (int i = 0; i < 2; i++) {
19865 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19866 input_attribs[i].location = i;
19867 }
19868
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019869 char const *vsSource =
19870 "#version 450\n"
19871 "\n"
19872 "layout(location=0) in mat2x4 x;\n"
19873 "out gl_PerVertex {\n"
19874 " vec4 gl_Position;\n"
19875 "};\n"
19876 "void main(){\n"
19877 " gl_Position = x[0] + x[1];\n"
19878 "}\n";
19879 char const *fsSource =
19880 "#version 450\n"
19881 "\n"
19882 "layout(location=0) out vec4 color;\n"
19883 "void main(){\n"
19884 " color = vec4(1);\n"
19885 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019886
19887 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19888 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19889
19890 VkPipelineObj pipe(m_device);
19891 pipe.AddColorAttachment();
19892 pipe.AddShader(&vs);
19893 pipe.AddShader(&fs);
19894
19895 pipe.AddVertexInputBindings(&input_binding, 1);
19896 pipe.AddVertexInputAttribs(input_attribs, 2);
19897
19898 VkDescriptorSetObj descriptorSet(m_device);
19899 descriptorSet.AppendDummy();
19900 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19901
19902 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19903
19904 /* expect success */
19905 m_errorMonitor->VerifyNotFound();
19906}
19907
19908TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19909 m_errorMonitor->ExpectSuccess();
19910
19911 ASSERT_NO_FATAL_FAILURE(InitState());
19912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19913
19914 VkVertexInputBindingDescription input_binding;
19915 memset(&input_binding, 0, sizeof(input_binding));
19916
19917 VkVertexInputAttributeDescription input_attribs[2];
19918 memset(input_attribs, 0, sizeof(input_attribs));
19919
19920 for (int i = 0; i < 2; i++) {
19921 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19922 input_attribs[i].location = i;
19923 }
19924
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019925 char const *vsSource =
19926 "#version 450\n"
19927 "\n"
19928 "layout(location=0) in vec4 x[2];\n"
19929 "out gl_PerVertex {\n"
19930 " vec4 gl_Position;\n"
19931 "};\n"
19932 "void main(){\n"
19933 " gl_Position = x[0] + x[1];\n"
19934 "}\n";
19935 char const *fsSource =
19936 "#version 450\n"
19937 "\n"
19938 "layout(location=0) out vec4 color;\n"
19939 "void main(){\n"
19940 " color = vec4(1);\n"
19941 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019942
19943 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19944 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19945
19946 VkPipelineObj pipe(m_device);
19947 pipe.AddColorAttachment();
19948 pipe.AddShader(&vs);
19949 pipe.AddShader(&fs);
19950
19951 pipe.AddVertexInputBindings(&input_binding, 1);
19952 pipe.AddVertexInputAttribs(input_attribs, 2);
19953
19954 VkDescriptorSetObj descriptorSet(m_device);
19955 descriptorSet.AppendDummy();
19956 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19957
19958 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19959
19960 m_errorMonitor->VerifyNotFound();
19961}
19962
19963TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019964 TEST_DESCRIPTION(
19965 "Test that pipeline validation accepts consuming a vertex attribute "
19966 "through multiple vertex shader inputs, each consuming a different "
19967 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019968 m_errorMonitor->ExpectSuccess();
19969
19970 ASSERT_NO_FATAL_FAILURE(InitState());
19971 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19972
19973 VkVertexInputBindingDescription input_binding;
19974 memset(&input_binding, 0, sizeof(input_binding));
19975
19976 VkVertexInputAttributeDescription input_attribs[3];
19977 memset(input_attribs, 0, sizeof(input_attribs));
19978
19979 for (int i = 0; i < 3; i++) {
19980 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19981 input_attribs[i].location = i;
19982 }
19983
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019984 char const *vsSource =
19985 "#version 450\n"
19986 "\n"
19987 "layout(location=0) in vec4 x;\n"
19988 "layout(location=1) in vec3 y1;\n"
19989 "layout(location=1, component=3) in float y2;\n"
19990 "layout(location=2) in vec4 z;\n"
19991 "out gl_PerVertex {\n"
19992 " vec4 gl_Position;\n"
19993 "};\n"
19994 "void main(){\n"
19995 " gl_Position = x + vec4(y1, y2) + z;\n"
19996 "}\n";
19997 char const *fsSource =
19998 "#version 450\n"
19999 "\n"
20000 "layout(location=0) out vec4 color;\n"
20001 "void main(){\n"
20002 " color = vec4(1);\n"
20003 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020004
20005 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20006 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20007
20008 VkPipelineObj pipe(m_device);
20009 pipe.AddColorAttachment();
20010 pipe.AddShader(&vs);
20011 pipe.AddShader(&fs);
20012
20013 pipe.AddVertexInputBindings(&input_binding, 1);
20014 pipe.AddVertexInputAttribs(input_attribs, 3);
20015
20016 VkDescriptorSetObj descriptorSet(m_device);
20017 descriptorSet.AppendDummy();
20018 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20019
20020 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20021
20022 m_errorMonitor->VerifyNotFound();
20023}
20024
20025TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
20026 m_errorMonitor->ExpectSuccess();
20027
20028 ASSERT_NO_FATAL_FAILURE(InitState());
20029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20030
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020031 char const *vsSource =
20032 "#version 450\n"
20033 "out gl_PerVertex {\n"
20034 " vec4 gl_Position;\n"
20035 "};\n"
20036 "void main(){\n"
20037 " gl_Position = vec4(0);\n"
20038 "}\n";
20039 char const *fsSource =
20040 "#version 450\n"
20041 "\n"
20042 "layout(location=0) out vec4 color;\n"
20043 "void main(){\n"
20044 " color = vec4(1);\n"
20045 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020046
20047 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20048 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20049
20050 VkPipelineObj pipe(m_device);
20051 pipe.AddColorAttachment();
20052 pipe.AddShader(&vs);
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, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020065 TEST_DESCRIPTION(
20066 "Test that pipeline validation accepts the relaxed type matching rules "
20067 "set out in 14.1.3: fundamental type must match, and producer side must "
20068 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020069 m_errorMonitor->ExpectSuccess();
20070
20071 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
20072
20073 ASSERT_NO_FATAL_FAILURE(InitState());
20074 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20075
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020076 char const *vsSource =
20077 "#version 450\n"
20078 "out gl_PerVertex {\n"
20079 " vec4 gl_Position;\n"
20080 "};\n"
20081 "layout(location=0) out vec3 x;\n"
20082 "layout(location=1) out ivec3 y;\n"
20083 "layout(location=2) out vec3 z;\n"
20084 "void main(){\n"
20085 " gl_Position = vec4(0);\n"
20086 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
20087 "}\n";
20088 char const *fsSource =
20089 "#version 450\n"
20090 "\n"
20091 "layout(location=0) out vec4 color;\n"
20092 "layout(location=0) in float x;\n"
20093 "layout(location=1) flat in int y;\n"
20094 "layout(location=2) in vec2 z;\n"
20095 "void main(){\n"
20096 " color = vec4(1 + x + y + z.x);\n"
20097 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020098
20099 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20100 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20101
20102 VkPipelineObj pipe(m_device);
20103 pipe.AddColorAttachment();
20104 pipe.AddShader(&vs);
20105 pipe.AddShader(&fs);
20106
20107 VkDescriptorSetObj descriptorSet(m_device);
20108 descriptorSet.AppendDummy();
20109 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20110
20111 VkResult err = VK_SUCCESS;
20112 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20113 ASSERT_VK_SUCCESS(err);
20114
20115 m_errorMonitor->VerifyNotFound();
20116}
20117
20118TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020119 TEST_DESCRIPTION(
20120 "Test that pipeline validation accepts per-vertex variables "
20121 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020122 m_errorMonitor->ExpectSuccess();
20123
20124 ASSERT_NO_FATAL_FAILURE(InitState());
20125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20126
20127 if (!m_device->phy().features().tessellationShader) {
20128 printf("Device does not support tessellation shaders; skipped.\n");
20129 return;
20130 }
20131
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020132 char const *vsSource =
20133 "#version 450\n"
20134 "void main(){}\n";
20135 char const *tcsSource =
20136 "#version 450\n"
20137 "layout(location=0) out int x[];\n"
20138 "layout(vertices=3) out;\n"
20139 "void main(){\n"
20140 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
20141 " gl_TessLevelInner[0] = 1;\n"
20142 " x[gl_InvocationID] = gl_InvocationID;\n"
20143 "}\n";
20144 char const *tesSource =
20145 "#version 450\n"
20146 "layout(triangles, equal_spacing, cw) in;\n"
20147 "layout(location=0) in int x[];\n"
20148 "out gl_PerVertex { vec4 gl_Position; };\n"
20149 "void main(){\n"
20150 " gl_Position.xyz = gl_TessCoord;\n"
20151 " gl_Position.w = x[0] + x[1] + x[2];\n"
20152 "}\n";
20153 char const *fsSource =
20154 "#version 450\n"
20155 "layout(location=0) out vec4 color;\n"
20156 "void main(){\n"
20157 " color = vec4(1);\n"
20158 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020159
20160 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20161 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
20162 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
20163 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20164
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020165 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
20166 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020167
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020168 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020169
20170 VkPipelineObj pipe(m_device);
20171 pipe.SetInputAssembly(&iasci);
20172 pipe.SetTessellation(&tsci);
20173 pipe.AddColorAttachment();
20174 pipe.AddShader(&vs);
20175 pipe.AddShader(&tcs);
20176 pipe.AddShader(&tes);
20177 pipe.AddShader(&fs);
20178
20179 VkDescriptorSetObj descriptorSet(m_device);
20180 descriptorSet.AppendDummy();
20181 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20182
20183 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20184
20185 m_errorMonitor->VerifyNotFound();
20186}
20187
20188TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020189 TEST_DESCRIPTION(
20190 "Test that pipeline validation accepts a user-defined "
20191 "interface block passed into the geometry shader. This "
20192 "is interesting because the 'extra' array level is not "
20193 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020194 m_errorMonitor->ExpectSuccess();
20195
20196 ASSERT_NO_FATAL_FAILURE(InitState());
20197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20198
20199 if (!m_device->phy().features().geometryShader) {
20200 printf("Device does not support geometry shaders; skipped.\n");
20201 return;
20202 }
20203
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020204 char const *vsSource =
20205 "#version 450\n"
20206 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
20207 "void main(){\n"
20208 " vs_out.x = vec4(1);\n"
20209 "}\n";
20210 char const *gsSource =
20211 "#version 450\n"
20212 "layout(triangles) in;\n"
20213 "layout(triangle_strip, max_vertices=3) out;\n"
20214 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
20215 "out gl_PerVertex { vec4 gl_Position; };\n"
20216 "void main() {\n"
20217 " gl_Position = gs_in[0].x;\n"
20218 " EmitVertex();\n"
20219 "}\n";
20220 char const *fsSource =
20221 "#version 450\n"
20222 "layout(location=0) out vec4 color;\n"
20223 "void main(){\n"
20224 " color = vec4(1);\n"
20225 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020226
20227 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20228 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
20229 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20230
20231 VkPipelineObj pipe(m_device);
20232 pipe.AddColorAttachment();
20233 pipe.AddShader(&vs);
20234 pipe.AddShader(&gs);
20235 pipe.AddShader(&fs);
20236
20237 VkDescriptorSetObj descriptorSet(m_device);
20238 descriptorSet.AppendDummy();
20239 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20240
20241 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20242
20243 m_errorMonitor->VerifyNotFound();
20244}
20245
20246TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020247 TEST_DESCRIPTION(
20248 "Test that pipeline validation accepts basic use of 64bit vertex "
20249 "attributes. This is interesting because they consume multiple "
20250 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020251 m_errorMonitor->ExpectSuccess();
20252
20253 ASSERT_NO_FATAL_FAILURE(InitState());
20254 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20255
20256 if (!m_device->phy().features().shaderFloat64) {
20257 printf("Device does not support 64bit vertex attributes; skipped.\n");
20258 return;
20259 }
20260
20261 VkVertexInputBindingDescription input_bindings[1];
20262 memset(input_bindings, 0, sizeof(input_bindings));
20263
20264 VkVertexInputAttributeDescription input_attribs[4];
20265 memset(input_attribs, 0, sizeof(input_attribs));
20266 input_attribs[0].location = 0;
20267 input_attribs[0].offset = 0;
20268 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20269 input_attribs[1].location = 2;
20270 input_attribs[1].offset = 32;
20271 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20272 input_attribs[2].location = 4;
20273 input_attribs[2].offset = 64;
20274 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20275 input_attribs[3].location = 6;
20276 input_attribs[3].offset = 96;
20277 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20278
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020279 char const *vsSource =
20280 "#version 450\n"
20281 "\n"
20282 "layout(location=0) in dmat4 x;\n"
20283 "out gl_PerVertex {\n"
20284 " vec4 gl_Position;\n"
20285 "};\n"
20286 "void main(){\n"
20287 " gl_Position = vec4(x[0][0]);\n"
20288 "}\n";
20289 char const *fsSource =
20290 "#version 450\n"
20291 "\n"
20292 "layout(location=0) out vec4 color;\n"
20293 "void main(){\n"
20294 " color = vec4(1);\n"
20295 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020296
20297 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20298 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20299
20300 VkPipelineObj pipe(m_device);
20301 pipe.AddColorAttachment();
20302 pipe.AddShader(&vs);
20303 pipe.AddShader(&fs);
20304
20305 pipe.AddVertexInputBindings(input_bindings, 1);
20306 pipe.AddVertexInputAttribs(input_attribs, 4);
20307
20308 VkDescriptorSetObj descriptorSet(m_device);
20309 descriptorSet.AppendDummy();
20310 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20311
20312 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20313
20314 m_errorMonitor->VerifyNotFound();
20315}
20316
20317TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20318 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20319 m_errorMonitor->ExpectSuccess();
20320
20321 ASSERT_NO_FATAL_FAILURE(InitState());
20322
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020323 char const *vsSource =
20324 "#version 450\n"
20325 "\n"
20326 "out gl_PerVertex {\n"
20327 " vec4 gl_Position;\n"
20328 "};\n"
20329 "void main(){\n"
20330 " gl_Position = vec4(1);\n"
20331 "}\n";
20332 char const *fsSource =
20333 "#version 450\n"
20334 "\n"
20335 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20336 "layout(location=0) out vec4 color;\n"
20337 "void main() {\n"
20338 " color = subpassLoad(x);\n"
20339 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020340
20341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20343
20344 VkPipelineObj pipe(m_device);
20345 pipe.AddShader(&vs);
20346 pipe.AddShader(&fs);
20347 pipe.AddColorAttachment();
20348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20349
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020350 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
20351 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020352 VkDescriptorSetLayout dsl;
20353 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20354 ASSERT_VK_SUCCESS(err);
20355
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020356 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020357 VkPipelineLayout pl;
20358 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20359 ASSERT_VK_SUCCESS(err);
20360
20361 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020362 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20363 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20364 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
20365 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20366 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 -060020367 };
20368 VkAttachmentReference color = {
20369 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20370 };
20371 VkAttachmentReference input = {
20372 1, VK_IMAGE_LAYOUT_GENERAL,
20373 };
20374
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020375 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020376
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020377 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020378 VkRenderPass rp;
20379 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20380 ASSERT_VK_SUCCESS(err);
20381
20382 // should be OK. would go wrong here if it's going to...
20383 pipe.CreateVKPipeline(pl, rp);
20384
20385 m_errorMonitor->VerifyNotFound();
20386
20387 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20388 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20389 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20390}
20391
20392TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020393 TEST_DESCRIPTION(
20394 "Test that pipeline validation accepts a compute pipeline which declares a "
20395 "descriptor-backed resource which is not provided, but the shader does not "
20396 "statically use it. This is interesting because it requires compute pipelines "
20397 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020398 m_errorMonitor->ExpectSuccess();
20399
20400 ASSERT_NO_FATAL_FAILURE(InitState());
20401
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020402 char const *csSource =
20403 "#version 450\n"
20404 "\n"
20405 "layout(local_size_x=1) in;\n"
20406 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20407 "void main(){\n"
20408 " // x is not used.\n"
20409 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020410
20411 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20412
20413 VkDescriptorSetObj descriptorSet(m_device);
20414 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20415
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020416 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20417 nullptr,
20418 0,
20419 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20420 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20421 descriptorSet.GetPipelineLayout(),
20422 VK_NULL_HANDLE,
20423 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020424
20425 VkPipeline pipe;
20426 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20427
20428 m_errorMonitor->VerifyNotFound();
20429
20430 if (err == VK_SUCCESS) {
20431 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20432 }
20433}
20434
20435TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020436 TEST_DESCRIPTION(
20437 "Test that pipeline validation accepts a shader consuming only the "
20438 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020439 m_errorMonitor->ExpectSuccess();
20440
20441 ASSERT_NO_FATAL_FAILURE(InitState());
20442
20443 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020444 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20445 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20446 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020447 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020448 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020449 VkDescriptorSetLayout dsl;
20450 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20451 ASSERT_VK_SUCCESS(err);
20452
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020453 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020454 VkPipelineLayout pl;
20455 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20456 ASSERT_VK_SUCCESS(err);
20457
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020458 char const *csSource =
20459 "#version 450\n"
20460 "\n"
20461 "layout(local_size_x=1) in;\n"
20462 "layout(set=0, binding=0) uniform sampler s;\n"
20463 "layout(set=0, binding=1) uniform texture2D t;\n"
20464 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20465 "void main() {\n"
20466 " x = texture(sampler2D(t, s), vec2(0));\n"
20467 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020468 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20469
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020470 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20471 nullptr,
20472 0,
20473 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20474 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20475 pl,
20476 VK_NULL_HANDLE,
20477 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020478
20479 VkPipeline pipe;
20480 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20481
20482 m_errorMonitor->VerifyNotFound();
20483
20484 if (err == VK_SUCCESS) {
20485 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20486 }
20487
20488 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20489 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20490}
20491
20492TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020493 TEST_DESCRIPTION(
20494 "Test that pipeline validation accepts a shader consuming only the "
20495 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020496 m_errorMonitor->ExpectSuccess();
20497
20498 ASSERT_NO_FATAL_FAILURE(InitState());
20499
20500 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020501 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20502 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20503 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020504 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020505 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020506 VkDescriptorSetLayout dsl;
20507 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20508 ASSERT_VK_SUCCESS(err);
20509
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020510 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020511 VkPipelineLayout pl;
20512 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20513 ASSERT_VK_SUCCESS(err);
20514
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020515 char const *csSource =
20516 "#version 450\n"
20517 "\n"
20518 "layout(local_size_x=1) in;\n"
20519 "layout(set=0, binding=0) uniform texture2D t;\n"
20520 "layout(set=0, binding=1) uniform sampler s;\n"
20521 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20522 "void main() {\n"
20523 " x = texture(sampler2D(t, s), vec2(0));\n"
20524 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020525 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20526
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020527 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20528 nullptr,
20529 0,
20530 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20531 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20532 pl,
20533 VK_NULL_HANDLE,
20534 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020535
20536 VkPipeline pipe;
20537 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20538
20539 m_errorMonitor->VerifyNotFound();
20540
20541 if (err == VK_SUCCESS) {
20542 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20543 }
20544
20545 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20546 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20547}
20548
20549TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020550 TEST_DESCRIPTION(
20551 "Test that pipeline validation accepts a shader consuming "
20552 "both the sampler and the image of a combined image+sampler "
20553 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020554 m_errorMonitor->ExpectSuccess();
20555
20556 ASSERT_NO_FATAL_FAILURE(InitState());
20557
20558 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020559 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20560 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020561 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020562 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020563 VkDescriptorSetLayout dsl;
20564 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20565 ASSERT_VK_SUCCESS(err);
20566
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020567 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020568 VkPipelineLayout pl;
20569 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20570 ASSERT_VK_SUCCESS(err);
20571
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020572 char const *csSource =
20573 "#version 450\n"
20574 "\n"
20575 "layout(local_size_x=1) in;\n"
20576 "layout(set=0, binding=0) uniform texture2D t;\n"
20577 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20578 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20579 "void main() {\n"
20580 " x = texture(sampler2D(t, s), vec2(0));\n"
20581 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020582 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20583
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020584 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20585 nullptr,
20586 0,
20587 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20588 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20589 pl,
20590 VK_NULL_HANDLE,
20591 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020592
20593 VkPipeline pipe;
20594 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20595
20596 m_errorMonitor->VerifyNotFound();
20597
20598 if (err == VK_SUCCESS) {
20599 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20600 }
20601
20602 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20603 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20604}
20605
20606TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20607 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20608
20609 ASSERT_NO_FATAL_FAILURE(InitState());
20610
20611 // Positive test to check parameter_validation and unique_objects support
20612 // for NV_dedicated_allocation
20613 uint32_t extension_count = 0;
20614 bool supports_nv_dedicated_allocation = false;
20615 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20616 ASSERT_VK_SUCCESS(err);
20617
20618 if (extension_count > 0) {
20619 std::vector<VkExtensionProperties> available_extensions(extension_count);
20620
20621 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20622 ASSERT_VK_SUCCESS(err);
20623
20624 for (const auto &extension_props : available_extensions) {
20625 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20626 supports_nv_dedicated_allocation = true;
20627 }
20628 }
20629 }
20630
20631 if (supports_nv_dedicated_allocation) {
20632 m_errorMonitor->ExpectSuccess();
20633
20634 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20635 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20636 dedicated_buffer_create_info.pNext = nullptr;
20637 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20638
20639 uint32_t queue_family_index = 0;
20640 VkBufferCreateInfo buffer_create_info = {};
20641 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20642 buffer_create_info.pNext = &dedicated_buffer_create_info;
20643 buffer_create_info.size = 1024;
20644 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20645 buffer_create_info.queueFamilyIndexCount = 1;
20646 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20647
20648 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070020649 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020650 ASSERT_VK_SUCCESS(err);
20651
20652 VkMemoryRequirements memory_reqs;
20653 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20654
20655 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20656 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20657 dedicated_memory_info.pNext = nullptr;
20658 dedicated_memory_info.buffer = buffer;
20659 dedicated_memory_info.image = VK_NULL_HANDLE;
20660
20661 VkMemoryAllocateInfo memory_info = {};
20662 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20663 memory_info.pNext = &dedicated_memory_info;
20664 memory_info.allocationSize = memory_reqs.size;
20665
20666 bool pass;
20667 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20668 ASSERT_TRUE(pass);
20669
20670 VkDeviceMemory buffer_memory;
20671 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20672 ASSERT_VK_SUCCESS(err);
20673
20674 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20675 ASSERT_VK_SUCCESS(err);
20676
20677 vkDestroyBuffer(m_device->device(), buffer, NULL);
20678 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20679
20680 m_errorMonitor->VerifyNotFound();
20681 }
20682}
20683
20684TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20685 VkResult err;
20686
20687 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20688
20689 ASSERT_NO_FATAL_FAILURE(InitState());
20690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20691
20692 std::vector<const char *> device_extension_names;
20693 auto features = m_device->phy().features();
20694 // Artificially disable support for non-solid fill modes
20695 features.fillModeNonSolid = false;
20696 // The sacrificial device object
20697 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20698
20699 VkRenderpassObj render_pass(&test_device);
20700
20701 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20702 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20703 pipeline_layout_ci.setLayoutCount = 0;
20704 pipeline_layout_ci.pSetLayouts = NULL;
20705
20706 VkPipelineLayout pipeline_layout;
20707 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20708 ASSERT_VK_SUCCESS(err);
20709
20710 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20711 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20712 rs_ci.pNext = nullptr;
20713 rs_ci.lineWidth = 1.0f;
20714 rs_ci.rasterizerDiscardEnable = true;
20715
20716 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20717 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20718
20719 // Set polygonMode=FILL. No error is expected
20720 m_errorMonitor->ExpectSuccess();
20721 {
20722 VkPipelineObj pipe(&test_device);
20723 pipe.AddShader(&vs);
20724 pipe.AddShader(&fs);
20725 pipe.AddColorAttachment();
20726 // Set polygonMode to a good value
20727 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20728 pipe.SetRasterization(&rs_ci);
20729 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20730 }
20731 m_errorMonitor->VerifyNotFound();
20732
20733 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20734}
20735
20736TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20737 VkResult err;
20738 ASSERT_NO_FATAL_FAILURE(InitState());
20739 ASSERT_NO_FATAL_FAILURE(InitViewport());
20740 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20741
20742 VkPipelineLayout pipeline_layout;
20743 VkPushConstantRange pc_range = {};
20744 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20745 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20746 pipeline_layout_ci.pushConstantRangeCount = 1;
20747 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20748
20749 //
20750 // Check for invalid push constant ranges in pipeline layouts.
20751 //
20752 struct PipelineLayoutTestCase {
20753 VkPushConstantRange const range;
20754 char const *msg;
20755 };
20756
20757 // Check for overlapping ranges
20758 const uint32_t ranges_per_test = 5;
20759 struct OverlappingRangeTestCase {
20760 VkPushConstantRange const ranges[ranges_per_test];
20761 char const *msg;
20762 };
20763
20764 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020765 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
20766 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
20767 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
20768 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
20769 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
20770 ""},
20771 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
20772 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
20773 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
20774 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
20775 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
20776 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020777 for (const auto &iter : overlapping_range_tests_pos) {
20778 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20779 m_errorMonitor->ExpectSuccess();
20780 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20781 m_errorMonitor->VerifyNotFound();
20782 if (VK_SUCCESS == err) {
20783 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20784 }
20785 }
20786
20787 //
20788 // CmdPushConstants tests
20789 //
20790 const uint8_t dummy_values[100] = {};
20791
Tony Barbour552f6c02016-12-21 14:34:07 -070020792 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020793
20794 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020795 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
20796 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
20797 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
20798 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
20799 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
20800 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020801
20802 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20803 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020804 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
20805 {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 -060020806 };
20807
20808 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20809 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20810 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20811 ASSERT_VK_SUCCESS(err);
20812 for (const auto &iter : cmd_overlap_tests_pos) {
20813 m_errorMonitor->ExpectSuccess();
20814 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020815 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020816 m_errorMonitor->VerifyNotFound();
20817 }
20818 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20819
Tony Barbour552f6c02016-12-21 14:34:07 -070020820 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020821}
20822
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020823#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020824TEST_F(VkPositiveLayerTest, LongFenceChain)
20825{
20826 m_errorMonitor->ExpectSuccess();
20827
20828 ASSERT_NO_FATAL_FAILURE(InitState());
20829 VkResult err;
20830
20831 std::vector<VkFence> fences;
20832
20833 const int chainLength = 32768;
20834
20835 for (int i = 0; i < chainLength; i++) {
20836 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20837 VkFence fence;
20838 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20839 ASSERT_VK_SUCCESS(err);
20840
20841 fences.push_back(fence);
20842
20843 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20844 0, nullptr, 0, nullptr };
20845 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20846 ASSERT_VK_SUCCESS(err);
20847
20848 }
20849
20850 // BOOM, stack overflow.
20851 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20852
20853 for (auto fence : fences)
20854 vkDestroyFence(m_device->device(), fence, nullptr);
20855
20856 m_errorMonitor->VerifyNotFound();
20857}
20858#endif
20859
Cody Northrop1242dfd2016-07-13 17:24:59 -060020860#if defined(ANDROID) && defined(VALIDATION_APK)
20861static bool initialized = false;
20862static bool active = false;
20863
20864// Convert Intents to argv
20865// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020866std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020867 std::vector<std::string> args;
20868 JavaVM &vm = *app.activity->vm;
20869 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020870 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020871
20872 JNIEnv &env = *p_env;
20873 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020874 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020875 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020876 jmethodID get_string_extra_method =
20877 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020878 jvalue get_string_extra_args;
20879 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020880 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020881
20882 std::string args_str;
20883 if (extra_str) {
20884 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20885 args_str = extra_utf;
20886 env.ReleaseStringUTFChars(extra_str, extra_utf);
20887 env.DeleteLocalRef(extra_str);
20888 }
20889
20890 env.DeleteLocalRef(get_string_extra_args.l);
20891 env.DeleteLocalRef(intent);
20892 vm.DetachCurrentThread();
20893
20894 // split args_str
20895 std::stringstream ss(args_str);
20896 std::string arg;
20897 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020898 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020899 }
20900
20901 return args;
20902}
20903
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020904static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020905
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020906static void processCommand(struct android_app *app, int32_t cmd) {
20907 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020908 case APP_CMD_INIT_WINDOW: {
20909 if (app->window) {
20910 initialized = true;
20911 }
20912 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020913 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020914 case APP_CMD_GAINED_FOCUS: {
20915 active = true;
20916 break;
20917 }
20918 case APP_CMD_LOST_FOCUS: {
20919 active = false;
20920 break;
20921 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020922 }
20923}
20924
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020925void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020926 app_dummy();
20927
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020928 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020929
20930 int vulkanSupport = InitVulkan();
20931 if (vulkanSupport == 0) {
20932 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20933 return;
20934 }
20935
20936 app->onAppCmd = processCommand;
20937 app->onInputEvent = processInput;
20938
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020939 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020940 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020941 struct android_poll_source *source;
20942 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020943 if (source) {
20944 source->process(app, source);
20945 }
20946
20947 if (app->destroyRequested != 0) {
20948 VkTestFramework::Finish();
20949 return;
20950 }
20951 }
20952
20953 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020954 // Use the following key to send arguments to gtest, i.e.
20955 // --es args "--gtest_filter=-VkLayerTest.foo"
20956 const char key[] = "args";
20957 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020959 std::string filter = "";
20960 if (args.size() > 0) {
20961 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20962 filter += args[0];
20963 } else {
20964 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20965 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020966
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020967 int argc = 2;
20968 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20969 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020970
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020971 // Route output to files until we can override the gtest output
20972 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20973 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020975 ::testing::InitGoogleTest(&argc, argv);
20976 VkTestFramework::InitArgs(&argc, argv);
20977 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020978
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020979 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020980
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020981 if (result != 0) {
20982 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20983 } else {
20984 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20985 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020986
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020987 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020988
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020989 fclose(stdout);
20990 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020991
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020992 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020993
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020994 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020995 }
20996 }
20997}
20998#endif
20999
Tony Barbour300a6082015-04-07 13:44:53 -060021000int main(int argc, char **argv) {
21001 int result;
21002
Cody Northrop8e54a402016-03-08 22:25:52 -070021003#ifdef ANDROID
21004 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021005 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070021006#endif
21007
Tony Barbour300a6082015-04-07 13:44:53 -060021008 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060021009 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060021010
21011 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
21012
21013 result = RUN_ALL_TESTS();
21014
Tony Barbour6918cd52015-04-09 12:58:51 -060021015 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060021016 return result;
21017}