blob: 7237531fcbe9f67e1c39528fefeb2b811e04e3c1 [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 {
59 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 Lobodzinskice751c62016-09-08 10:45:35 -060087static const char bindStateVertShaderText[] = "#version 450\n"
88 "vec2 vertices[3];\n"
89 "out gl_PerVertex {\n"
90 " vec4 gl_Position;\n"
91 "};\n"
92 "void main() {\n"
93 " vertices[0] = vec2(-1.0, -1.0);\n"
94 " vertices[1] = vec2( 1.0, -1.0);\n"
95 " vertices[2] = vec2( 0.0, 1.0);\n"
96 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static const char bindStateFragShaderText[] = "#version 450\n"
100 "\n"
101 "layout(location = 0) out vec4 uFragColor;\n"
102 "void main(){\n"
103 " uFragColor = vec4(0,1,0,1);\n"
104 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500105
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600106static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
107 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
108 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600109
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110// ErrorMonitor Usage:
111//
Dave Houltonfbf52152017-01-06 12:55:29 -0700112// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600113// encountered log messages, or a validation error enum identifying
114// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
115// will match all log messages. logMsg will return true for skipCall
116// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600117//
Dave Houltonfbf52152017-01-06 12:55:29 -0700118// Call VerifyFound to determine if all desired failure messages
119// were encountered. Call VerifyNotFound to determine if any unexpected
120// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600121class ErrorMonitor {
Karl Schultz6addd812016-02-02 17:17:23 -0700122 public:
123 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700124 test_platform_thread_create_mutex(&mutex_);
125 test_platform_thread_lock_mutex(&mutex_);
126 Reset();
127 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600128 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600129
Dave Houltonfbf52152017-01-06 12:55:29 -0700130 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600131
Dave Houltonfbf52152017-01-06 12:55:29 -0700132 // Set monitor to pristine state
133 void Reset() {
134 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
135 bailout_ = NULL;
136 message_found_ = VK_FALSE;
137 failure_message_strings_.clear();
138 desired_message_strings_.clear();
139 desired_message_ids_.clear();
140 other_messages_.clear();
141 message_outstanding_count_ = 0;
142 }
143
144 // ErrorMonitor will look for an error message containing the specified string(s)
Karl Schultz6addd812016-02-02 17:17:23 -0700145 void SetDesiredFailureMsg(VkFlags msgFlags, const char *msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700146 test_platform_thread_lock_mutex(&mutex_);
147 desired_message_strings_.insert(msgString);
148 message_flags_ |= msgFlags;
149 message_outstanding_count_++;
150 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600151 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600152
Dave Houltonfbf52152017-01-06 12:55:29 -0700153 // ErrorMonitor will look for a message ID matching the specified one(s)
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600154 void SetDesiredFailureMsg(VkFlags msgFlags, UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700155 test_platform_thread_lock_mutex(&mutex_);
156 desired_message_ids_.insert(msg_id);
157 message_flags_ |= msgFlags;
158 message_outstanding_count_++;
159 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600160 }
161
162 VkBool32 CheckForDesiredMsg(uint32_t message_code, const char *msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600163 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700164 test_platform_thread_lock_mutex(&mutex_);
165 if (bailout_ != NULL) {
166 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600167 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600168 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600169 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600170
Dave Houltonfbf52152017-01-06 12:55:29 -0700171 for (auto desired_msg : desired_message_strings_) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600172 if (desired_msg.length() == 0) {
173 // An empty desired_msg string "" indicates a positive test - not expecting an error.
174 // Return true to avoid calling layers/driver with this error.
175 // And don't erase the "" string, so it remains if another error is found.
176 result = VK_TRUE;
Tony Barbourae58dba2016-12-13 16:30:36 -0700177 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700178 message_found_ = VK_TRUE;
179 failure_message_strings_.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600180 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600181 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700182 message_outstanding_count_--;
183 failure_message_strings_.insert(errorString);
184 message_found_ = VK_TRUE;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 result = VK_TRUE;
186 // We only want one match for each expected error so remove from set here
187 // 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 -0700188 desired_message_strings_.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600189 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600190 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600191 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700192 for (auto desired_id : desired_message_ids_) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600193 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
194 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
195 // Return true to avoid calling layers/driver with this error.
196 result = VK_TRUE;
197 } else if (desired_id == message_code) {
198 // Double-check that the string matches the error enum
199 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
200 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700201 message_outstanding_count_--;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600202 result = VK_TRUE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700203 message_found_ = VK_TRUE;
204 desired_message_ids_.erase(desired_id);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600205 break;
206 } else {
207 // Treat this message as a regular unexpected error, but print a warning jic
208 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
209 errorString.c_str(), desired_id, validation_error_map[desired_id]);
210 }
211 }
212 }
213
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600214 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200215 printf("Unexpected: %s\n", msgString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700216 other_messages_.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600217 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700218 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600219 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600220 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600221
Dave Houltonfbf52152017-01-06 12:55:29 -0700222 vector<string> GetOtherFailureMsgs(void) { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600223
Dave Houltonfbf52152017-01-06 12:55:29 -0700224 VkDebugReportFlagsEXT GetMessageFlags(void) { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600225
Dave Houltonfbf52152017-01-06 12:55:29 -0700226 VkBool32 AnyDesiredMsgFound(void) { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600227
Dave Houltonfbf52152017-01-06 12:55:29 -0700228 VkBool32 AllDesiredMsgsFound(void) { return (0 == message_outstanding_count_); }
229
230 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600231
Karl Schultz6addd812016-02-02 17:17:23 -0700232 void DumpFailureMsgs(void) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600233 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600234 if (otherMsgs.size()) {
235 cout << "Other error messages logged for this test were:" << endl;
236 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
237 cout << " " << *iter << endl;
238 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600239 }
240 }
241
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600242 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200243
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
245 void ExpectSuccess(VkDebugReportFlagsEXT message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600246 // Match ANY message matching specified type
247 SetDesiredFailureMsg(message_flag_mask, "");
Dave Houltonfbf52152017-01-06 12:55:29 -0700248 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200249 }
250
251 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600252 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700253 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200254 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700255 for (auto desired_msg : desired_message_strings_) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600256 FAIL() << "Did not receive expected error '" << desired_msg << "'";
257 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700258 for (auto desired_id : desired_message_ids_) {
Tony Barbour59b42282016-11-03 13:31:28 -0600259 FAIL() << "Did not receive expected error '" << desired_id << "'";
260 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200261 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700262 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200263 }
264
265 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600266 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700267 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200268 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700269 for (auto msg : failure_message_strings_) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600270 FAIL() << "Expected to succeed but got error: " << msg;
271 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200272 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700273 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200274 }
275
Karl Schultz6addd812016-02-02 17:17:23 -0700276 private:
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 VkFlags message_flags_;
278 std::unordered_set<uint32_t> desired_message_ids_;
279 std::unordered_set<string> desired_message_strings_;
280 std::unordered_set<string> failure_message_strings_;
281 vector<string> other_messages_;
282 test_platform_thread_mutex mutex_;
283 bool *bailout_;
284 VkBool32 message_found_;
285 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600286};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500287
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600288static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
289 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
290 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600291 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
292 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600293 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600294 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600295 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600296}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500297
Karl Schultz6addd812016-02-02 17:17:23 -0700298class VkLayerTest : public VkRenderFramework {
299 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600300 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
301 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700302 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600303 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
304 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700305 }
Tony Barbour300a6082015-04-07 13:44:53 -0600306
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600307 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
308 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700309 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600310 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700311 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600312 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700313 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600314 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
315 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
316 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700317 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
318 }
319 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
320 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
321 }
322
323 protected:
324 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600325 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600326
327 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600328 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600329 std::vector<const char *> instance_extension_names;
330 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600331
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700332 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600333 /*
334 * Since CreateDbgMsgCallback is an instance level extension call
335 * any extension / layer that utilizes that feature also needs
336 * to be enabled at create instance time.
337 */
Karl Schultz6addd812016-02-02 17:17:23 -0700338 // Use Threading layer first to protect others from
339 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700340 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600341 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800342 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700343 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800344 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600345 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700346 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600347
Ian Elliott2c1daf52016-05-12 09:41:46 -0600348 if (m_enableWSI) {
349 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
350 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
351#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
352#if defined(VK_USE_PLATFORM_ANDROID_KHR)
353 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
354#endif // VK_USE_PLATFORM_ANDROID_KHR
355#if defined(VK_USE_PLATFORM_MIR_KHR)
356 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
357#endif // VK_USE_PLATFORM_MIR_KHR
358#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
359 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
360#endif // VK_USE_PLATFORM_WAYLAND_KHR
361#if defined(VK_USE_PLATFORM_WIN32_KHR)
362 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
363#endif // VK_USE_PLATFORM_WIN32_KHR
364#endif // NEED_TO_TEST_THIS_ON_PLATFORM
365#if defined(VK_USE_PLATFORM_XCB_KHR)
366 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
367#elif defined(VK_USE_PLATFORM_XLIB_KHR)
368 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
369#endif // VK_USE_PLATFORM_XLIB_KHR
370 }
371
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600372 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600373 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800374 this->app_info.pApplicationName = "layer_tests";
375 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600376 this->app_info.pEngineName = "unittest";
377 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600378 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600379
Tony Barbour15524c32015-04-29 17:34:29 -0600380 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600381 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600382 }
383
384 virtual void TearDown() {
385 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600386 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600387 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600388 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600389
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600390 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600391};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500392
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600393void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500394 // Create identity matrix
395 int i;
396 struct vktriangle_vs_uniform data;
397
398 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700399 glm::mat4 View = glm::mat4(1.0f);
400 glm::mat4 Model = glm::mat4(1.0f);
401 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500402 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700403 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500404
405 memcpy(&data.mvp, &MVP[0][0], matrixSize);
406
Karl Schultz6addd812016-02-02 17:17:23 -0700407 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600408 {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 -0500409 };
410
Karl Schultz6addd812016-02-02 17:17:23 -0700411 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500412 data.position[i][0] = tri_data[i].posX;
413 data.position[i][1] = tri_data[i].posY;
414 data.position[i][2] = tri_data[i].posZ;
415 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700416 data.color[i][0] = tri_data[i].r;
417 data.color[i][1] = tri_data[i].g;
418 data.color[i][2] = tri_data[i].b;
419 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500420 }
421
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500422 ASSERT_NO_FATAL_FAILURE(InitViewport());
423
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200424 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
425 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500426
Karl Schultz6addd812016-02-02 17:17:23 -0700427 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600428 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500429
430 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800431 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500432 pipelineobj.AddShader(&vs);
433 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600434 if (failMask & BsoFailLineWidth) {
435 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600436 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600437 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600438 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
439 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600440 }
441 if (failMask & BsoFailDepthBias) {
442 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600443 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600444 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600445 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600446 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600447 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600448 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700449 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700450 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600451 if (failMask & BsoFailViewport) {
452 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
453 }
454 if (failMask & BsoFailScissor) {
455 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
456 }
457 if (failMask & BsoFailBlend) {
458 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600459 VkPipelineColorBlendAttachmentState att_state = {};
460 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
461 att_state.blendEnable = VK_TRUE;
462 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600463 }
464 if (failMask & BsoFailDepthBounds) {
465 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
466 }
467 if (failMask & BsoFailStencilReadMask) {
468 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
469 }
470 if (failMask & BsoFailStencilWriteMask) {
471 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
472 }
473 if (failMask & BsoFailStencilReference) {
474 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
475 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500476
477 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600478 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500479
480 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700481 m_commandBuffer->BeginCommandBuffer();
482 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500483
Tony Barbourfe3351b2015-07-28 10:17:20 -0600484 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500485
486 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600487 if (failMask & BsoFailIndexBuffer) {
488 // Use DrawIndexed w/o an index buffer bound
489 DrawIndexed(3, 1, 0, 0, 0);
490 } else {
491 Draw(3, 1, 0, 0);
492 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500493
Mark Muellerd4914412016-06-13 17:52:06 -0600494 if (failMask & BsoFailCmdClearAttachments) {
495 VkClearAttachment color_attachment = {};
496 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
497 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
498 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
499
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600500 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600501 }
502
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500503 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700504 m_commandBuffer->EndRenderPass();
505 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600506 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507}
508
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600509void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
510 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600512 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500513 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600514 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500515 }
516
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800517 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700518 // Make sure depthWriteEnable is set so that Depth fail test will work
519 // correctly
520 // Make sure stencilTestEnable is set so that Stencil fail test will work
521 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600522 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800523 stencil.failOp = VK_STENCIL_OP_KEEP;
524 stencil.passOp = VK_STENCIL_OP_KEEP;
525 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
526 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600527
528 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
529 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600530 ds_ci.pNext = NULL;
531 ds_ci.depthTestEnable = VK_FALSE;
532 ds_ci.depthWriteEnable = VK_TRUE;
533 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
534 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600535 if (failMask & BsoFailDepthBounds) {
536 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600537 ds_ci.maxDepthBounds = 0.0f;
538 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600539 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600540 ds_ci.stencilTestEnable = VK_TRUE;
541 ds_ci.front = stencil;
542 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600543
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600544 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600545 pipelineobj.SetViewport(m_viewports);
546 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800547 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600548 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600549 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800550 commandBuffer->BindPipeline(pipelineobj);
551 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500552}
553
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600554class VkPositiveLayerTest : public VkLayerTest {
555 public:
556 protected:
557};
558
Ian Elliott2c1daf52016-05-12 09:41:46 -0600559class VkWsiEnabledLayerTest : public VkLayerTest {
560 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600561 protected:
562 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600563};
564
Mark Muellerdfe37552016-07-07 14:47:42 -0600565class VkBufferTest {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600566 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600567 enum eTestEnFlags {
568 eDoubleDelete,
569 eInvalidDeviceOffset,
570 eInvalidMemoryOffset,
571 eBindNullBuffer,
572 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600573 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600574 };
575
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600576 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600577
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600578 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
579 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600580 return true;
581 }
582 VkDeviceSize offset_limit = 0;
583 if (eInvalidMemoryOffset == aTestFlag) {
584 VkBuffer vulkanBuffer;
585 VkBufferCreateInfo buffer_create_info = {};
586 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
587 buffer_create_info.size = 32;
588 buffer_create_info.usage = aBufferUsage;
589
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600590 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600591 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600592
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600594 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
595 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600596 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
597 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600598 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600599 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600600 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600601 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600602 }
603 if (eOffsetAlignment < offset_limit) {
604 return true;
605 }
606 return false;
607 }
608
609 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600610 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
611 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600612
613 if (eBindNullBuffer == aTestFlag) {
614 VulkanMemory = 0;
615 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
616 } else {
617 VkBufferCreateInfo buffer_create_info = {};
618 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
619 buffer_create_info.size = 32;
620 buffer_create_info.usage = aBufferUsage;
621
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600622 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600623
624 CreateCurrent = true;
625
626 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600627 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600628
629 VkMemoryAllocateInfo memory_allocate_info = {};
630 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
631 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600632 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
633 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600634 if (!pass) {
635 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
636 return;
637 }
638
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600639 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600640 AllocateCurrent = true;
641 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
643 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600644 BoundCurrent = true;
645
646 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
647 }
648 }
649
650 ~VkBufferTest() {
651 if (CreateCurrent) {
652 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
653 }
654 if (AllocateCurrent) {
655 if (InvalidDeleteEn) {
656 union {
657 VkDeviceMemory device_memory;
658 unsigned long long index_access;
659 } bad_index;
660
661 bad_index.device_memory = VulkanMemory;
662 bad_index.index_access++;
663
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600664 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600665 }
666 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
667 }
668 }
669
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600670 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600671
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600673
674 void TestDoubleDestroy() {
675 // Destroy the buffer but leave the flag set, which will cause
676 // the buffer to be destroyed again in the destructor.
677 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
678 }
679
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600680 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600681 bool AllocateCurrent;
682 bool BoundCurrent;
683 bool CreateCurrent;
684 bool InvalidDeleteEn;
685
686 VkBuffer VulkanBuffer;
687 VkDevice VulkanDevice;
688 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600689};
690
691class VkVerticesObj {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600692 public:
693 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600694 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600695 : BoundCurrent(false), AttributeCount(aAttributeCount), BindingCount(aBindingCount), BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600696 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600697 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
698 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600699 BindIdGenerator++; // NB: This can wrap w/misuse
700
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600701 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
702 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600703
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600704 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
705 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
706 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
707 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
708 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600709
710 unsigned i = 0;
711 do {
712 VertexInputAttributeDescription[i].binding = BindId;
713 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600714 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
715 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600716 i++;
717 } while (AttributeCount < i);
718
719 i = 0;
720 do {
721 VertexInputBindingDescription[i].binding = BindId;
722 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600723 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600724 i++;
725 } while (BindingCount < i);
726 }
727
728 ~VkVerticesObj() {
729 if (VertexInputAttributeDescription) {
730 delete[] VertexInputAttributeDescription;
731 }
732 if (VertexInputBindingDescription) {
733 delete[] VertexInputBindingDescription;
734 }
735 }
736
737 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600738 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
739 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600740 return true;
741 }
742
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600743 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600744 VkDeviceSize *offsetList;
745 unsigned offsetCount;
746
747 if (aOffsetCount) {
748 offsetList = aOffsetList;
749 offsetCount = aOffsetCount;
750 } else {
751 offsetList = new VkDeviceSize[1]();
752 offsetCount = 1;
753 }
754
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600755 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600756 BoundCurrent = true;
757
758 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600759 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600760 }
761 }
762
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600763 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600764 static uint32_t BindIdGenerator;
765
766 bool BoundCurrent;
767 unsigned AttributeCount;
768 unsigned BindingCount;
769 uint32_t BindId;
770
771 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
772 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
773 VkVertexInputBindingDescription *VertexInputBindingDescription;
774 VkConstantBufferObj VulkanMemoryBuffer;
775};
776
777uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500778// ********************************************************************************************************************
779// ********************************************************************************************************************
780// ********************************************************************************************************************
781// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600782#if PARAMETER_VALIDATION_TESTS
783TEST_F(VkLayerTest, RequiredParameter) {
784 TEST_DESCRIPTION("Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
785 "pointer, array, and array count parameters");
786
787 ASSERT_NO_FATAL_FAILURE(InitState());
788
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600790 // Specify NULL for a pointer to a handle
791 // Expected to trigger an error with
792 // parameter_validation::validate_required_pointer
793 vkGetPhysicalDeviceFeatures(gpu(), NULL);
794 m_errorMonitor->VerifyFound();
795
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
797 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600798 // Specify NULL for pointer to array count
799 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600800 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600801 m_errorMonitor->VerifyFound();
802
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600804 // Specify 0 for a required array count
805 // Expected to trigger an error with parameter_validation::validate_array
806 VkViewport view_port = {};
807 m_commandBuffer->SetViewport(0, 0, &view_port);
808 m_errorMonitor->VerifyFound();
809
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600811 // Specify NULL for a required array
812 // Expected to trigger an error with parameter_validation::validate_array
813 m_commandBuffer->SetViewport(0, 1, NULL);
814 m_errorMonitor->VerifyFound();
815
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600817 // Specify VK_NULL_HANDLE for a required handle
818 // Expected to trigger an error with
819 // parameter_validation::validate_required_handle
820 vkUnmapMemory(device(), VK_NULL_HANDLE);
821 m_errorMonitor->VerifyFound();
822
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
824 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600825 // Specify VK_NULL_HANDLE for a required handle array entry
826 // Expected to trigger an error with
827 // parameter_validation::validate_required_handle_array
828 VkFence fence = VK_NULL_HANDLE;
829 vkResetFences(device(), 1, &fence);
830 m_errorMonitor->VerifyFound();
831
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600833 // Specify NULL for a required struct pointer
834 // Expected to trigger an error with
835 // parameter_validation::validate_struct_type
836 VkDeviceMemory memory = VK_NULL_HANDLE;
837 vkAllocateMemory(device(), NULL, NULL, &memory);
838 m_errorMonitor->VerifyFound();
839
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600841 // Specify 0 for a required VkFlags parameter
842 // Expected to trigger an error with parameter_validation::validate_flags
843 m_commandBuffer->SetStencilReference(0, 0);
844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 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 -0600847 // Specify 0 for a required VkFlags array entry
848 // Expected to trigger an error with
849 // parameter_validation::validate_flags_array
850 VkSemaphore semaphore = VK_NULL_HANDLE;
851 VkPipelineStageFlags stageFlags = 0;
852 VkSubmitInfo submitInfo = {};
853 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
854 submitInfo.waitSemaphoreCount = 1;
855 submitInfo.pWaitSemaphores = &semaphore;
856 submitInfo.pWaitDstStageMask = &stageFlags;
857 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
858 m_errorMonitor->VerifyFound();
859}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600860
Dustin Gravesfce74c02016-05-10 11:42:58 -0600861TEST_F(VkLayerTest, ReservedParameter) {
862 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
863
864 ASSERT_NO_FATAL_FAILURE(InitState());
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600867 // Specify 0 for a reserved VkFlags parameter
868 // Expected to trigger an error with
869 // parameter_validation::validate_reserved_flags
870 VkEvent event_handle = VK_NULL_HANDLE;
871 VkEventCreateInfo event_info = {};
872 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
873 event_info.flags = 1;
874 vkCreateEvent(device(), &event_info, NULL, &event_handle);
875 m_errorMonitor->VerifyFound();
876}
877
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600878TEST_F(VkLayerTest, InvalidStructSType) {
879 TEST_DESCRIPTION("Specify an invalid VkStructureType for a Vulkan "
880 "structure's sType field");
881
882 ASSERT_NO_FATAL_FAILURE(InitState());
883
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600885 // Zero struct memory, effectively setting sType to
886 // VK_STRUCTURE_TYPE_APPLICATION_INFO
887 // Expected to trigger an error with
888 // parameter_validation::validate_struct_type
889 VkMemoryAllocateInfo alloc_info = {};
890 VkDeviceMemory memory = VK_NULL_HANDLE;
891 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
892 m_errorMonitor->VerifyFound();
893
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600894 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600895 // Zero struct memory, effectively setting sType to
896 // VK_STRUCTURE_TYPE_APPLICATION_INFO
897 // Expected to trigger an error with
898 // parameter_validation::validate_struct_type_array
899 VkSubmitInfo submit_info = {};
900 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
901 m_errorMonitor->VerifyFound();
902}
903
904TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600905 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600906
907 ASSERT_NO_FATAL_FAILURE(InitState());
908
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600910 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600911 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600912 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600913 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600914 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600915 // Zero-initialization will provide the correct sType
916 VkApplicationInfo app_info = {};
917 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
918 event_alloc_info.pNext = &app_info;
919 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
920 m_errorMonitor->VerifyFound();
921
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
923 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600924 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
925 // a function that has allowed pNext structure types and specify
926 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600927 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600928 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600929 VkMemoryAllocateInfo memory_alloc_info = {};
930 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
931 memory_alloc_info.pNext = &app_info;
932 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600933 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600934}
Dustin Graves5d33d532016-05-09 16:21:12 -0600935
936TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600937 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600938
939 ASSERT_NO_FATAL_FAILURE(InitState());
940
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not fall within the begin..end "
942 "range of the core VkFormat "
943 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600944 // Specify an invalid VkFormat value
945 // Expected to trigger an error with
946 // parameter_validation::validate_ranged_enum
947 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600948 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600949 m_errorMonitor->VerifyFound();
950
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600951 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 -0600952 // Specify an invalid VkFlags bitmask value
953 // Expected to trigger an error with parameter_validation::validate_flags
954 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600955 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
956 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600957 m_errorMonitor->VerifyFound();
958
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600959 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 -0600960 // Specify an invalid VkFlags array entry
961 // Expected to trigger an error with
962 // parameter_validation::validate_flags_array
963 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600965 VkSubmitInfo submit_info = {};
966 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
967 submit_info.waitSemaphoreCount = 1;
968 submit_info.pWaitSemaphores = &semaphore;
969 submit_info.pWaitDstStageMask = &stage_flags;
970 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
971 m_errorMonitor->VerifyFound();
972
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600974 // Specify an invalid VkBool32 value
975 // Expected to trigger a warning with
976 // parameter_validation::validate_bool32
977 VkSampler sampler = VK_NULL_HANDLE;
978 VkSamplerCreateInfo sampler_info = {};
979 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
980 sampler_info.pNext = NULL;
981 sampler_info.magFilter = VK_FILTER_NEAREST;
982 sampler_info.minFilter = VK_FILTER_NEAREST;
983 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
984 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
985 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
986 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
987 sampler_info.mipLodBias = 1.0;
988 sampler_info.maxAnisotropy = 1;
989 sampler_info.compareEnable = VK_FALSE;
990 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
991 sampler_info.minLod = 1.0;
992 sampler_info.maxLod = 1.0;
993 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
994 sampler_info.unnormalizedCoordinates = VK_FALSE;
995 // Not VK_TRUE or VK_FALSE
996 sampler_info.anisotropyEnable = 3;
997 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
998 m_errorMonitor->VerifyFound();
999}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001000
1001TEST_F(VkLayerTest, FailedReturnValue) {
1002 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1003
1004 ASSERT_NO_FATAL_FAILURE(InitState());
1005
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001006 // Find an unsupported image format
1007 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1008 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1009 VkFormat format = static_cast<VkFormat>(f);
1010 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001011 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001012 unsupported = format;
1013 break;
1014 }
1015 }
1016
1017 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1019 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001020 // Specify an unsupported VkFormat value to generate a
1021 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1022 // Expected to trigger a warning from
1023 // parameter_validation::validate_result
1024 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001025 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1026 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001027 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1028 m_errorMonitor->VerifyFound();
1029 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001030}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001031
1032TEST_F(VkLayerTest, UpdateBufferAlignment) {
1033 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001034 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001035
1036 ASSERT_NO_FATAL_FAILURE(InitState());
1037
1038 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1039 vk_testing::Buffer buffer;
1040 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1041
Tony Barbour552f6c02016-12-21 14:34:07 -07001042 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001043 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001045 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1046 m_errorMonitor->VerifyFound();
1047
1048 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001050 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1051 m_errorMonitor->VerifyFound();
1052
1053 // Introduce failure by using dataSize that is < 0
1054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001055 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001056 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1057 m_errorMonitor->VerifyFound();
1058
1059 // Introduce failure by using dataSize that is > 65536
1060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001061 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001062 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1063 m_errorMonitor->VerifyFound();
1064
Tony Barbour552f6c02016-12-21 14:34:07 -07001065 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001066}
1067
1068TEST_F(VkLayerTest, FillBufferAlignment) {
1069 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072
1073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1074 vk_testing::Buffer buffer;
1075 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1076
Tony Barbour552f6c02016-12-21 14:34:07 -07001077 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078
1079 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001081 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1082 m_errorMonitor->VerifyFound();
1083
1084 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001086 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1087 m_errorMonitor->VerifyFound();
1088
1089 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1092 m_errorMonitor->VerifyFound();
1093
Tony Barbour552f6c02016-12-21 14:34:07 -07001094 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001095}
Dustin Graves40f35822016-06-23 11:12:53 -06001096
Cortd889ff92016-07-27 09:51:27 -07001097TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1098 VkResult err;
1099
1100 TEST_DESCRIPTION("Attempt to use a non-solid polygon fill mode in a "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001101 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001102
1103 ASSERT_NO_FATAL_FAILURE(InitState());
1104 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1105
1106 std::vector<const char *> device_extension_names;
1107 auto features = m_device->phy().features();
1108 // Artificially disable support for non-solid fill modes
1109 features.fillModeNonSolid = false;
1110 // The sacrificial device object
1111 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1112
1113 VkRenderpassObj render_pass(&test_device);
1114
1115 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1116 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1117 pipeline_layout_ci.setLayoutCount = 0;
1118 pipeline_layout_ci.pSetLayouts = NULL;
1119
1120 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001121 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001122 ASSERT_VK_SUCCESS(err);
1123
1124 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1125 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1126 rs_ci.pNext = nullptr;
1127 rs_ci.lineWidth = 1.0f;
1128 rs_ci.rasterizerDiscardEnable = true;
1129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001130 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1131 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001132
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001133 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001134 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1135 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001136 {
1137 VkPipelineObj pipe(&test_device);
1138 pipe.AddShader(&vs);
1139 pipe.AddShader(&fs);
1140 pipe.AddColorAttachment();
1141 // Introduce failure by setting unsupported polygon mode
1142 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1143 pipe.SetRasterization(&rs_ci);
1144 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1145 }
1146 m_errorMonitor->VerifyFound();
1147
1148 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1150 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001151 {
1152 VkPipelineObj pipe(&test_device);
1153 pipe.AddShader(&vs);
1154 pipe.AddShader(&fs);
1155 pipe.AddColorAttachment();
1156 // Introduce failure by setting unsupported polygon mode
1157 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1158 pipe.SetRasterization(&rs_ci);
1159 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1160 }
1161 m_errorMonitor->VerifyFound();
1162
Cortd889ff92016-07-27 09:51:27 -07001163 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1164}
1165
Dustin Gravesffa90fa2016-05-06 11:20:38 -06001166#endif // PARAMETER_VALIDATION_TESTS
1167
Tobin Ehlis0788f522015-05-26 16:11:58 -06001168#if MEM_TRACKER_TESTS
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001169#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001170TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001171{
1172 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001173 VkFenceCreateInfo fenceInfo = {};
1174 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1175 fenceInfo.pNext = NULL;
1176 fenceInfo.flags = 0;
1177
Mike Weiblencce7ec72016-10-17 19:33:05 -06001178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001179
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001180 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001181
1182 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1183 vk_testing::Buffer buffer;
1184 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001185
Tony Barbourfe3351b2015-07-28 10:17:20 -06001186 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001187 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001188 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001189
1190 testFence.init(*m_device, fenceInfo);
1191
1192 // Bypass framework since it does the waits automatically
1193 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001194 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001195 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1196 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001197 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001198 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001199 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001200 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001201 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001202 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001203 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001204
1205 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206 ASSERT_VK_SUCCESS( err );
1207
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001208 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001209 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001210
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001211 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001212}
1213
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001214TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001215{
1216 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001217 VkFenceCreateInfo fenceInfo = {};
1218 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1219 fenceInfo.pNext = NULL;
1220 fenceInfo.flags = 0;
1221
Mike Weiblencce7ec72016-10-17 19:33:05 -06001222 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001223
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001224 ASSERT_NO_FATAL_FAILURE(InitState());
1225 ASSERT_NO_FATAL_FAILURE(InitViewport());
1226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1227
Tony Barbourfe3351b2015-07-28 10:17:20 -06001228 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001229 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001230 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001231
1232 testFence.init(*m_device, fenceInfo);
1233
1234 // Bypass framework since it does the waits automatically
1235 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001237 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1238 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001239 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001240 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001241 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001242 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001243 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001244 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001245 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001246
1247 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001248 ASSERT_VK_SUCCESS( err );
1249
Jon Ashburnf19916e2016-01-11 13:12:43 -07001250 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001251 VkCommandBufferBeginInfo info = {};
1252 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1253 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001254 info.renderPass = VK_NULL_HANDLE;
1255 info.subpass = 0;
1256 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001257 info.occlusionQueryEnable = VK_FALSE;
1258 info.queryFlags = 0;
1259 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001260
1261 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001262 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001263
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001264 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001265}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001266#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001267
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001268TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1269 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1270
1271 ASSERT_NO_FATAL_FAILURE(InitState());
1272
1273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1274 VkBuffer buffer;
1275 VkBufferCreateInfo buf_info = {};
1276 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1277 buf_info.pNext = NULL;
1278 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1279 buf_info.size = 2048;
1280 buf_info.queueFamilyIndexCount = 0;
1281 buf_info.pQueueFamilyIndices = NULL;
1282 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1283 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1284 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1285 m_errorMonitor->VerifyFound();
1286
1287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1288 VkImage image;
1289 VkImageCreateInfo image_create_info = {};
1290 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1291 image_create_info.pNext = NULL;
1292 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1293 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1294 image_create_info.extent.width = 512;
1295 image_create_info.extent.height = 64;
1296 image_create_info.extent.depth = 1;
1297 image_create_info.mipLevels = 1;
1298 image_create_info.arrayLayers = 1;
1299 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1300 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1301 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1302 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1303 image_create_info.queueFamilyIndexCount = 0;
1304 image_create_info.pQueueFamilyIndices = NULL;
1305 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1306 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1307 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1308 m_errorMonitor->VerifyFound();
1309}
1310
Tobin Ehlisf11be982016-05-11 13:52:53 -06001311TEST_F(VkLayerTest, InvalidMemoryAliasing) {
1312 TEST_DESCRIPTION("Create a buffer and image, allocate memory, and bind the "
1313 "buffer and image to memory such that they will alias.");
1314 VkResult err;
1315 bool pass;
1316 ASSERT_NO_FATAL_FAILURE(InitState());
1317
Tobin Ehlis077ded32016-05-12 17:39:13 -06001318 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001319 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001320 VkImage image2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001321 VkDeviceMemory mem; // buffer will be bound first
1322 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001323 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001324 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001325
1326 VkBufferCreateInfo buf_info = {};
1327 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1328 buf_info.pNext = NULL;
1329 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1330 buf_info.size = 256;
1331 buf_info.queueFamilyIndexCount = 0;
1332 buf_info.pQueueFamilyIndices = NULL;
1333 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1334 buf_info.flags = 0;
1335 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1336 ASSERT_VK_SUCCESS(err);
1337
Tobin Ehlis077ded32016-05-12 17:39:13 -06001338 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001339
1340 VkImageCreateInfo image_create_info = {};
1341 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1342 image_create_info.pNext = NULL;
1343 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1344 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1345 image_create_info.extent.width = 64;
1346 image_create_info.extent.height = 64;
1347 image_create_info.extent.depth = 1;
1348 image_create_info.mipLevels = 1;
1349 image_create_info.arrayLayers = 1;
1350 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001351 // Image tiling must be optimal to trigger error when aliasing linear buffer
1352 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001353 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1354 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1355 image_create_info.queueFamilyIndexCount = 0;
1356 image_create_info.pQueueFamilyIndices = NULL;
1357 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1358 image_create_info.flags = 0;
1359
Tobin Ehlisf11be982016-05-11 13:52:53 -06001360 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1361 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001362 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1363 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001364
Tobin Ehlis077ded32016-05-12 17:39:13 -06001365 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1366
1367 VkMemoryAllocateInfo alloc_info = {};
1368 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1369 alloc_info.pNext = NULL;
1370 alloc_info.memoryTypeIndex = 0;
1371 // Ensure memory is big enough for both bindings
1372 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001373 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1374 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001375 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001376 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001377 vkDestroyImage(m_device->device(), image, NULL);
1378 return;
1379 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001380 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1381 ASSERT_VK_SUCCESS(err);
1382 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1383 ASSERT_VK_SUCCESS(err);
1384
Rene Lindsayd14f5572016-12-16 14:57:18 -07001385 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1386
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001388 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001389 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1390 m_errorMonitor->VerifyFound();
1391
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001392 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001393 // aliasing buffer2
1394 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1395 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001396 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1397 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001398 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001399 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001401 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001402 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001403 m_errorMonitor->VerifyFound();
1404
1405 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001406 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001407 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001408 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001409 vkFreeMemory(m_device->device(), mem, NULL);
1410 vkFreeMemory(m_device->device(), mem_img, NULL);
1411}
1412
Tobin Ehlis35372522016-05-12 08:32:31 -06001413TEST_F(VkLayerTest, InvalidMemoryMapping) {
1414 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1415 VkResult err;
1416 bool pass;
1417 ASSERT_NO_FATAL_FAILURE(InitState());
1418
1419 VkBuffer buffer;
1420 VkDeviceMemory mem;
1421 VkMemoryRequirements mem_reqs;
1422
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001423 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1424
Tobin Ehlis35372522016-05-12 08:32:31 -06001425 VkBufferCreateInfo buf_info = {};
1426 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1427 buf_info.pNext = NULL;
1428 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1429 buf_info.size = 256;
1430 buf_info.queueFamilyIndexCount = 0;
1431 buf_info.pQueueFamilyIndices = NULL;
1432 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1433 buf_info.flags = 0;
1434 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1435 ASSERT_VK_SUCCESS(err);
1436
1437 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1438 VkMemoryAllocateInfo alloc_info = {};
1439 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1440 alloc_info.pNext = NULL;
1441 alloc_info.memoryTypeIndex = 0;
1442
1443 // Ensure memory is big enough for both bindings
1444 static const VkDeviceSize allocation_size = 0x10000;
1445 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001446 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 -06001447 if (!pass) {
1448 vkDestroyBuffer(m_device->device(), buffer, NULL);
1449 return;
1450 }
1451 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1452 ASSERT_VK_SUCCESS(err);
1453
1454 uint8_t *pData;
1455 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001456 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 -06001457 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1458 m_errorMonitor->VerifyFound();
1459 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001460 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001461 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1463 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1464 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001465 m_errorMonitor->VerifyFound();
1466
1467 // Unmap the memory to avoid re-map error
1468 vkUnmapMemory(m_device->device(), mem);
1469 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1471 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1472 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001473 m_errorMonitor->VerifyFound();
1474 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1476 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001477 m_errorMonitor->VerifyFound();
1478 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001480 vkUnmapMemory(m_device->device(), mem);
1481 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001482
Tobin Ehlis35372522016-05-12 08:32:31 -06001483 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001484 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001485 ASSERT_VK_SUCCESS(err);
1486 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001487 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001488 mmr.memory = mem;
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001489 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001491 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1492 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001493
Tobin Ehlis35372522016-05-12 08:32:31 -06001494 // Now flush range that oversteps mapped range
1495 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001496 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001497 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001498 mmr.offset = atom_size;
1499 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1501 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1502 m_errorMonitor->VerifyFound();
1503
1504 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1505 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001506 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001507 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001508 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001509 mmr.size = VK_WHOLE_SIZE;
1510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001511 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1512 m_errorMonitor->VerifyFound();
1513
Tony Barboure3975eb2016-12-15 14:52:44 -07001514#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001515 // Some platforms have an atomsize of 1 which makes the test meaningless
1516 if (atom_size > 3) {
1517 // Now with an offset NOT a multiple of the device limit
1518 vkUnmapMemory(m_device->device(), mem);
1519 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1520 ASSERT_VK_SUCCESS(err);
1521 mmr.offset = 3; // Not a multiple of atom_size
1522 mmr.size = VK_WHOLE_SIZE;
1523 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1524 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1525 m_errorMonitor->VerifyFound();
1526
1527 // Now with a size NOT a multiple of the device limit
1528 vkUnmapMemory(m_device->device(), mem);
1529 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1530 ASSERT_VK_SUCCESS(err);
1531 mmr.offset = atom_size;
1532 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1534 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1535 m_errorMonitor->VerifyFound();
1536 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001537#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001538 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1539 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001540 if (!pass) {
1541 vkFreeMemory(m_device->device(), mem, NULL);
1542 vkDestroyBuffer(m_device->device(), buffer, NULL);
1543 return;
1544 }
1545 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1546 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1547
1548 vkDestroyBuffer(m_device->device(), buffer, NULL);
1549 vkFreeMemory(m_device->device(), mem, NULL);
1550}
1551
Chris Forbes09368e42016-10-13 11:59:22 +13001552#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001553TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1554 VkResult err;
1555 bool pass;
1556
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001557 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1558 // following declaration (which is temporarily being moved below):
1559 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001560 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001561 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001562 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001563 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001564 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001565 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001566
1567 ASSERT_NO_FATAL_FAILURE(InitState());
1568
Ian Elliott3f06ce52016-04-29 14:46:21 -06001569#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1570#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1571 // Use the functions from the VK_KHR_android_surface extension without
1572 // enabling that extension:
1573
1574 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001575 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1577 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001578 pass = (err != VK_SUCCESS);
1579 ASSERT_TRUE(pass);
1580 m_errorMonitor->VerifyFound();
1581#endif // VK_USE_PLATFORM_ANDROID_KHR
1582
Ian Elliott3f06ce52016-04-29 14:46:21 -06001583#if defined(VK_USE_PLATFORM_MIR_KHR)
1584 // Use the functions from the VK_KHR_mir_surface extension without enabling
1585 // that extension:
1586
1587 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001588 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001590 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1591 pass = (err != VK_SUCCESS);
1592 ASSERT_TRUE(pass);
1593 m_errorMonitor->VerifyFound();
1594
1595 // Tell whether an mir_connection supports presentation:
1596 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1598 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001599 m_errorMonitor->VerifyFound();
1600#endif // VK_USE_PLATFORM_MIR_KHR
1601
Ian Elliott3f06ce52016-04-29 14:46:21 -06001602#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1603 // Use the functions from the VK_KHR_wayland_surface extension without
1604 // enabling that extension:
1605
1606 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001607 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1609 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001610 pass = (err != VK_SUCCESS);
1611 ASSERT_TRUE(pass);
1612 m_errorMonitor->VerifyFound();
1613
1614 // Tell whether an wayland_display supports presentation:
1615 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1617 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001618 m_errorMonitor->VerifyFound();
1619#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott489eec02016-05-05 14:12:44 -06001620#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001621
Ian Elliott3f06ce52016-04-29 14:46:21 -06001622#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001623 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1624 // TO NON-LINUX PLATFORMS:
1625 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001626 // Use the functions from the VK_KHR_win32_surface extension without
1627 // enabling that extension:
1628
1629 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001630 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1632 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001633 pass = (err != VK_SUCCESS);
1634 ASSERT_TRUE(pass);
1635 m_errorMonitor->VerifyFound();
1636
1637 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001639 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001640 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001641// Set this (for now, until all platforms are supported and tested):
1642#define NEED_TO_TEST_THIS_ON_PLATFORM
1643#endif // VK_USE_PLATFORM_WIN32_KHR
Tony Barbour2e7bd402016-11-14 14:46:33 -07001644#if defined(VK_USE_PLATFORM_XCB_KHR) || defined (VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001645 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1646 // TO NON-LINUX PLATFORMS:
1647 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001648#endif
1649#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001650 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1651 // that extension:
1652
1653 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001654 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001656 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1657 pass = (err != VK_SUCCESS);
1658 ASSERT_TRUE(pass);
1659 m_errorMonitor->VerifyFound();
1660
1661 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001662 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001663 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1665 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001666 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001667// Set this (for now, until all platforms are supported and tested):
1668#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001669#endif // VK_USE_PLATFORM_XCB_KHR
1670
Ian Elliott12630812016-04-29 14:35:43 -06001671#if defined(VK_USE_PLATFORM_XLIB_KHR)
1672 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1673 // that extension:
1674
1675 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001676 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001678 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1679 pass = (err != VK_SUCCESS);
1680 ASSERT_TRUE(pass);
1681 m_errorMonitor->VerifyFound();
1682
1683 // Tell whether an Xlib VisualID supports presentation:
1684 Display *dpy = NULL;
1685 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001687 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1688 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001689// Set this (for now, until all platforms are supported and tested):
1690#define NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott12630812016-04-29 14:35:43 -06001691#endif // VK_USE_PLATFORM_XLIB_KHR
1692
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001693// Use the functions from the VK_KHR_surface extension without enabling
1694// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001695
Ian Elliott489eec02016-05-05 14:12:44 -06001696#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001697 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001699 vkDestroySurfaceKHR(instance(), surface, NULL);
1700 m_errorMonitor->VerifyFound();
1701
1702 // Check if surface supports presentation:
1703 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001705 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1706 pass = (err != VK_SUCCESS);
1707 ASSERT_TRUE(pass);
1708 m_errorMonitor->VerifyFound();
1709
1710 // Check surface capabilities:
1711 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1713 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001714 pass = (err != VK_SUCCESS);
1715 ASSERT_TRUE(pass);
1716 m_errorMonitor->VerifyFound();
1717
1718 // Check surface formats:
1719 uint32_t format_count = 0;
1720 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1722 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001723 pass = (err != VK_SUCCESS);
1724 ASSERT_TRUE(pass);
1725 m_errorMonitor->VerifyFound();
1726
1727 // Check surface present modes:
1728 uint32_t present_mode_count = 0;
1729 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1731 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001732 pass = (err != VK_SUCCESS);
1733 ASSERT_TRUE(pass);
1734 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001735#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001736
Ian Elliott1c32c772016-04-28 14:47:13 -06001737 // Use the functions from the VK_KHR_swapchain extension without enabling
1738 // that extension:
1739
1740 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001742 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1743 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001744 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001745 pass = (err != VK_SUCCESS);
1746 ASSERT_TRUE(pass);
1747 m_errorMonitor->VerifyFound();
1748
1749 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1751 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 pass = (err != VK_SUCCESS);
1753 ASSERT_TRUE(pass);
1754 m_errorMonitor->VerifyFound();
1755
Chris Forbeseb7d5502016-09-13 18:19:21 +12001756 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1757 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1758 VkFence fence;
1759 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1760
Ian Elliott1c32c772016-04-28 14:47:13 -06001761 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001763 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001764 pass = (err != VK_SUCCESS);
1765 ASSERT_TRUE(pass);
1766 m_errorMonitor->VerifyFound();
1767
Chris Forbeseb7d5502016-09-13 18:19:21 +12001768 vkDestroyFence(m_device->device(), fence, nullptr);
1769
Ian Elliott1c32c772016-04-28 14:47:13 -06001770 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001771 //
1772 // NOTE: Currently can't test this because a real swapchain is needed (as
1773 // opposed to the fake one we created) in order for the layer to lookup the
1774 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001775
1776 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001778 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1779 m_errorMonitor->VerifyFound();
1780}
Chris Forbes09368e42016-10-13 11:59:22 +13001781#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001782
Karl Schultz6addd812016-02-02 17:17:23 -07001783TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1784 VkResult err;
1785 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001786
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1788 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001789
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001790 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001791
1792 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001793 VkImage image;
1794 VkDeviceMemory mem;
1795 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001796
Karl Schultz6addd812016-02-02 17:17:23 -07001797 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1798 const int32_t tex_width = 32;
1799 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001800
Tony Barboureb254902015-07-15 12:50:33 -06001801 VkImageCreateInfo image_create_info = {};
1802 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001803 image_create_info.pNext = NULL;
1804 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1805 image_create_info.format = tex_format;
1806 image_create_info.extent.width = tex_width;
1807 image_create_info.extent.height = tex_height;
1808 image_create_info.extent.depth = 1;
1809 image_create_info.mipLevels = 1;
1810 image_create_info.arrayLayers = 1;
1811 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1812 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1813 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1814 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001815 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001816
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001817 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001818 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001819 mem_alloc.pNext = NULL;
1820 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001821
Chia-I Wuf7458c52015-10-26 21:10:41 +08001822 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001823 ASSERT_VK_SUCCESS(err);
1824
Karl Schultz6addd812016-02-02 17:17:23 -07001825 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001826
Mark Lobodzinski23065352015-05-29 09:32:35 -05001827 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001828
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001829 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Karl Schultz6addd812016-02-02 17:17:23 -07001830 if (!pass) { // If we can't find any unmappable memory this test doesn't
1831 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001832 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001833 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001834 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001835
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001836 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001837 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001838 ASSERT_VK_SUCCESS(err);
1839
1840 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06001841 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001842 ASSERT_VK_SUCCESS(err);
1843
1844 // Map memory as if to initialize the image
1845 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001846 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001847
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001848 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001849
Chia-I Wuf7458c52015-10-26 21:10:41 +08001850 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06001851 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001852}
1853
Karl Schultz6addd812016-02-02 17:17:23 -07001854TEST_F(VkLayerTest, RebindMemory) {
1855 VkResult err;
1856 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001857
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001859
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001860 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001861
1862 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001863 VkImage image;
1864 VkDeviceMemory mem1;
1865 VkDeviceMemory mem2;
1866 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001867
Karl Schultz6addd812016-02-02 17:17:23 -07001868 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1869 const int32_t tex_width = 32;
1870 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001871
Tony Barboureb254902015-07-15 12:50:33 -06001872 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001873 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1874 image_create_info.pNext = NULL;
1875 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1876 image_create_info.format = tex_format;
1877 image_create_info.extent.width = tex_width;
1878 image_create_info.extent.height = tex_height;
1879 image_create_info.extent.depth = 1;
1880 image_create_info.mipLevels = 1;
1881 image_create_info.arrayLayers = 1;
1882 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1883 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1884 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1885 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001886
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001887 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07001888 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1889 mem_alloc.pNext = NULL;
1890 mem_alloc.allocationSize = 0;
1891 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06001892
Karl Schultz6addd812016-02-02 17:17:23 -07001893 // Introduce failure, do NOT set memProps to
1894 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06001895 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08001896 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001897 ASSERT_VK_SUCCESS(err);
1898
Karl Schultz6addd812016-02-02 17:17:23 -07001899 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001900
1901 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001902 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06001903 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001904
1905 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001906 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001907 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001908 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001909 ASSERT_VK_SUCCESS(err);
1910
1911 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06001912 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001913 ASSERT_VK_SUCCESS(err);
1914
Karl Schultz6addd812016-02-02 17:17:23 -07001915 // Introduce validation failure, try to bind a different memory object to
1916 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06001917 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001918
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001919 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06001920
Chia-I Wuf7458c52015-10-26 21:10:41 +08001921 vkDestroyImage(m_device->device(), image, NULL);
1922 vkFreeMemory(m_device->device(), mem1, NULL);
1923 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001924}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001925
Karl Schultz6addd812016-02-02 17:17:23 -07001926TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001927 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001928
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "submitted in SIGNALED state. Fences "
1930 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001931
1932 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06001933 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1934 fenceInfo.pNext = NULL;
1935 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06001936
Tony Barbour300a6082015-04-07 13:44:53 -06001937 ASSERT_NO_FATAL_FAILURE(InitState());
1938 ASSERT_NO_FATAL_FAILURE(InitViewport());
1939 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1940
Tony Barbour552f6c02016-12-21 14:34:07 -07001941 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001942 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07001943 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06001944
1945 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001946
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001947 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001948 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1949 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001950 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001951 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001952 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001953 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001954 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001955 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001956 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001957
1958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07001959 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001960
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001961 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06001962}
Chris Forbes4e44c912016-06-16 10:20:00 +12001963
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001964TEST_F(VkLayerTest, InvalidUsageBits) {
1965 TEST_DESCRIPTION("Specify wrong usage for image then create conflicting view of image "
1966 "Initialize buffer with wrong usage then perform copy expecting errors "
1967 "from both the image and the buffer (2 calls)");
1968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06001969
1970 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001971
1972 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
1973
Tony Barbourf92621a2016-05-02 14:28:12 -06001974 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06001975 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001976 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06001977 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06001978
Tony Barbourf92621a2016-05-02 14:28:12 -06001979 VkImageView dsv;
1980 VkImageViewCreateInfo dsvci = {};
1981 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1982 dsvci.image = image.handle();
1983 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13001984 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06001985 dsvci.subresourceRange.layerCount = 1;
1986 dsvci.subresourceRange.baseMipLevel = 0;
1987 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001988 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06001989
Tony Barbourf92621a2016-05-02 14:28:12 -06001990 // Create a view with depth / stencil aspect for image with different usage
1991 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001992
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001993 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06001994
1995 // Initialize buffer with TRANSFER_DST usage
1996 vk_testing::Buffer buffer;
1997 VkMemoryPropertyFlags reqs = 0;
1998 buffer.init_as_dst(*m_device, 128 * 128, reqs);
1999 VkBufferImageCopy region = {};
2000 region.bufferRowLength = 128;
2001 region.bufferImageHeight = 128;
2002 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2003 region.imageSubresource.layerCount = 1;
2004 region.imageExtent.height = 16;
2005 region.imageExtent.width = 16;
2006 region.imageExtent.depth = 1;
2007
Tony Barbourf92621a2016-05-02 14:28:12 -06002008 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2009 // TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002010 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002011
Chris Forbesda581202016-10-06 18:25:26 +13002012 // two separate errors from this call:
2013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2015
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002016 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2017 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002018 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002019}
Tony Barbour75d79f02016-08-30 09:39:07 -06002020
Tony Barbour75d79f02016-08-30 09:39:07 -06002021
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002022#endif // MEM_TRACKER_TESTS
2023
Tobin Ehlis4bf96d12015-06-25 11:58:41 -06002024#if OBJ_TRACKER_TESTS
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002025
2026TEST_F(VkLayerTest, LeakAnObject) {
2027 VkResult err;
2028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002029 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002030
2031 // Note that we have to create a new device since destroying the
2032 // framework's device causes Teardown() to fail and just calling Teardown
2033 // will destroy the errorMonitor.
2034
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002036
2037 ASSERT_NO_FATAL_FAILURE(InitState());
2038
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002039 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002040 std::vector<VkDeviceQueueCreateInfo> queue_info;
2041 queue_info.reserve(queue_props.size());
2042 std::vector<std::vector<float>> queue_priorities;
2043 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2044 VkDeviceQueueCreateInfo qi = {};
2045 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2046 qi.pNext = NULL;
2047 qi.queueFamilyIndex = i;
2048 qi.queueCount = queue_props[i].queueCount;
2049 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2050 qi.pQueuePriorities = queue_priorities[i].data();
2051 queue_info.push_back(qi);
2052 }
2053
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002054 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002055
2056 // The sacrificial device object
2057 VkDevice testDevice;
2058 VkDeviceCreateInfo device_create_info = {};
2059 auto features = m_device->phy().features();
2060 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2061 device_create_info.pNext = NULL;
2062 device_create_info.queueCreateInfoCount = queue_info.size();
2063 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002064 device_create_info.enabledLayerCount = 0;
2065 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002066 device_create_info.pEnabledFeatures = &features;
2067 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2068 ASSERT_VK_SUCCESS(err);
2069
2070 VkFence fence;
2071 VkFenceCreateInfo fence_create_info = {};
2072 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2073 fence_create_info.pNext = NULL;
2074 fence_create_info.flags = 0;
2075 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2076 ASSERT_VK_SUCCESS(err);
2077
2078 // Induce failure by not calling vkDestroyFence
2079 vkDestroyDevice(testDevice, NULL);
2080 m_errorMonitor->VerifyFound();
2081}
2082
2083TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
2084
2085 TEST_DESCRIPTION("Allocate command buffers from one command pool and "
2086 "attempt to delete them from another.");
2087
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002089
Cody Northropc31a84f2016-08-22 10:41:47 -06002090 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002091 VkCommandPool command_pool_one;
2092 VkCommandPool command_pool_two;
2093
2094 VkCommandPoolCreateInfo pool_create_info{};
2095 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2096 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2097 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2098
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002099 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002100
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002101 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002102
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002103 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002104 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002105 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002106 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002107 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002108 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002109 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002110
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002111 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002112
2113 m_errorMonitor->VerifyFound();
2114
2115 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2116 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2117}
2118
2119TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2120 VkResult err;
2121
2122 TEST_DESCRIPTION("Allocate descriptor sets from one DS pool and "
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002123 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002124
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002126
2127 ASSERT_NO_FATAL_FAILURE(InitState());
2128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2129
2130 VkDescriptorPoolSize ds_type_count = {};
2131 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2132 ds_type_count.descriptorCount = 1;
2133
2134 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2135 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2136 ds_pool_ci.pNext = NULL;
2137 ds_pool_ci.flags = 0;
2138 ds_pool_ci.maxSets = 1;
2139 ds_pool_ci.poolSizeCount = 1;
2140 ds_pool_ci.pPoolSizes = &ds_type_count;
2141
2142 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002143 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002144 ASSERT_VK_SUCCESS(err);
2145
2146 // Create a second descriptor pool
2147 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002148 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002149 ASSERT_VK_SUCCESS(err);
2150
2151 VkDescriptorSetLayoutBinding dsl_binding = {};
2152 dsl_binding.binding = 0;
2153 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2154 dsl_binding.descriptorCount = 1;
2155 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2156 dsl_binding.pImmutableSamplers = NULL;
2157
2158 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2159 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2160 ds_layout_ci.pNext = NULL;
2161 ds_layout_ci.bindingCount = 1;
2162 ds_layout_ci.pBindings = &dsl_binding;
2163
2164 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002165 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002166 ASSERT_VK_SUCCESS(err);
2167
2168 VkDescriptorSet descriptorSet;
2169 VkDescriptorSetAllocateInfo alloc_info = {};
2170 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2171 alloc_info.descriptorSetCount = 1;
2172 alloc_info.descriptorPool = ds_pool_one;
2173 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002174 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002175 ASSERT_VK_SUCCESS(err);
2176
2177 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2178
2179 m_errorMonitor->VerifyFound();
2180
2181 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2182 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2183 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2184}
2185
2186TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002188
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002189 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002190
2191 ASSERT_NO_FATAL_FAILURE(InitState());
2192
2193 // Pass bogus handle into GetImageMemoryRequirements
2194 VkMemoryRequirements mem_reqs;
2195 uint64_t fakeImageHandle = 0xCADECADE;
2196 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2197
2198 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2199
2200 m_errorMonitor->VerifyFound();
2201}
2202
Karl Schultz6addd812016-02-02 17:17:23 -07002203TEST_F(VkLayerTest, PipelineNotBound) {
2204 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002205
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002206 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002207
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002209
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002210 ASSERT_NO_FATAL_FAILURE(InitState());
2211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002212
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002213 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002214 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2215 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002216
2217 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002218 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2219 ds_pool_ci.pNext = NULL;
2220 ds_pool_ci.maxSets = 1;
2221 ds_pool_ci.poolSizeCount = 1;
2222 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002223
2224 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002225 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002226 ASSERT_VK_SUCCESS(err);
2227
2228 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002229 dsl_binding.binding = 0;
2230 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2231 dsl_binding.descriptorCount = 1;
2232 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2233 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002234
2235 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002236 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2237 ds_layout_ci.pNext = NULL;
2238 ds_layout_ci.bindingCount = 1;
2239 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002240
2241 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002242 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002243 ASSERT_VK_SUCCESS(err);
2244
2245 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002246 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002247 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002248 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002249 alloc_info.descriptorPool = ds_pool;
2250 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002251 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002252 ASSERT_VK_SUCCESS(err);
2253
2254 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002255 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2256 pipeline_layout_ci.pNext = NULL;
2257 pipeline_layout_ci.setLayoutCount = 1;
2258 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002259
2260 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002261 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002262 ASSERT_VK_SUCCESS(err);
2263
Mark Youngad779052016-01-06 14:26:04 -07002264 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002265
Tony Barbour552f6c02016-12-21 14:34:07 -07002266 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002267 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002268
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002269 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002270
Chia-I Wuf7458c52015-10-26 21:10:41 +08002271 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2272 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2273 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002274}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002275
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002276TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2277 VkResult err;
2278
2279 TEST_DESCRIPTION("Test validation check for an invalid memory type index "
2280 "during bind[Buffer|Image]Memory time");
2281
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002282 ASSERT_NO_FATAL_FAILURE(InitState());
2283
2284 // Create an image, allocate memory, set a bad typeIndex and then try to
2285 // bind it
2286 VkImage image;
2287 VkDeviceMemory mem;
2288 VkMemoryRequirements mem_reqs;
2289 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2290 const int32_t tex_width = 32;
2291 const int32_t tex_height = 32;
2292
2293 VkImageCreateInfo image_create_info = {};
2294 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2295 image_create_info.pNext = NULL;
2296 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2297 image_create_info.format = tex_format;
2298 image_create_info.extent.width = tex_width;
2299 image_create_info.extent.height = tex_height;
2300 image_create_info.extent.depth = 1;
2301 image_create_info.mipLevels = 1;
2302 image_create_info.arrayLayers = 1;
2303 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2304 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2305 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2306 image_create_info.flags = 0;
2307
2308 VkMemoryAllocateInfo mem_alloc = {};
2309 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2310 mem_alloc.pNext = NULL;
2311 mem_alloc.allocationSize = 0;
2312 mem_alloc.memoryTypeIndex = 0;
2313
2314 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2315 ASSERT_VK_SUCCESS(err);
2316
2317 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2318 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002319
2320 // Introduce Failure, select invalid TypeIndex
2321 VkPhysicalDeviceMemoryProperties memory_info;
2322
2323 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2324 unsigned int i;
2325 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2326 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2327 mem_alloc.memoryTypeIndex = i;
2328 break;
2329 }
2330 }
2331 if (i >= memory_info.memoryTypeCount) {
2332 printf("No invalid memory type index could be found; skipped.\n");
2333 vkDestroyImage(m_device->device(), image, NULL);
2334 return;
2335 }
2336
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002337 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 -06002338
2339 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2340 ASSERT_VK_SUCCESS(err);
2341
2342 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2343 (void)err;
2344
2345 m_errorMonitor->VerifyFound();
2346
2347 vkDestroyImage(m_device->device(), image, NULL);
2348 vkFreeMemory(m_device->device(), mem, NULL);
2349}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002350
Karl Schultz6addd812016-02-02 17:17:23 -07002351TEST_F(VkLayerTest, BindInvalidMemory) {
2352 VkResult err;
2353 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002354
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002356
Tobin Ehlisec598302015-09-15 15:02:17 -06002357 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002358
2359 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002360 VkImage image;
2361 VkDeviceMemory mem;
2362 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002363
Karl Schultz6addd812016-02-02 17:17:23 -07002364 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2365 const int32_t tex_width = 32;
2366 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002367
2368 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002369 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2370 image_create_info.pNext = NULL;
2371 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2372 image_create_info.format = tex_format;
2373 image_create_info.extent.width = tex_width;
2374 image_create_info.extent.height = tex_height;
2375 image_create_info.extent.depth = 1;
2376 image_create_info.mipLevels = 1;
2377 image_create_info.arrayLayers = 1;
2378 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2379 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2380 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2381 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002382
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002383 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002384 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2385 mem_alloc.pNext = NULL;
2386 mem_alloc.allocationSize = 0;
2387 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002388
Chia-I Wuf7458c52015-10-26 21:10:41 +08002389 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002390 ASSERT_VK_SUCCESS(err);
2391
Karl Schultz6addd812016-02-02 17:17:23 -07002392 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002393
2394 mem_alloc.allocationSize = mem_reqs.size;
2395
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002396 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002397 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002398
2399 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002400 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002401 ASSERT_VK_SUCCESS(err);
2402
2403 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002404 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002405
2406 // Try to bind free memory that has been freed
2407 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2408 // This may very well return an error.
2409 (void)err;
2410
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002411 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002412
Chia-I Wuf7458c52015-10-26 21:10:41 +08002413 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002414}
2415
Karl Schultz6addd812016-02-02 17:17:23 -07002416TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2417 VkResult err;
2418 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002419
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002421
Tobin Ehlisec598302015-09-15 15:02:17 -06002422 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002423
Karl Schultz6addd812016-02-02 17:17:23 -07002424 // Create an image object, allocate memory, destroy the object and then try
2425 // to bind it
2426 VkImage image;
2427 VkDeviceMemory mem;
2428 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002429
Karl Schultz6addd812016-02-02 17:17:23 -07002430 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2431 const int32_t tex_width = 32;
2432 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002433
2434 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002435 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2436 image_create_info.pNext = NULL;
2437 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2438 image_create_info.format = tex_format;
2439 image_create_info.extent.width = tex_width;
2440 image_create_info.extent.height = tex_height;
2441 image_create_info.extent.depth = 1;
2442 image_create_info.mipLevels = 1;
2443 image_create_info.arrayLayers = 1;
2444 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2445 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2446 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2447 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002448
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002449 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002450 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2451 mem_alloc.pNext = NULL;
2452 mem_alloc.allocationSize = 0;
2453 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002454
Chia-I Wuf7458c52015-10-26 21:10:41 +08002455 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002456 ASSERT_VK_SUCCESS(err);
2457
Karl Schultz6addd812016-02-02 17:17:23 -07002458 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002459
2460 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002461 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002462 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002463
2464 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002465 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002466 ASSERT_VK_SUCCESS(err);
2467
2468 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002469 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002470 ASSERT_VK_SUCCESS(err);
2471
2472 // Now Try to bind memory to this destroyed object
2473 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2474 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002475 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002476
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002477 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002478
Chia-I Wuf7458c52015-10-26 21:10:41 +08002479 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002480}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002481
Mark Lobodzinski209b5292015-09-17 09:44:05 -06002482#endif // OBJ_TRACKER_TESTS
2483
Tobin Ehlis0788f522015-05-26 16:11:58 -06002484#if DRAW_STATE_TESTS
Mark Lobodzinskic808d442016-04-14 10:57:23 -06002485
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002486TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2487 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2488
2489 ASSERT_NO_FATAL_FAILURE(InitState());
2490 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2491
2492 VkVertexInputBindingDescription input_binding;
2493 memset(&input_binding, 0, sizeof(input_binding));
2494
2495 VkVertexInputAttributeDescription input_attribs;
2496 memset(&input_attribs, 0, sizeof(input_attribs));
2497
2498 // Pick a really bad format for this purpose and make sure it should fail
2499 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2500 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2501 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2502 printf("Format unsuitable for test; skipped.\n");
2503 return;
2504 }
2505
2506 input_attribs.location = 0;
2507 char const *vsSource = "#version 450\n"
2508 "\n"
2509 "out gl_PerVertex {\n"
2510 " vec4 gl_Position;\n"
2511 "};\n"
2512 "void main(){\n"
2513 " gl_Position = vec4(1);\n"
2514 "}\n";
2515 char const *fsSource = "#version 450\n"
2516 "\n"
2517 "layout(location=0) out vec4 color;\n"
2518 "void main(){\n"
2519 " color = vec4(1);\n"
2520 "}\n";
2521
2522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2523 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2524 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2525
2526 VkPipelineObj pipe(m_device);
2527 pipe.AddColorAttachment();
2528 pipe.AddShader(&vs);
2529 pipe.AddShader(&fs);
2530
2531 pipe.AddVertexInputBindings(&input_binding, 1);
2532 pipe.AddVertexInputAttribs(&input_attribs, 1);
2533
2534 VkDescriptorSetObj descriptorSet(m_device);
2535 descriptorSet.AppendDummy();
2536 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2537
2538 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2539
2540 m_errorMonitor->VerifyFound();
2541}
2542
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002543TEST_F(VkLayerTest, ImageSampleCounts) {
2544
2545 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger "
2546 "validation errors.");
2547 ASSERT_NO_FATAL_FAILURE(InitState());
2548
2549 VkMemoryPropertyFlags reqs = 0;
2550 VkImageCreateInfo image_create_info = {};
2551 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2552 image_create_info.pNext = NULL;
2553 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2554 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2555 image_create_info.extent.width = 256;
2556 image_create_info.extent.height = 256;
2557 image_create_info.extent.depth = 1;
2558 image_create_info.mipLevels = 1;
2559 image_create_info.arrayLayers = 1;
2560 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2561 image_create_info.flags = 0;
2562
2563 VkImageBlit blit_region = {};
2564 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2565 blit_region.srcSubresource.baseArrayLayer = 0;
2566 blit_region.srcSubresource.layerCount = 1;
2567 blit_region.srcSubresource.mipLevel = 0;
2568 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2569 blit_region.dstSubresource.baseArrayLayer = 0;
2570 blit_region.dstSubresource.layerCount = 1;
2571 blit_region.dstSubresource.mipLevel = 0;
2572
2573 // Create two images, the source with sampleCount = 2, and attempt to blit
2574 // between them
2575 {
2576 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002577 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002578 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002579 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002580 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002581 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002582 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002583 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002584 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2586 "of VK_SAMPLE_COUNT_2_BIT but "
2587 "must be VK_SAMPLE_COUNT_1_BIT");
2588 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2589 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002590 m_errorMonitor->VerifyFound();
2591 m_commandBuffer->EndCommandBuffer();
2592 }
2593
2594 // Create two images, the dest with sampleCount = 4, and attempt to blit
2595 // between them
2596 {
2597 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002598 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002599 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002600 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002601 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002602 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002603 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002604 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002605 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2607 "of VK_SAMPLE_COUNT_4_BIT but "
2608 "must be VK_SAMPLE_COUNT_1_BIT");
2609 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2610 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002611 m_errorMonitor->VerifyFound();
2612 m_commandBuffer->EndCommandBuffer();
2613 }
2614
2615 VkBufferImageCopy copy_region = {};
2616 copy_region.bufferRowLength = 128;
2617 copy_region.bufferImageHeight = 128;
2618 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2619 copy_region.imageSubresource.layerCount = 1;
2620 copy_region.imageExtent.height = 64;
2621 copy_region.imageExtent.width = 64;
2622 copy_region.imageExtent.depth = 1;
2623
2624 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2625 // buffer to image
2626 {
2627 vk_testing::Buffer src_buffer;
2628 VkMemoryPropertyFlags reqs = 0;
2629 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2630 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002631 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002632 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002633 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002634 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2636 "of VK_SAMPLE_COUNT_8_BIT but "
2637 "must be VK_SAMPLE_COUNT_1_BIT");
2638 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2639 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002640 m_errorMonitor->VerifyFound();
2641 m_commandBuffer->EndCommandBuffer();
2642 }
2643
2644 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2645 // image to buffer
2646 {
2647 vk_testing::Buffer dst_buffer;
2648 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2649 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002650 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002651 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002652 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002653 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "was created with a sample count "
2655 "of VK_SAMPLE_COUNT_2_BIT but "
2656 "must be VK_SAMPLE_COUNT_1_BIT");
2657 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002658 dst_buffer.handle(), 1, &copy_region);
2659 m_errorMonitor->VerifyFound();
2660 m_commandBuffer->EndCommandBuffer();
2661 }
2662}
2663
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002664TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002665 ASSERT_NO_FATAL_FAILURE(InitState());
2666
2667 VkImageObj src_image(m_device);
2668 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2669 VkImageObj dst_image(m_device);
2670 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2671 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002672 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 -06002673
2674 VkImageBlit blitRegion = {};
2675 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2676 blitRegion.srcSubresource.baseArrayLayer = 0;
2677 blitRegion.srcSubresource.layerCount = 1;
2678 blitRegion.srcSubresource.mipLevel = 0;
2679 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2680 blitRegion.dstSubresource.baseArrayLayer = 0;
2681 blitRegion.dstSubresource.layerCount = 1;
2682 blitRegion.dstSubresource.mipLevel = 0;
2683
Dave Houlton34df4cb2016-12-01 16:43:06 -07002684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
2685
2686 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
2687 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002688
2689 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07002690 m_commandBuffer->BeginCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002691 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(),
2692 dst_image.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2693
2694 m_errorMonitor->VerifyFound();
2695
Dave Houlton34df4cb2016-12-01 16:43:06 -07002696 // Test should generate 2 VU failures
2697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
2698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002699
2700 // Unsigned int vs signed int
2701 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(),
2702 dst_image2.layout(), 1, &blitRegion, VK_FILTER_NEAREST);
2703
Dave Houlton34df4cb2016-12-01 16:43:06 -07002704 // TODO: Note that this only verifies that at least one of the VU enums was found
2705 // 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 -06002706 m_errorMonitor->VerifyFound();
2707
Tony Barbour552f6c02016-12-21 14:34:07 -07002708 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002709}
2710
2711
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002712TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2713 VkResult err;
2714 bool pass;
2715
2716 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2717 ASSERT_NO_FATAL_FAILURE(InitState());
2718
2719 // If w/d/h granularity is 1, test is not meaningful
2720 // TODO: When virtual device limits are available, create a set of limits for this test that
2721 // will always have a granularity of > 1 for w, h, and d
2722 auto index = m_device->graphics_queue_node_index_;
2723 auto queue_family_properties = m_device->phy().queue_properties();
2724
2725 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2726 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2727 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2728 return;
2729 }
2730
2731 // Create two images of different types and try to copy between them
2732 VkImage srcImage;
2733 VkImage dstImage;
2734 VkDeviceMemory srcMem;
2735 VkDeviceMemory destMem;
2736 VkMemoryRequirements memReqs;
2737
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002738 VkImageCreateInfo image_create_info = {};
2739 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2740 image_create_info.pNext = NULL;
2741 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2742 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2743 image_create_info.extent.width = 32;
2744 image_create_info.extent.height = 32;
2745 image_create_info.extent.depth = 1;
2746 image_create_info.mipLevels = 1;
2747 image_create_info.arrayLayers = 4;
2748 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2749 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2750 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2751 image_create_info.flags = 0;
2752
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002753 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002754 ASSERT_VK_SUCCESS(err);
2755
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002756 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002757 ASSERT_VK_SUCCESS(err);
2758
2759 // Allocate memory
2760 VkMemoryAllocateInfo memAlloc = {};
2761 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2762 memAlloc.pNext = NULL;
2763 memAlloc.allocationSize = 0;
2764 memAlloc.memoryTypeIndex = 0;
2765
2766 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2767 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002768 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002769 ASSERT_TRUE(pass);
2770 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2771 ASSERT_VK_SUCCESS(err);
2772
2773 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2774 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002775 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002776 ASSERT_VK_SUCCESS(err);
2777 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2778 ASSERT_VK_SUCCESS(err);
2779
2780 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2781 ASSERT_VK_SUCCESS(err);
2782 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2783 ASSERT_VK_SUCCESS(err);
2784
Tony Barbour552f6c02016-12-21 14:34:07 -07002785 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002786 VkImageCopy copyRegion;
2787 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2788 copyRegion.srcSubresource.mipLevel = 0;
2789 copyRegion.srcSubresource.baseArrayLayer = 0;
2790 copyRegion.srcSubresource.layerCount = 1;
2791 copyRegion.srcOffset.x = 0;
2792 copyRegion.srcOffset.y = 0;
2793 copyRegion.srcOffset.z = 0;
2794 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2795 copyRegion.dstSubresource.mipLevel = 0;
2796 copyRegion.dstSubresource.baseArrayLayer = 0;
2797 copyRegion.dstSubresource.layerCount = 1;
2798 copyRegion.dstOffset.x = 0;
2799 copyRegion.dstOffset.y = 0;
2800 copyRegion.dstOffset.z = 0;
2801 copyRegion.extent.width = 1;
2802 copyRegion.extent.height = 1;
2803 copyRegion.extent.depth = 1;
2804
2805 // Introduce failure by setting srcOffset to a bad granularity value
2806 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2808 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002809 m_errorMonitor->VerifyFound();
2810
2811 // Introduce failure by setting extent to a bad granularity value
2812 copyRegion.srcOffset.y = 0;
2813 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2815 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002816 m_errorMonitor->VerifyFound();
2817
2818 // Now do some buffer/image copies
2819 vk_testing::Buffer buffer;
2820 VkMemoryPropertyFlags reqs = 0;
2821 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2822 VkBufferImageCopy region = {};
2823 region.bufferOffset = 0;
2824 region.bufferRowLength = 3;
2825 region.bufferImageHeight = 128;
2826 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2827 region.imageSubresource.layerCount = 1;
2828 region.imageExtent.height = 16;
2829 region.imageExtent.width = 16;
2830 region.imageExtent.depth = 1;
2831 region.imageOffset.x = 0;
2832 region.imageOffset.y = 0;
2833 region.imageOffset.z = 0;
2834
2835 // Introduce failure by setting bufferRowLength to a bad granularity value
2836 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2838 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2839 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002840 m_errorMonitor->VerifyFound();
2841 region.bufferRowLength = 128;
2842
2843 // Introduce failure by setting bufferOffset to a bad granularity value
2844 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2846 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2847 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002848 m_errorMonitor->VerifyFound();
2849 region.bufferOffset = 0;
2850
2851 // Introduce failure by setting bufferImageHeight to a bad granularity value
2852 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2854 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2855 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002856 m_errorMonitor->VerifyFound();
2857 region.bufferImageHeight = 128;
2858
2859 // Introduce failure by setting imageExtent to a bad granularity value
2860 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2862 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
2863 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002864 m_errorMonitor->VerifyFound();
2865 region.imageExtent.width = 16;
2866
2867 // Introduce failure by setting imageOffset to a bad granularity value
2868 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2870 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2871 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002872 m_errorMonitor->VerifyFound();
2873
Tony Barbour552f6c02016-12-21 14:34:07 -07002874 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002875
2876 vkDestroyImage(m_device->device(), srcImage, NULL);
2877 vkDestroyImage(m_device->device(), dstImage, NULL);
2878 vkFreeMemory(m_device->device(), srcMem, NULL);
2879 vkFreeMemory(m_device->device(), destMem, NULL);
2880}
2881
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002882TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002883 TEST_DESCRIPTION("Submit command buffer created using one queue family and "
2884 "attempt to submit them on a queue created in a different "
2885 "queue family.");
2886
Cody Northropc31a84f2016-08-22 10:41:47 -06002887 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002888 // This test is meaningless unless we have multiple queue families
2889 auto queue_family_properties = m_device->phy().queue_properties();
2890 if (queue_family_properties.size() < 2) {
2891 return;
2892 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002894 // Get safe index of another queue family
2895 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
2896 ASSERT_NO_FATAL_FAILURE(InitState());
2897 // Create a second queue using a different queue family
2898 VkQueue other_queue;
2899 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
2900
2901 // Record an empty cmd buffer
2902 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
2903 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
2904 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
2905 vkEndCommandBuffer(m_commandBuffer->handle());
2906
2907 // And submit on the wrong queue
2908 VkSubmitInfo submit_info = {};
2909 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2910 submit_info.commandBufferCount = 1;
2911 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06002912 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002913
2914 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06002915}
2916
Chris Forbes4c24a922016-11-16 08:59:10 +13002917TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
2918 ASSERT_NO_FATAL_FAILURE(InitState());
2919
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002920 // There are no attachments, but refer to attachment 0.
2921 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13002922 VkSubpassDescription subpasses[] = {
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002923 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr,
2924 nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13002925 };
2926
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002927 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
2928 nullptr,
2929 0,
2930 0,
2931 nullptr,
2932 1,
2933 subpasses,
2934 0,
2935 nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13002936 VkRenderPass rp;
2937
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002938 // "... must be less than the total number of attachments ..."
Chris Forbes4c24a922016-11-16 08:59:10 +13002939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbes2d9b2a82016-11-21 10:45:39 +13002940 VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13002941 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2942 m_errorMonitor->VerifyFound();
2943}
2944
Chris Forbesa58c4522016-09-28 15:19:39 +13002945TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
2946 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
2947 ASSERT_NO_FATAL_FAILURE(InitState());
2948
2949 // A renderpass with two subpasses, both writing the same attachment.
2950 VkAttachmentDescription attach[] = {
2951 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
2952 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2953 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
2954 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
2955 },
2956 };
2957 VkAttachmentReference ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
2958 VkSubpassDescription subpasses[] = {
2959 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2960 1, &ref, nullptr, nullptr, 0, nullptr },
2961 { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
2962 1, &ref, nullptr, nullptr, 0, nullptr },
2963 };
2964 VkSubpassDependency dep = {
2965 0, 1,
2966 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2967 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
2968 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2969 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
2970 VK_DEPENDENCY_BY_REGION_BIT
2971 };
2972 VkRenderPassCreateInfo rpci = {
2973 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
2974 0, 1, attach, 2, subpasses, 1, &dep
2975 };
2976 VkRenderPass rp;
2977 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
2978 ASSERT_VK_SUCCESS(err);
2979
2980 VkImageObj image(m_device);
2981 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM,
2982 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
2983 VK_IMAGE_TILING_OPTIMAL, 0);
2984 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
2985
2986 VkFramebufferCreateInfo fbci = {
2987 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr,
2988 0, rp, 1, &imageView, 32, 32, 1
2989 };
2990 VkFramebuffer fb;
2991 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
2992 ASSERT_VK_SUCCESS(err);
2993
2994 char const *vsSource =
2995 "#version 450\n"
2996 "void main() { gl_Position = vec4(1); }\n";
2997 char const *fsSource =
2998 "#version 450\n"
2999 "layout(location=0) out vec4 color;\n"
3000 "void main() { color = vec4(1); }\n";
3001
3002 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3003 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3004 VkPipelineObj pipe(m_device);
3005 pipe.AddColorAttachment();
3006 pipe.AddShader(&vs);
3007 pipe.AddShader(&fs);
3008 VkViewport view_port = {};
3009 m_viewports.push_back(view_port);
3010 pipe.SetViewport(m_viewports);
3011 VkRect2D rect = {};
3012 m_scissors.push_back(rect);
3013 pipe.SetScissor(m_scissors);
3014
3015 VkPipelineLayoutCreateInfo plci = {
3016 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr,
3017 0, 0, nullptr, 0, nullptr
3018 };
3019 VkPipelineLayout pl;
3020 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3021 ASSERT_VK_SUCCESS(err);
3022 pipe.CreateVKPipeline(pl, rp);
3023
Tony Barbour552f6c02016-12-21 14:34:07 -07003024 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003025
3026 VkRenderPassBeginInfo rpbi = {
3027 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr,
3028 rp, fb, { { 0, 0, }, { 32, 32 } }, 0, nullptr
3029 };
3030
3031 // subtest 1: bind in the wrong subpass
3032 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3033 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3035 "built for subpass 0 but used in subpass 1");
3036 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3037 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3038 m_errorMonitor->VerifyFound();
3039
3040 vkCmdEndRenderPass(m_commandBuffer->handle());
3041
3042 // subtest 2: bind in correct subpass, then transition to next subpass
3043 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3044 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3045 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
3046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3047 "built for subpass 0 but used in subpass 1");
3048 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3049 m_errorMonitor->VerifyFound();
3050
3051 vkCmdEndRenderPass(m_commandBuffer->handle());
3052
Tony Barbour552f6c02016-12-21 14:34:07 -07003053 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003054
3055 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3056 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3057 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3058}
3059
Tony Barbour4e919972016-08-09 13:27:40 -06003060TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
3061 TEST_DESCRIPTION("Generate INVALID_RENDER_AREA error by beginning renderpass"
3062 "with extent outside of framebuffer");
3063 ASSERT_NO_FATAL_FAILURE(InitState());
3064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3065
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot execute a render pass with renderArea "
3067 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003068
3069 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3070 m_renderPassBeginInfo.renderArea.extent.width = 257;
3071 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003072 m_commandBuffer->BeginCommandBuffer();
3073 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003074 m_errorMonitor->VerifyFound();
3075}
3076
3077TEST_F(VkLayerTest, DisabledIndependentBlend) {
3078 TEST_DESCRIPTION("Generate INDEPENDENT_BLEND by disabling independent "
3079 "blend and then specifying different blend states for two "
3080 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003081 VkPhysicalDeviceFeatures features = {};
3082 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003083 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003084
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3086 "Invalid Pipeline CreateInfo: If independent blend feature not "
3087 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003088
Cody Northropc31a84f2016-08-22 10:41:47 -06003089 VkDescriptorSetObj descriptorSet(m_device);
3090 descriptorSet.AppendDummy();
3091 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003092
Cody Northropc31a84f2016-08-22 10:41:47 -06003093 VkPipelineObj pipeline(m_device);
3094 VkRenderpassObj renderpass(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003095 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003096 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003097
Cody Northropc31a84f2016-08-22 10:41:47 -06003098 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3099 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3100 att_state1.blendEnable = VK_TRUE;
3101 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3102 att_state2.blendEnable = VK_FALSE;
3103 pipeline.AddColorAttachment(0, &att_state1);
3104 pipeline.AddColorAttachment(1, &att_state2);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003105 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass.handle());
Cody Northropc31a84f2016-08-22 10:41:47 -06003106 m_errorMonitor->VerifyFound();
Tony Barbour4e919972016-08-09 13:27:40 -06003107}
3108
Chris Forbes26ec2122016-11-29 08:58:33 +13003109#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003110TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3111 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3112 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003113 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003114
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3116 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003117
3118 // Create a renderPass with a single color attachment
3119 VkAttachmentReference attach = {};
3120 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3121 VkSubpassDescription subpass = {};
3122 VkRenderPassCreateInfo rpci = {};
3123 rpci.subpassCount = 1;
3124 rpci.pSubpasses = &subpass;
3125 rpci.attachmentCount = 1;
3126 VkAttachmentDescription attach_desc = {};
3127 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3128 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3129 rpci.pAttachments = &attach_desc;
3130 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3131 VkRenderPass rp;
3132 subpass.pDepthStencilAttachment = &attach;
3133 subpass.pColorAttachments = NULL;
3134 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3135 m_errorMonitor->VerifyFound();
3136}
Chris Forbes26ec2122016-11-29 08:58:33 +13003137#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003138
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003139TEST_F(VkLayerTest, UnusedPreserveAttachment) {
3140 TEST_DESCRIPTION("Create a framebuffer where a subpass has a preserve "
3141 "attachment reference of VK_ATTACHMENT_UNUSED");
3142
3143 ASSERT_NO_FATAL_FAILURE(InitState());
3144 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3145
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003147
3148 VkAttachmentReference color_attach = {};
3149 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3150 color_attach.attachment = 0;
3151 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3152 VkSubpassDescription subpass = {};
3153 subpass.colorAttachmentCount = 1;
3154 subpass.pColorAttachments = &color_attach;
3155 subpass.preserveAttachmentCount = 1;
3156 subpass.pPreserveAttachments = &preserve_attachment;
3157
3158 VkRenderPassCreateInfo rpci = {};
3159 rpci.subpassCount = 1;
3160 rpci.pSubpasses = &subpass;
3161 rpci.attachmentCount = 1;
3162 VkAttachmentDescription attach_desc = {};
3163 attach_desc.format = VK_FORMAT_UNDEFINED;
3164 rpci.pAttachments = &attach_desc;
3165 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3166 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003167 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003168
3169 m_errorMonitor->VerifyFound();
3170
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003171 if (result == VK_SUCCESS) {
3172 vkDestroyRenderPass(m_device->device(), rp, NULL);
3173 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003174}
3175
Chris Forbesc5389742016-06-29 11:49:23 +12003176TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003177 TEST_DESCRIPTION("Ensure that CreateRenderPass produces a validation error "
3178 "when the source of a subpass multisample resolve "
3179 "does not have multiple samples.");
3180
Chris Forbesc5389742016-06-29 11:49:23 +12003181 ASSERT_NO_FATAL_FAILURE(InitState());
3182
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003183 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3184 "Subpass 0 requests multisample resolve from attachment 0 which has "
3185 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003186
3187 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003188 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3189 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3190 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3191 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3192 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3193 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003194 };
3195
3196 VkAttachmentReference color = {
3197 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3198 };
3199
3200 VkAttachmentReference resolve = {
3201 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3202 };
3203
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003204 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003205
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003206 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003207
3208 VkRenderPass rp;
3209 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3210
3211 m_errorMonitor->VerifyFound();
3212
3213 if (err == VK_SUCCESS)
3214 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3215}
3216
3217TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003218 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3219 "when a subpass multisample resolve operation is "
3220 "requested, and the destination of that resolve has "
3221 "multiple samples.");
3222
Chris Forbesc5389742016-06-29 11:49:23 +12003223 ASSERT_NO_FATAL_FAILURE(InitState());
3224
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3226 "Subpass 0 requests multisample resolve into attachment 1, which "
3227 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003228
3229 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003230 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3231 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3232 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3233 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3234 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3235 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003236 };
3237
3238 VkAttachmentReference color = {
3239 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3240 };
3241
3242 VkAttachmentReference resolve = {
3243 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3244 };
3245
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003246 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003247
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003248 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003249
3250 VkRenderPass rp;
3251 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3252
3253 m_errorMonitor->VerifyFound();
3254
3255 if (err == VK_SUCCESS)
3256 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3257}
3258
Chris Forbes3f128ef2016-06-29 14:58:53 +12003259TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Chris Forbes6655bb32016-07-01 18:27:30 +12003260 TEST_DESCRIPTION("Ensure CreateRenderPass produces a validation error "
3261 "when the color and depth attachments used by a subpass "
3262 "have inconsistent sample counts");
3263
Chris Forbes3f128ef2016-06-29 14:58:53 +12003264 ASSERT_NO_FATAL_FAILURE(InitState());
3265
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3267 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003268
3269 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003270 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3271 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3272 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3273 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3274 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3275 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003276 };
3277
3278 VkAttachmentReference color[] = {
3279 {
3280 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3281 },
3282 {
3283 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3284 },
3285 };
3286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003287 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003289 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003290
3291 VkRenderPass rp;
3292 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3293
3294 m_errorMonitor->VerifyFound();
3295
3296 if (err == VK_SUCCESS)
3297 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3298}
3299
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003300TEST_F(VkLayerTest, FramebufferCreateErrors) {
3301 TEST_DESCRIPTION("Hit errors when attempting to create a framebuffer :\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003302 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003303 " 2. Use a color image as depthStencil attachment\n"
Mike Weiblencce7ec72016-10-17 19:33:05 -06003304 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3305 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3306 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3307 " 6. Framebuffer attachment where dimensions don't match\n"
3308 " 7. Framebuffer attachment w/o identity swizzle\n"
3309 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003310
3311 ASSERT_NO_FATAL_FAILURE(InitState());
3312 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3315 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3316 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003317
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003318 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003319 VkAttachmentReference attach = {};
3320 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3321 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003322 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003323 VkRenderPassCreateInfo rpci = {};
3324 rpci.subpassCount = 1;
3325 rpci.pSubpasses = &subpass;
3326 rpci.attachmentCount = 1;
3327 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003328 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003329 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003330 rpci.pAttachments = &attach_desc;
3331 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3332 VkRenderPass rp;
3333 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3334 ASSERT_VK_SUCCESS(err);
3335
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003336 VkImageView ivs[2];
3337 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3338 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003339 VkFramebufferCreateInfo fb_info = {};
3340 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3341 fb_info.pNext = NULL;
3342 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003343 // Set mis-matching attachmentCount
3344 fb_info.attachmentCount = 2;
3345 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003346 fb_info.width = 100;
3347 fb_info.height = 100;
3348 fb_info.layers = 1;
3349
3350 VkFramebuffer fb;
3351 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3352
3353 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003354 if (err == VK_SUCCESS) {
3355 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3356 }
3357 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003358
3359 // Create a renderPass with a depth-stencil attachment created with
3360 // IMAGE_USAGE_COLOR_ATTACHMENT
3361 // Add our color attachment to pDepthStencilAttachment
3362 subpass.pDepthStencilAttachment = &attach;
3363 subpass.pColorAttachments = NULL;
3364 VkRenderPass rp_ds;
3365 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3366 ASSERT_VK_SUCCESS(err);
3367 // Set correct attachment count, but attachment has COLOR usage bit set
3368 fb_info.attachmentCount = 1;
3369 fb_info.renderPass = rp_ds;
3370
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003372 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3373
3374 m_errorMonitor->VerifyFound();
3375 if (err == VK_SUCCESS) {
3376 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3377 }
3378 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003379
3380 // Create new renderpass with alternate attachment format from fb
3381 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3382 subpass.pDepthStencilAttachment = NULL;
3383 subpass.pColorAttachments = &attach;
3384 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3385 ASSERT_VK_SUCCESS(err);
3386
3387 // Cause error due to mis-matched formats between rp & fb
3388 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3389 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3391 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003392 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3393
3394 m_errorMonitor->VerifyFound();
3395 if (err == VK_SUCCESS) {
3396 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3397 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003398 vkDestroyRenderPass(m_device->device(), rp, NULL);
3399
3400 // Create new renderpass with alternate sample count from fb
3401 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3402 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3403 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3404 ASSERT_VK_SUCCESS(err);
3405
3406 // Cause error due to mis-matched sample count between rp & fb
3407 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has VK_SAMPLE_COUNT_1_BIT samples "
3409 "that do not match the "
3410 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003411 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3412
3413 m_errorMonitor->VerifyFound();
3414 if (err == VK_SUCCESS) {
3415 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3416 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003417
3418 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003419
3420 // Create a custom imageView with non-1 mip levels
3421 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003422 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 -06003423 ASSERT_TRUE(image.initialized());
3424
3425 VkImageView view;
3426 VkImageViewCreateInfo ivci = {};
3427 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3428 ivci.image = image.handle();
3429 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3430 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3431 ivci.subresourceRange.layerCount = 1;
3432 ivci.subresourceRange.baseMipLevel = 0;
3433 // Set level count 2 (only 1 is allowed for FB attachment)
3434 ivci.subresourceRange.levelCount = 2;
3435 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3436 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3437 ASSERT_VK_SUCCESS(err);
3438 // Re-create renderpass to have matching sample count
3439 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3440 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3441 ASSERT_VK_SUCCESS(err);
3442
3443 fb_info.renderPass = rp;
3444 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003446 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3447
3448 m_errorMonitor->VerifyFound();
3449 if (err == VK_SUCCESS) {
3450 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3451 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003452 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003453 // Update view to original color buffer and grow FB dimensions too big
3454 fb_info.pAttachments = ivs;
3455 fb_info.height = 1024;
3456 fb_info.width = 1024;
3457 fb_info.layers = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003458 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at "
3459 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003460 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3461
3462 m_errorMonitor->VerifyFound();
3463 if (err == VK_SUCCESS) {
3464 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3465 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003466 // Create view attachment with non-identity swizzle
3467 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3468 ivci.image = image.handle();
3469 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3470 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3471 ivci.subresourceRange.layerCount = 1;
3472 ivci.subresourceRange.baseMipLevel = 0;
3473 ivci.subresourceRange.levelCount = 1;
3474 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3475 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3476 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3477 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3478 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3479 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3480 ASSERT_VK_SUCCESS(err);
3481
3482 fb_info.pAttachments = &view;
3483 fb_info.height = 100;
3484 fb_info.width = 100;
3485 fb_info.layers = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has non-identy swizzle. All "
3487 "framebuffer attachments must have "
3488 "been created with the identity "
3489 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003490 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3491
3492 m_errorMonitor->VerifyFound();
3493 if (err == VK_SUCCESS) {
3494 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3495 }
3496 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003497 // reset attachment to color attachment
3498 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003499
3500 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003501 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003502 fb_info.height = 100;
3503 fb_info.layers = 1;
3504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
3505 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3506
3507 m_errorMonitor->VerifyFound();
3508 if (err == VK_SUCCESS) {
3509 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3510 }
3511
3512 // Request fb that exceeds max height
3513 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003514 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003515 fb_info.layers = 1;
3516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
3517 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3518
3519 m_errorMonitor->VerifyFound();
3520 if (err == VK_SUCCESS) {
3521 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3522 }
3523
3524 // Request fb that exceeds max layers
3525 fb_info.width = 100;
3526 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003527 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -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 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003535
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003536 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003537}
3538
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003539TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003540 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bias dynamic "
3541 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003542
Cody Northropc31a84f2016-08-22 10:41:47 -06003543 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003544 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3546 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003547 m_errorMonitor->VerifyFound();
3548}
3549
3550TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003551 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Line Width dynamic "
3552 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003553
Cody Northropc31a84f2016-08-22 10:41:47 -06003554 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003555 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3557 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003558 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003559}
3560
3561TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003562 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Viewport dynamic "
3563 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003564
Cody Northropc31a84f2016-08-22 10:41:47 -06003565 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003566 // Dynamic viewport state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003567 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003568 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003569 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003570}
3571
3572TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003573 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Scissor dynamic "
3574 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003575
Cody Northropc31a84f2016-08-22 10:41:47 -06003576 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003577 // Dynamic scissor state
Mike Weiblen95dd0f92016-10-19 12:28:27 -06003578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003579 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003580 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003581}
3582
Cortd713fe82016-07-27 09:51:27 -07003583TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003584 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Blend Constants "
3585 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003586
3587 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003588 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3590 "Dynamic blend constants state not set for this command buffer");
3591 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003592 m_errorMonitor->VerifyFound();
3593}
3594
3595TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003596 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Depth Bounds dynamic "
3597 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003598
3599 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003600 if (!m_device->phy().features().depthBounds) {
3601 printf("Device does not support depthBounds test; skipped.\n");
3602 return;
3603 }
3604 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3606 "Dynamic depth bounds state not set for this command buffer");
3607 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003608 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003609}
3610
3611TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003612 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Read dynamic "
3613 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003614
3615 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003616 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003617 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3618 "Dynamic stencil read mask state not set for this command buffer");
3619 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003620 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003621}
3622
3623TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003624 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Write dynamic"
3625 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003626
3627 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003628 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003629 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3630 "Dynamic stencil write mask state not set for this command buffer");
3631 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003632 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003633}
3634
3635TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003636 TEST_DESCRIPTION("Run a simple draw calls to validate failure when Stencil Ref dynamic "
3637 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003638
3639 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003640 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3642 "Dynamic stencil reference state not set for this command buffer");
3643 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003644 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003645}
3646
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003647TEST_F(VkLayerTest, IndexBufferNotBound) {
3648 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003649
3650 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3652 "Index buffer object not bound to this command buffer when Indexed ");
3653 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003654 m_errorMonitor->VerifyFound();
3655}
3656
Karl Schultz6addd812016-02-02 17:17:23 -07003657TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3659 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3660 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003661
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003662 ASSERT_NO_FATAL_FAILURE(InitState());
3663 ASSERT_NO_FATAL_FAILURE(InitViewport());
3664 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3665
Karl Schultz6addd812016-02-02 17:17:23 -07003666 // We luck out b/c by default the framework creates CB w/ the
3667 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07003668 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003669 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07003670 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003671
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003672 // Bypass framework since it does the waits automatically
3673 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003674 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003675 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3676 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003677 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003678 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003679 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003680 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003681 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003682 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003683 submit_info.pSignalSemaphores = NULL;
3684
Chris Forbes40028e22016-06-13 09:59:34 +12003685 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003686 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003687 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003688
Karl Schultz6addd812016-02-02 17:17:23 -07003689 // Cause validation error by re-submitting cmd buffer that should only be
3690 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003691 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003692 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003693
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003694 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003695}
3696
Karl Schultz6addd812016-02-02 17:17:23 -07003697TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003698 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003699 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003700
3701 ASSERT_NO_FATAL_FAILURE(InitState());
3702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003703
Karl Schultz6addd812016-02-02 17:17:23 -07003704 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3705 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003706 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003707 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003708 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003709
3710 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003711 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3712 ds_pool_ci.pNext = NULL;
3713 ds_pool_ci.flags = 0;
3714 ds_pool_ci.maxSets = 1;
3715 ds_pool_ci.poolSizeCount = 1;
3716 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003717
3718 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003719 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003720 ASSERT_VK_SUCCESS(err);
3721
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003722 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3723 dsl_binding_samp.binding = 0;
3724 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3725 dsl_binding_samp.descriptorCount = 1;
3726 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3727 dsl_binding_samp.pImmutableSamplers = NULL;
3728
3729 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3730 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3731 ds_layout_ci.pNext = NULL;
3732 ds_layout_ci.bindingCount = 1;
3733 ds_layout_ci.pBindings = &dsl_binding_samp;
3734
3735 VkDescriptorSetLayout ds_layout_samp;
3736 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3737 ASSERT_VK_SUCCESS(err);
3738
3739 // Try to allocate 2 sets when pool only has 1 set
3740 VkDescriptorSet descriptor_sets[2];
3741 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3742 VkDescriptorSetAllocateInfo alloc_info = {};
3743 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3744 alloc_info.descriptorSetCount = 2;
3745 alloc_info.descriptorPool = ds_pool;
3746 alloc_info.pSetLayouts = set_layouts;
3747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3748 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3749 m_errorMonitor->VerifyFound();
3750
3751 alloc_info.descriptorSetCount = 1;
3752 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003753 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003754 dsl_binding.binding = 0;
3755 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3756 dsl_binding.descriptorCount = 1;
3757 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3758 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003759
Karl Schultz6addd812016-02-02 17:17:23 -07003760 ds_layout_ci.bindingCount = 1;
3761 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003762
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003763 VkDescriptorSetLayout ds_layout_ub;
3764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003765 ASSERT_VK_SUCCESS(err);
3766
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003767 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003768 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003769 alloc_info.pSetLayouts = &ds_layout_ub;
3770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3771 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003772
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003773 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003774
Karl Schultz2825ab92016-12-02 08:23:14 -07003775 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003776 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003777 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003778}
3779
Karl Schultz6addd812016-02-02 17:17:23 -07003780TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3781 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003782
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07003783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003784
Tobin Ehlise735c692015-10-08 13:13:50 -06003785 ASSERT_NO_FATAL_FAILURE(InitState());
3786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003787
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003788 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003789 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3790 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003791
3792 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003793 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3794 ds_pool_ci.pNext = NULL;
3795 ds_pool_ci.maxSets = 1;
3796 ds_pool_ci.poolSizeCount = 1;
3797 ds_pool_ci.flags = 0;
3798 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3799 // app can only call vkResetDescriptorPool on this pool.;
3800 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003801
3802 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003803 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003804 ASSERT_VK_SUCCESS(err);
3805
3806 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003807 dsl_binding.binding = 0;
3808 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3809 dsl_binding.descriptorCount = 1;
3810 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3811 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003812
3813 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003814 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3815 ds_layout_ci.pNext = NULL;
3816 ds_layout_ci.bindingCount = 1;
3817 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06003818
3819 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003820 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06003821 ASSERT_VK_SUCCESS(err);
3822
3823 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003824 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08003825 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003826 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06003827 alloc_info.descriptorPool = ds_pool;
3828 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003829 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06003830 ASSERT_VK_SUCCESS(err);
3831
3832 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003833 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06003834
Chia-I Wuf7458c52015-10-26 21:10:41 +08003835 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
3836 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06003837}
3838
Karl Schultz6addd812016-02-02 17:17:23 -07003839TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003840 // Attempt to clear Descriptor Pool with bad object.
3841 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06003842
3843 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003845 uint64_t fake_pool_handle = 0xbaad6001;
3846 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
3847 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06003848 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003849}
3850
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003851TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003852 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
3853 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003854 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06003855 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003856
3857 uint64_t fake_set_handle = 0xbaad6001;
3858 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06003859 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06003861
3862 ASSERT_NO_FATAL_FAILURE(InitState());
3863
3864 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
3865 layout_bindings[0].binding = 0;
3866 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3867 layout_bindings[0].descriptorCount = 1;
3868 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
3869 layout_bindings[0].pImmutableSamplers = NULL;
3870
3871 VkDescriptorSetLayout descriptor_set_layout;
3872 VkDescriptorSetLayoutCreateInfo dslci = {};
3873 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3874 dslci.pNext = NULL;
3875 dslci.bindingCount = 1;
3876 dslci.pBindings = layout_bindings;
3877 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003878 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003879
3880 VkPipelineLayout pipeline_layout;
3881 VkPipelineLayoutCreateInfo plci = {};
3882 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3883 plci.pNext = NULL;
3884 plci.setLayoutCount = 1;
3885 plci.pSetLayouts = &descriptor_set_layout;
3886 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06003887 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06003888
Tony Barbour552f6c02016-12-21 14:34:07 -07003889 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003890 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
3891 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06003892 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07003893 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06003894 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
3895 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003896}
3897
Karl Schultz6addd812016-02-02 17:17:23 -07003898TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06003899 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
3900 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06003901 uint64_t fake_layout_handle = 0xbaad6001;
3902 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07003903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06003904 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06003905 VkPipelineLayout pipeline_layout;
3906 VkPipelineLayoutCreateInfo plci = {};
3907 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
3908 plci.pNext = NULL;
3909 plci.setLayoutCount = 1;
3910 plci.pSetLayouts = &bad_layout;
3911 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
3912
3913 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06003914}
3915
Mark Muellerd4914412016-06-13 17:52:06 -06003916TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
3917 TEST_DESCRIPTION("This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
3918 "1) A uniform buffer update must have a valid buffer index."
3919 "2) When using an array of descriptors in a single WriteDescriptor,"
3920 " the descriptor types and stageflags must all be the same."
3921 "3) Immutable Sampler state must match across descriptors");
3922
Mike Weiblena6666382017-01-05 15:16:11 -07003923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06003924
3925 ASSERT_NO_FATAL_FAILURE(InitState());
3926 VkDescriptorPoolSize ds_type_count[4] = {};
3927 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3928 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003929 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003930 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07003931 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06003932 ds_type_count[2].descriptorCount = 1;
3933 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
3934 ds_type_count[3].descriptorCount = 1;
3935
3936 VkDescriptorPoolCreateInfo ds_pool_ci = {};
3937 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3938 ds_pool_ci.maxSets = 1;
3939 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
3940 ds_pool_ci.pPoolSizes = ds_type_count;
3941
3942 VkDescriptorPool ds_pool;
3943 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
3944 ASSERT_VK_SUCCESS(err);
3945
Mark Muellerb9896722016-06-16 09:54:29 -06003946 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06003947 layout_binding[0].binding = 0;
3948 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3949 layout_binding[0].descriptorCount = 1;
3950 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
3951 layout_binding[0].pImmutableSamplers = NULL;
3952
3953 layout_binding[1].binding = 1;
3954 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3955 layout_binding[1].descriptorCount = 1;
3956 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3957 layout_binding[1].pImmutableSamplers = NULL;
3958
3959 VkSamplerCreateInfo sampler_ci = {};
3960 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
3961 sampler_ci.pNext = NULL;
3962 sampler_ci.magFilter = VK_FILTER_NEAREST;
3963 sampler_ci.minFilter = VK_FILTER_NEAREST;
3964 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
3965 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3966 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3967 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
3968 sampler_ci.mipLodBias = 1.0;
3969 sampler_ci.anisotropyEnable = VK_FALSE;
3970 sampler_ci.maxAnisotropy = 1;
3971 sampler_ci.compareEnable = VK_FALSE;
3972 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
3973 sampler_ci.minLod = 1.0;
3974 sampler_ci.maxLod = 1.0;
3975 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
3976 sampler_ci.unnormalizedCoordinates = VK_FALSE;
3977 VkSampler sampler;
3978
3979 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
3980 ASSERT_VK_SUCCESS(err);
3981
3982 layout_binding[2].binding = 2;
3983 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3984 layout_binding[2].descriptorCount = 1;
3985 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
3986 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
3987
Mark Muellerd4914412016-06-13 17:52:06 -06003988 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3989 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3990 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
3991 ds_layout_ci.pBindings = layout_binding;
3992 VkDescriptorSetLayout ds_layout;
3993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
3994 ASSERT_VK_SUCCESS(err);
3995
3996 VkDescriptorSetAllocateInfo alloc_info = {};
3997 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3998 alloc_info.descriptorSetCount = 1;
3999 alloc_info.descriptorPool = ds_pool;
4000 alloc_info.pSetLayouts = &ds_layout;
4001 VkDescriptorSet descriptorSet;
4002 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4003 ASSERT_VK_SUCCESS(err);
4004
4005 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4006 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4007 pipeline_layout_ci.pNext = NULL;
4008 pipeline_layout_ci.setLayoutCount = 1;
4009 pipeline_layout_ci.pSetLayouts = &ds_layout;
4010
4011 VkPipelineLayout pipeline_layout;
4012 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4013 ASSERT_VK_SUCCESS(err);
4014
Mark Mueller5c838ce2016-06-16 09:54:29 -06004015 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004016 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4017 descriptor_write.dstSet = descriptorSet;
4018 descriptor_write.dstBinding = 0;
4019 descriptor_write.descriptorCount = 1;
4020 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4021
Mark Mueller5c838ce2016-06-16 09:54:29 -06004022 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004023 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4024 m_errorMonitor->VerifyFound();
4025
4026 // Create a buffer to update the descriptor with
4027 uint32_t qfi = 0;
4028 VkBufferCreateInfo buffCI = {};
4029 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4030 buffCI.size = 1024;
4031 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4032 buffCI.queueFamilyIndexCount = 1;
4033 buffCI.pQueueFamilyIndices = &qfi;
4034
4035 VkBuffer dyub;
4036 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4037 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004038
Tony Barboure132c5f2016-12-12 11:50:20 -07004039 VkDeviceMemory mem;
4040 VkMemoryRequirements mem_reqs;
4041 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4042
4043 VkMemoryAllocateInfo mem_alloc_info = {};
4044 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4045 mem_alloc_info.allocationSize = mem_reqs.size;
4046 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4047 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4048 ASSERT_VK_SUCCESS(err);
4049
4050 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4051 ASSERT_VK_SUCCESS(err);
4052
4053 VkDescriptorBufferInfo buffInfo[2] = {};
4054 buffInfo[0].buffer = dyub;
4055 buffInfo[0].offset = 0;
4056 buffInfo[0].range = 1024;
4057 buffInfo[1].buffer = dyub;
4058 buffInfo[1].offset = 0;
4059 buffInfo[1].range = 1024;
4060 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004061 descriptor_write.descriptorCount = 2;
4062
Mark Mueller5c838ce2016-06-16 09:54:29 -06004063 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004065 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4066 m_errorMonitor->VerifyFound();
4067
Mark Mueller5c838ce2016-06-16 09:54:29 -06004068 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4069 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004070 descriptor_write.dstBinding = 1;
4071 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004072
Mark Mueller5c838ce2016-06-16 09:54:29 -06004073 // Make pImageInfo index non-null to avoid complaints of it missing
4074 VkDescriptorImageInfo imageInfo = {};
4075 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4076 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004078 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4079 m_errorMonitor->VerifyFound();
4080
Mark Muellerd4914412016-06-13 17:52:06 -06004081 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004082 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004083 vkDestroySampler(m_device->device(), sampler, NULL);
4084 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4085 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4086 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4087}
4088
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004089TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
4090 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4091 "due to a buffer dependency being destroyed.");
4092 ASSERT_NO_FATAL_FAILURE(InitState());
4093
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004094 VkBuffer buffer;
4095 VkDeviceMemory mem;
4096 VkMemoryRequirements mem_reqs;
4097
4098 VkBufferCreateInfo buf_info = {};
4099 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004100 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004101 buf_info.size = 256;
4102 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4103 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4104 ASSERT_VK_SUCCESS(err);
4105
4106 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4107
4108 VkMemoryAllocateInfo alloc_info = {};
4109 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4110 alloc_info.allocationSize = 256;
4111 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004112 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 -06004113 if (!pass) {
4114 vkDestroyBuffer(m_device->device(), buffer, NULL);
4115 return;
4116 }
4117 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4118 ASSERT_VK_SUCCESS(err);
4119
4120 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4121 ASSERT_VK_SUCCESS(err);
4122
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004123 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004124 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004125 m_commandBuffer->EndCommandBuffer();
4126
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004128 // Destroy buffer dependency prior to submit to cause ERROR
4129 vkDestroyBuffer(m_device->device(), buffer, NULL);
4130
4131 VkSubmitInfo submit_info = {};
4132 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4133 submit_info.commandBufferCount = 1;
4134 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4135 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4136
4137 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004138 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004139 vkFreeMemory(m_device->handle(), mem, NULL);
4140}
4141
Tobin Ehlisea413442016-09-28 10:23:59 -06004142TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4143 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4144
4145 ASSERT_NO_FATAL_FAILURE(InitState());
4146 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4147
4148 VkDescriptorPoolSize ds_type_count;
4149 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4150 ds_type_count.descriptorCount = 1;
4151
4152 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4153 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4154 ds_pool_ci.maxSets = 1;
4155 ds_pool_ci.poolSizeCount = 1;
4156 ds_pool_ci.pPoolSizes = &ds_type_count;
4157
4158 VkDescriptorPool ds_pool;
4159 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4160 ASSERT_VK_SUCCESS(err);
4161
4162 VkDescriptorSetLayoutBinding layout_binding;
4163 layout_binding.binding = 0;
4164 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4165 layout_binding.descriptorCount = 1;
4166 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4167 layout_binding.pImmutableSamplers = NULL;
4168
4169 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4170 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4171 ds_layout_ci.bindingCount = 1;
4172 ds_layout_ci.pBindings = &layout_binding;
4173 VkDescriptorSetLayout ds_layout;
4174 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4175 ASSERT_VK_SUCCESS(err);
4176
4177 VkDescriptorSetAllocateInfo alloc_info = {};
4178 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4179 alloc_info.descriptorSetCount = 1;
4180 alloc_info.descriptorPool = ds_pool;
4181 alloc_info.pSetLayouts = &ds_layout;
4182 VkDescriptorSet descriptor_set;
4183 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4184 ASSERT_VK_SUCCESS(err);
4185
4186 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4187 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4188 pipeline_layout_ci.pNext = NULL;
4189 pipeline_layout_ci.setLayoutCount = 1;
4190 pipeline_layout_ci.pSetLayouts = &ds_layout;
4191
4192 VkPipelineLayout pipeline_layout;
4193 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4194 ASSERT_VK_SUCCESS(err);
4195
4196 VkBuffer buffer;
4197 uint32_t queue_family_index = 0;
4198 VkBufferCreateInfo buffer_create_info = {};
4199 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4200 buffer_create_info.size = 1024;
4201 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4202 buffer_create_info.queueFamilyIndexCount = 1;
4203 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4204
4205 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4206 ASSERT_VK_SUCCESS(err);
4207
4208 VkMemoryRequirements memory_reqs;
4209 VkDeviceMemory buffer_memory;
4210
4211 VkMemoryAllocateInfo memory_info = {};
4212 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4213 memory_info.allocationSize = 0;
4214 memory_info.memoryTypeIndex = 0;
4215
4216 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4217 memory_info.allocationSize = memory_reqs.size;
4218 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4219 ASSERT_TRUE(pass);
4220
4221 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4222 ASSERT_VK_SUCCESS(err);
4223 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4224 ASSERT_VK_SUCCESS(err);
4225
4226 VkBufferView view;
4227 VkBufferViewCreateInfo bvci = {};
4228 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4229 bvci.buffer = buffer;
4230 bvci.format = VK_FORMAT_R8_UNORM;
4231 bvci.range = VK_WHOLE_SIZE;
4232
4233 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4234 ASSERT_VK_SUCCESS(err);
4235
4236 VkWriteDescriptorSet descriptor_write = {};
4237 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4238 descriptor_write.dstSet = descriptor_set;
4239 descriptor_write.dstBinding = 0;
4240 descriptor_write.descriptorCount = 1;
4241 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4242 descriptor_write.pTexelBufferView = &view;
4243
4244 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4245
4246 char const *vsSource = "#version 450\n"
4247 "\n"
4248 "out gl_PerVertex { \n"
4249 " vec4 gl_Position;\n"
4250 "};\n"
4251 "void main(){\n"
4252 " gl_Position = vec4(1);\n"
4253 "}\n";
4254 char const *fsSource = "#version 450\n"
4255 "\n"
4256 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4257 "layout(location=0) out vec4 x;\n"
4258 "void main(){\n"
4259 " x = imageLoad(s, 0);\n"
4260 "}\n";
4261 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4262 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4263 VkPipelineObj pipe(m_device);
4264 pipe.AddShader(&vs);
4265 pipe.AddShader(&fs);
4266 pipe.AddColorAttachment();
4267 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4268
4269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4271
Tony Barbour552f6c02016-12-21 14:34:07 -07004272 m_commandBuffer->BeginCommandBuffer();
4273 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4274
Tobin Ehlisea413442016-09-28 10:23:59 -06004275 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4276 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4277 VkRect2D scissor = {{0, 0}, {16, 16}};
4278 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4279 // Bind pipeline to cmd buffer
4280 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4281 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4282 &descriptor_set, 0, nullptr);
4283 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004284 m_commandBuffer->EndRenderPass();
4285 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004286
4287 // Delete BufferView in order to invalidate cmd buffer
4288 vkDestroyBufferView(m_device->device(), view, NULL);
4289 // Now attempt submit of cmd buffer
4290 VkSubmitInfo submit_info = {};
4291 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4292 submit_info.commandBufferCount = 1;
4293 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4294 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4295 m_errorMonitor->VerifyFound();
4296
4297 // Clean-up
4298 vkDestroyBuffer(m_device->device(), buffer, NULL);
4299 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4300 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4301 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4302 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4303}
4304
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004305TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
4306 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4307 "due to an image dependency being destroyed.");
4308 ASSERT_NO_FATAL_FAILURE(InitState());
4309
4310 VkImage image;
4311 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4312 VkImageCreateInfo image_create_info = {};
4313 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4314 image_create_info.pNext = NULL;
4315 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4316 image_create_info.format = tex_format;
4317 image_create_info.extent.width = 32;
4318 image_create_info.extent.height = 32;
4319 image_create_info.extent.depth = 1;
4320 image_create_info.mipLevels = 1;
4321 image_create_info.arrayLayers = 1;
4322 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4323 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004324 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004325 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004326 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004327 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004328 // Have to bind memory to image before recording cmd in cmd buffer using it
4329 VkMemoryRequirements mem_reqs;
4330 VkDeviceMemory image_mem;
4331 bool pass;
4332 VkMemoryAllocateInfo mem_alloc = {};
4333 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4334 mem_alloc.pNext = NULL;
4335 mem_alloc.memoryTypeIndex = 0;
4336 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4337 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004338 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004339 ASSERT_TRUE(pass);
4340 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4341 ASSERT_VK_SUCCESS(err);
4342 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4343 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004344
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004345 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004346 VkClearColorValue ccv;
4347 ccv.float32[0] = 1.0f;
4348 ccv.float32[1] = 1.0f;
4349 ccv.float32[2] = 1.0f;
4350 ccv.float32[3] = 1.0f;
4351 VkImageSubresourceRange isr = {};
4352 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004353 isr.baseArrayLayer = 0;
4354 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004355 isr.layerCount = 1;
4356 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004357 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004358 m_commandBuffer->EndCommandBuffer();
4359
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004361 // Destroy image dependency prior to submit to cause ERROR
4362 vkDestroyImage(m_device->device(), image, NULL);
4363
4364 VkSubmitInfo submit_info = {};
4365 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4366 submit_info.commandBufferCount = 1;
4367 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4368 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4369
4370 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004371 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004372}
4373
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004374TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
4375 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4376 "due to a framebuffer image dependency being destroyed.");
4377 VkFormatProperties format_properties;
4378 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004379 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4380 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004381 return;
4382 }
4383
4384 ASSERT_NO_FATAL_FAILURE(InitState());
4385 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4386
4387 VkImageCreateInfo image_ci = {};
4388 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4389 image_ci.pNext = NULL;
4390 image_ci.imageType = VK_IMAGE_TYPE_2D;
4391 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4392 image_ci.extent.width = 32;
4393 image_ci.extent.height = 32;
4394 image_ci.extent.depth = 1;
4395 image_ci.mipLevels = 1;
4396 image_ci.arrayLayers = 1;
4397 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4398 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004399 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004400 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4401 image_ci.flags = 0;
4402 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004403 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004404
4405 VkMemoryRequirements memory_reqs;
4406 VkDeviceMemory image_memory;
4407 bool pass;
4408 VkMemoryAllocateInfo memory_info = {};
4409 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4410 memory_info.pNext = NULL;
4411 memory_info.allocationSize = 0;
4412 memory_info.memoryTypeIndex = 0;
4413 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4414 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004415 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004416 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004417 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004418 ASSERT_VK_SUCCESS(err);
4419 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4420 ASSERT_VK_SUCCESS(err);
4421
4422 VkImageViewCreateInfo ivci = {
4423 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4424 nullptr,
4425 0,
4426 image,
4427 VK_IMAGE_VIEW_TYPE_2D,
4428 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004429 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004430 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4431 };
4432 VkImageView view;
4433 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4434 ASSERT_VK_SUCCESS(err);
4435
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004436 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004437 VkFramebuffer fb;
4438 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4439 ASSERT_VK_SUCCESS(err);
4440
4441 // Just use default renderpass with our framebuffer
4442 m_renderPassBeginInfo.framebuffer = fb;
4443 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004444 m_commandBuffer->BeginCommandBuffer();
4445 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4446 m_commandBuffer->EndRenderPass();
4447 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004448 // Destroy image attached to framebuffer to invalidate cmd buffer
4449 vkDestroyImage(m_device->device(), image, NULL);
4450 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004452 QueueCommandBuffer(false);
4453 m_errorMonitor->VerifyFound();
4454
4455 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4456 vkDestroyImageView(m_device->device(), view, nullptr);
4457 vkFreeMemory(m_device->device(), image_memory, nullptr);
4458}
4459
Tobin Ehlisb329f992016-10-12 13:20:29 -06004460TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4461 TEST_DESCRIPTION("Delete in-use framebuffer.");
4462 VkFormatProperties format_properties;
4463 VkResult err = VK_SUCCESS;
4464 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4465
4466 ASSERT_NO_FATAL_FAILURE(InitState());
4467 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4468
4469 VkImageObj image(m_device);
4470 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4471 ASSERT_TRUE(image.initialized());
4472 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4473
4474 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4475 VkFramebuffer fb;
4476 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4477 ASSERT_VK_SUCCESS(err);
4478
4479 // Just use default renderpass with our framebuffer
4480 m_renderPassBeginInfo.framebuffer = fb;
4481 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004482 m_commandBuffer->BeginCommandBuffer();
4483 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4484 m_commandBuffer->EndRenderPass();
4485 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004486 // Submit cmd buffer to put it in-flight
4487 VkSubmitInfo submit_info = {};
4488 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4489 submit_info.commandBufferCount = 1;
4490 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4491 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4492 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06004494 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4495 m_errorMonitor->VerifyFound();
4496 // Wait for queue to complete so we can safely destroy everything
4497 vkQueueWaitIdle(m_device->m_queue);
4498 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4499}
4500
Tobin Ehlis88becd72016-09-21 14:33:41 -06004501TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4502 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4503 VkFormatProperties format_properties;
4504 VkResult err = VK_SUCCESS;
4505 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004506
4507 ASSERT_NO_FATAL_FAILURE(InitState());
4508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4509
4510 VkImageCreateInfo image_ci = {};
4511 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4512 image_ci.pNext = NULL;
4513 image_ci.imageType = VK_IMAGE_TYPE_2D;
4514 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4515 image_ci.extent.width = 256;
4516 image_ci.extent.height = 256;
4517 image_ci.extent.depth = 1;
4518 image_ci.mipLevels = 1;
4519 image_ci.arrayLayers = 1;
4520 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4521 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004522 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004523 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4524 image_ci.flags = 0;
4525 VkImage image;
4526 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4527
4528 VkMemoryRequirements memory_reqs;
4529 VkDeviceMemory image_memory;
4530 bool pass;
4531 VkMemoryAllocateInfo memory_info = {};
4532 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4533 memory_info.pNext = NULL;
4534 memory_info.allocationSize = 0;
4535 memory_info.memoryTypeIndex = 0;
4536 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4537 memory_info.allocationSize = memory_reqs.size;
4538 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4539 ASSERT_TRUE(pass);
4540 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4541 ASSERT_VK_SUCCESS(err);
4542 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4543 ASSERT_VK_SUCCESS(err);
4544
4545 VkImageViewCreateInfo ivci = {
4546 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4547 nullptr,
4548 0,
4549 image,
4550 VK_IMAGE_VIEW_TYPE_2D,
4551 VK_FORMAT_B8G8R8A8_UNORM,
4552 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4553 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4554 };
4555 VkImageView view;
4556 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4557 ASSERT_VK_SUCCESS(err);
4558
4559 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4560 VkFramebuffer fb;
4561 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4562 ASSERT_VK_SUCCESS(err);
4563
4564 // Just use default renderpass with our framebuffer
4565 m_renderPassBeginInfo.framebuffer = fb;
4566 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004567 m_commandBuffer->BeginCommandBuffer();
4568 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4569 m_commandBuffer->EndRenderPass();
4570 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06004571 // Submit cmd buffer to put it (and attached imageView) in-flight
4572 VkSubmitInfo submit_info = {};
4573 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4574 submit_info.commandBufferCount = 1;
4575 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4576 // Submit cmd buffer to put framebuffer and children in-flight
4577 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4578 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004580 vkDestroyImage(m_device->device(), image, NULL);
4581 m_errorMonitor->VerifyFound();
4582 // Wait for queue to complete so we can safely destroy image and other objects
4583 vkQueueWaitIdle(m_device->m_queue);
4584 vkDestroyImage(m_device->device(), image, NULL);
4585 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4586 vkDestroyImageView(m_device->device(), view, nullptr);
4587 vkFreeMemory(m_device->device(), image_memory, nullptr);
4588}
4589
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004590TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4591 TEST_DESCRIPTION("Delete in-use renderPass.");
4592
4593 ASSERT_NO_FATAL_FAILURE(InitState());
4594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4595
4596 // Create simple renderpass
4597 VkAttachmentReference attach = {};
4598 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4599 VkSubpassDescription subpass = {};
4600 subpass.pColorAttachments = &attach;
4601 VkRenderPassCreateInfo rpci = {};
4602 rpci.subpassCount = 1;
4603 rpci.pSubpasses = &subpass;
4604 rpci.attachmentCount = 1;
4605 VkAttachmentDescription attach_desc = {};
4606 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4607 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4608 rpci.pAttachments = &attach_desc;
4609 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4610 VkRenderPass rp;
4611 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4612 ASSERT_VK_SUCCESS(err);
4613
4614 // Create a pipeline that uses the given renderpass
4615 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4616 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4617
4618 VkPipelineLayout pipeline_layout;
4619 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4620 ASSERT_VK_SUCCESS(err);
4621
4622 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4623 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4624 vp_state_ci.viewportCount = 1;
4625 VkViewport vp = {}; // Just need dummy vp to point to
4626 vp_state_ci.pViewports = &vp;
4627 vp_state_ci.scissorCount = 1;
4628 VkRect2D scissors = {}; // Dummy scissors to point to
4629 vp_state_ci.pScissors = &scissors;
4630
4631 VkPipelineShaderStageCreateInfo shaderStages[2];
4632 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4633
4634 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4635 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4636 // but add it to be able to run on more devices
4637 shaderStages[0] = vs.GetStageCreateInfo();
4638 shaderStages[1] = fs.GetStageCreateInfo();
4639
4640 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4641 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4642
4643 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4644 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4645 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4646
4647 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4648 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4649 rs_ci.rasterizerDiscardEnable = true;
4650 rs_ci.lineWidth = 1.0f;
4651
4652 VkPipelineColorBlendAttachmentState att = {};
4653 att.blendEnable = VK_FALSE;
4654 att.colorWriteMask = 0xf;
4655
4656 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4657 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4658 cb_ci.attachmentCount = 1;
4659 cb_ci.pAttachments = &att;
4660
4661 VkGraphicsPipelineCreateInfo gp_ci = {};
4662 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4663 gp_ci.stageCount = 2;
4664 gp_ci.pStages = shaderStages;
4665 gp_ci.pVertexInputState = &vi_ci;
4666 gp_ci.pInputAssemblyState = &ia_ci;
4667 gp_ci.pViewportState = &vp_state_ci;
4668 gp_ci.pRasterizationState = &rs_ci;
4669 gp_ci.pColorBlendState = &cb_ci;
4670 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4671 gp_ci.layout = pipeline_layout;
4672 gp_ci.renderPass = rp;
4673
4674 VkPipelineCacheCreateInfo pc_ci = {};
4675 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4676
4677 VkPipeline pipeline;
4678 VkPipelineCache pipe_cache;
4679 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4680 ASSERT_VK_SUCCESS(err);
4681
4682 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4683 ASSERT_VK_SUCCESS(err);
4684 // Bind pipeline to cmd buffer, will also bind renderpass
4685 m_commandBuffer->BeginCommandBuffer();
4686 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4687 m_commandBuffer->EndCommandBuffer();
4688
4689 VkSubmitInfo submit_info = {};
4690 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4691 submit_info.commandBufferCount = 1;
4692 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4693 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4694
4695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4696 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4697 m_errorMonitor->VerifyFound();
4698
4699 // Wait for queue to complete so we can safely destroy everything
4700 vkQueueWaitIdle(m_device->m_queue);
4701 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4702 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4703 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4704 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4705}
4706
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004707TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004708 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004709 ASSERT_NO_FATAL_FAILURE(InitState());
4710
4711 VkImage image;
4712 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4713 VkImageCreateInfo image_create_info = {};
4714 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4715 image_create_info.pNext = NULL;
4716 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4717 image_create_info.format = tex_format;
4718 image_create_info.extent.width = 32;
4719 image_create_info.extent.height = 32;
4720 image_create_info.extent.depth = 1;
4721 image_create_info.mipLevels = 1;
4722 image_create_info.arrayLayers = 1;
4723 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4724 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004725 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004726 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004727 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004728 ASSERT_VK_SUCCESS(err);
4729 // Have to bind memory to image before recording cmd in cmd buffer using it
4730 VkMemoryRequirements mem_reqs;
4731 VkDeviceMemory image_mem;
4732 bool pass;
4733 VkMemoryAllocateInfo mem_alloc = {};
4734 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4735 mem_alloc.pNext = NULL;
4736 mem_alloc.memoryTypeIndex = 0;
4737 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4738 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004739 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004740 ASSERT_TRUE(pass);
4741 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4742 ASSERT_VK_SUCCESS(err);
4743
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004744 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004746 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004747
4748 m_commandBuffer->BeginCommandBuffer();
4749 VkClearColorValue ccv;
4750 ccv.float32[0] = 1.0f;
4751 ccv.float32[1] = 1.0f;
4752 ccv.float32[2] = 1.0f;
4753 ccv.float32[3] = 1.0f;
4754 VkImageSubresourceRange isr = {};
4755 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4756 isr.baseArrayLayer = 0;
4757 isr.baseMipLevel = 0;
4758 isr.layerCount = 1;
4759 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004760 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004761 m_commandBuffer->EndCommandBuffer();
4762
4763 m_errorMonitor->VerifyFound();
4764 vkDestroyImage(m_device->device(), image, NULL);
4765 vkFreeMemory(m_device->device(), image_mem, nullptr);
4766}
4767
4768TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004769 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004770 ASSERT_NO_FATAL_FAILURE(InitState());
4771
4772 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004773 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 -06004774 VK_IMAGE_TILING_OPTIMAL, 0);
4775 ASSERT_TRUE(image.initialized());
4776
4777 VkBuffer buffer;
4778 VkDeviceMemory mem;
4779 VkMemoryRequirements mem_reqs;
4780
4781 VkBufferCreateInfo buf_info = {};
4782 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004783 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004784 buf_info.size = 256;
4785 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4786 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4787 ASSERT_VK_SUCCESS(err);
4788
4789 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4790
4791 VkMemoryAllocateInfo alloc_info = {};
4792 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4793 alloc_info.allocationSize = 256;
4794 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004795 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 -06004796 if (!pass) {
4797 vkDestroyBuffer(m_device->device(), buffer, NULL);
4798 return;
4799 }
4800 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4801 ASSERT_VK_SUCCESS(err);
4802
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004803 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004805 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004806 VkBufferImageCopy region = {};
4807 region.bufferRowLength = 128;
4808 region.bufferImageHeight = 128;
4809 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4810
4811 region.imageSubresource.layerCount = 1;
4812 region.imageExtent.height = 4;
4813 region.imageExtent.width = 4;
4814 region.imageExtent.depth = 1;
4815 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004816 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
4817 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004818 m_commandBuffer->EndCommandBuffer();
4819
4820 m_errorMonitor->VerifyFound();
4821
4822 vkDestroyBuffer(m_device->device(), buffer, NULL);
4823 vkFreeMemory(m_device->handle(), mem, NULL);
4824}
4825
Tobin Ehlis85940f52016-07-07 16:57:21 -06004826TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
4827 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4828 "due to an event dependency being destroyed.");
4829 ASSERT_NO_FATAL_FAILURE(InitState());
4830
4831 VkEvent event;
4832 VkEventCreateInfo evci = {};
4833 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
4834 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
4835 ASSERT_VK_SUCCESS(result);
4836
4837 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004838 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06004839 m_commandBuffer->EndCommandBuffer();
4840
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06004842 // Destroy event dependency prior to submit to cause ERROR
4843 vkDestroyEvent(m_device->device(), event, NULL);
4844
4845 VkSubmitInfo submit_info = {};
4846 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4847 submit_info.commandBufferCount = 1;
4848 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4849 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4850
4851 m_errorMonitor->VerifyFound();
4852}
4853
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004854TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
4855 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4856 "due to a query pool dependency being destroyed.");
4857 ASSERT_NO_FATAL_FAILURE(InitState());
4858
4859 VkQueryPool query_pool;
4860 VkQueryPoolCreateInfo qpci{};
4861 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
4862 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
4863 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004864 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004865 ASSERT_VK_SUCCESS(result);
4866
4867 m_commandBuffer->BeginCommandBuffer();
4868 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
4869 m_commandBuffer->EndCommandBuffer();
4870
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06004872 // Destroy query pool dependency prior to submit to cause ERROR
4873 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
4874
4875 VkSubmitInfo submit_info = {};
4876 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4877 submit_info.commandBufferCount = 1;
4878 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4879 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4880
4881 m_errorMonitor->VerifyFound();
4882}
4883
Tobin Ehlis24130d92016-07-08 15:50:53 -06004884TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
4885 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4886 "due to a pipeline dependency being destroyed.");
4887 ASSERT_NO_FATAL_FAILURE(InitState());
4888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4889
4890 VkResult err;
4891
4892 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4893 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4894
4895 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004896 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004897 ASSERT_VK_SUCCESS(err);
4898
4899 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4900 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4901 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004902 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06004903 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004904 vp_state_ci.scissorCount = 1;
4905 VkRect2D scissors = {}; // Dummy scissors to point to
4906 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004907
4908 VkPipelineShaderStageCreateInfo shaderStages[2];
4909 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4910
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004911 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
4912 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
4913 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06004914 shaderStages[0] = vs.GetStageCreateInfo();
4915 shaderStages[1] = fs.GetStageCreateInfo();
4916
4917 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4918 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4919
4920 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4921 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4922 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4923
4924 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4925 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12004926 rs_ci.rasterizerDiscardEnable = true;
4927 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004928
4929 VkPipelineColorBlendAttachmentState att = {};
4930 att.blendEnable = VK_FALSE;
4931 att.colorWriteMask = 0xf;
4932
4933 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4934 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4935 cb_ci.attachmentCount = 1;
4936 cb_ci.pAttachments = &att;
4937
4938 VkGraphicsPipelineCreateInfo gp_ci = {};
4939 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4940 gp_ci.stageCount = 2;
4941 gp_ci.pStages = shaderStages;
4942 gp_ci.pVertexInputState = &vi_ci;
4943 gp_ci.pInputAssemblyState = &ia_ci;
4944 gp_ci.pViewportState = &vp_state_ci;
4945 gp_ci.pRasterizationState = &rs_ci;
4946 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06004947 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4948 gp_ci.layout = pipeline_layout;
4949 gp_ci.renderPass = renderPass();
4950
4951 VkPipelineCacheCreateInfo pc_ci = {};
4952 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4953
4954 VkPipeline pipeline;
4955 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004956 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004957 ASSERT_VK_SUCCESS(err);
4958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004959 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004960 ASSERT_VK_SUCCESS(err);
4961
4962 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004963 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06004964 m_commandBuffer->EndCommandBuffer();
4965 // Now destroy pipeline in order to cause error when submitting
4966 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4967
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06004969
4970 VkSubmitInfo submit_info = {};
4971 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4972 submit_info.commandBufferCount = 1;
4973 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4974 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4975
4976 m_errorMonitor->VerifyFound();
4977 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
4978 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4979}
4980
Tobin Ehlis31289162016-08-17 14:57:58 -06004981TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
4982 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
4983 "due to a bound descriptor set with a buffer dependency "
4984 "being destroyed.");
4985 ASSERT_NO_FATAL_FAILURE(InitState());
4986 ASSERT_NO_FATAL_FAILURE(InitViewport());
4987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4988
4989 VkDescriptorPoolSize ds_type_count = {};
4990 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4991 ds_type_count.descriptorCount = 1;
4992
4993 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4994 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4995 ds_pool_ci.pNext = NULL;
4996 ds_pool_ci.maxSets = 1;
4997 ds_pool_ci.poolSizeCount = 1;
4998 ds_pool_ci.pPoolSizes = &ds_type_count;
4999
5000 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005001 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005002 ASSERT_VK_SUCCESS(err);
5003
5004 VkDescriptorSetLayoutBinding dsl_binding = {};
5005 dsl_binding.binding = 0;
5006 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5007 dsl_binding.descriptorCount = 1;
5008 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5009 dsl_binding.pImmutableSamplers = NULL;
5010
5011 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5012 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5013 ds_layout_ci.pNext = NULL;
5014 ds_layout_ci.bindingCount = 1;
5015 ds_layout_ci.pBindings = &dsl_binding;
5016 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005017 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005018 ASSERT_VK_SUCCESS(err);
5019
5020 VkDescriptorSet descriptorSet;
5021 VkDescriptorSetAllocateInfo alloc_info = {};
5022 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5023 alloc_info.descriptorSetCount = 1;
5024 alloc_info.descriptorPool = ds_pool;
5025 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005026 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005027 ASSERT_VK_SUCCESS(err);
5028
5029 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5030 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5031 pipeline_layout_ci.pNext = NULL;
5032 pipeline_layout_ci.setLayoutCount = 1;
5033 pipeline_layout_ci.pSetLayouts = &ds_layout;
5034
5035 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005036 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005037 ASSERT_VK_SUCCESS(err);
5038
5039 // Create a buffer to update the descriptor with
5040 uint32_t qfi = 0;
5041 VkBufferCreateInfo buffCI = {};
5042 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5043 buffCI.size = 1024;
5044 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5045 buffCI.queueFamilyIndexCount = 1;
5046 buffCI.pQueueFamilyIndices = &qfi;
5047
5048 VkBuffer buffer;
5049 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5050 ASSERT_VK_SUCCESS(err);
5051 // Allocate memory and bind to buffer so we can make it to the appropriate
5052 // error
5053 VkMemoryAllocateInfo mem_alloc = {};
5054 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5055 mem_alloc.pNext = NULL;
5056 mem_alloc.allocationSize = 1024;
5057 mem_alloc.memoryTypeIndex = 0;
5058
5059 VkMemoryRequirements memReqs;
5060 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005061 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005062 if (!pass) {
5063 vkDestroyBuffer(m_device->device(), buffer, NULL);
5064 return;
5065 }
5066
5067 VkDeviceMemory mem;
5068 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5069 ASSERT_VK_SUCCESS(err);
5070 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5071 ASSERT_VK_SUCCESS(err);
5072 // Correctly update descriptor to avoid "NOT_UPDATED" error
5073 VkDescriptorBufferInfo buffInfo = {};
5074 buffInfo.buffer = buffer;
5075 buffInfo.offset = 0;
5076 buffInfo.range = 1024;
5077
5078 VkWriteDescriptorSet descriptor_write;
5079 memset(&descriptor_write, 0, sizeof(descriptor_write));
5080 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5081 descriptor_write.dstSet = descriptorSet;
5082 descriptor_write.dstBinding = 0;
5083 descriptor_write.descriptorCount = 1;
5084 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5085 descriptor_write.pBufferInfo = &buffInfo;
5086
5087 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5088
5089 // Create PSO to be used for draw-time errors below
5090 char const *vsSource = "#version 450\n"
5091 "\n"
5092 "out gl_PerVertex { \n"
5093 " vec4 gl_Position;\n"
5094 "};\n"
5095 "void main(){\n"
5096 " gl_Position = vec4(1);\n"
5097 "}\n";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005098 char const *fsSource = "#version 450\n"
5099 "\n"
5100 "layout(location=0) out vec4 x;\n"
5101 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5102 "void main(){\n"
5103 " x = vec4(bar.y);\n"
5104 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005105 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5106 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5107 VkPipelineObj pipe(m_device);
5108 pipe.AddShader(&vs);
5109 pipe.AddShader(&fs);
5110 pipe.AddColorAttachment();
5111 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5112
Tony Barbour552f6c02016-12-21 14:34:07 -07005113 m_commandBuffer->BeginCommandBuffer();
5114 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005115 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5116 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5117 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005118
5119 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5120 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5121
Tobin Ehlis31289162016-08-17 14:57:58 -06005122 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005123 m_commandBuffer->EndRenderPass();
5124 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005126 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5127 vkDestroyBuffer(m_device->device(), buffer, NULL);
5128 // Attempt to submit cmd buffer
5129 VkSubmitInfo submit_info = {};
5130 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5131 submit_info.commandBufferCount = 1;
5132 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5133 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5134 m_errorMonitor->VerifyFound();
5135 // Cleanup
5136 vkFreeMemory(m_device->device(), mem, NULL);
5137
5138 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5139 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5140 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5141}
5142
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005143TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
5144 TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid "
5145 "due to a bound descriptor sets with a combined image "
5146 "sampler having their image, sampler, and descriptor set "
5147 "each respectively destroyed and then attempting to "
Mark Mueller917f6bc2016-08-30 10:57:19 -06005148 "submit associated cmd buffers. Attempt to destroy a "
5149 "DescriptorSet that is in use.");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005150 ASSERT_NO_FATAL_FAILURE(InitState());
5151 ASSERT_NO_FATAL_FAILURE(InitViewport());
5152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5153
5154 VkDescriptorPoolSize ds_type_count = {};
5155 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5156 ds_type_count.descriptorCount = 1;
5157
5158 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5159 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5160 ds_pool_ci.pNext = NULL;
5161 ds_pool_ci.maxSets = 1;
5162 ds_pool_ci.poolSizeCount = 1;
5163 ds_pool_ci.pPoolSizes = &ds_type_count;
5164
5165 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005166 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005167 ASSERT_VK_SUCCESS(err);
5168
5169 VkDescriptorSetLayoutBinding dsl_binding = {};
5170 dsl_binding.binding = 0;
5171 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5172 dsl_binding.descriptorCount = 1;
5173 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5174 dsl_binding.pImmutableSamplers = NULL;
5175
5176 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5177 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5178 ds_layout_ci.pNext = NULL;
5179 ds_layout_ci.bindingCount = 1;
5180 ds_layout_ci.pBindings = &dsl_binding;
5181 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005182 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005183 ASSERT_VK_SUCCESS(err);
5184
5185 VkDescriptorSet descriptorSet;
5186 VkDescriptorSetAllocateInfo alloc_info = {};
5187 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5188 alloc_info.descriptorSetCount = 1;
5189 alloc_info.descriptorPool = ds_pool;
5190 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005191 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005192 ASSERT_VK_SUCCESS(err);
5193
5194 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5195 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5196 pipeline_layout_ci.pNext = NULL;
5197 pipeline_layout_ci.setLayoutCount = 1;
5198 pipeline_layout_ci.pSetLayouts = &ds_layout;
5199
5200 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005201 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005202 ASSERT_VK_SUCCESS(err);
5203
5204 // Create images to update the descriptor with
5205 VkImage image;
5206 VkImage image2;
5207 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5208 const int32_t tex_width = 32;
5209 const int32_t tex_height = 32;
5210 VkImageCreateInfo image_create_info = {};
5211 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5212 image_create_info.pNext = NULL;
5213 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5214 image_create_info.format = tex_format;
5215 image_create_info.extent.width = tex_width;
5216 image_create_info.extent.height = tex_height;
5217 image_create_info.extent.depth = 1;
5218 image_create_info.mipLevels = 1;
5219 image_create_info.arrayLayers = 1;
5220 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5221 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5222 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5223 image_create_info.flags = 0;
5224 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5225 ASSERT_VK_SUCCESS(err);
5226 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5227 ASSERT_VK_SUCCESS(err);
5228
5229 VkMemoryRequirements memory_reqs;
5230 VkDeviceMemory image_memory;
5231 bool pass;
5232 VkMemoryAllocateInfo memory_info = {};
5233 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5234 memory_info.pNext = NULL;
5235 memory_info.allocationSize = 0;
5236 memory_info.memoryTypeIndex = 0;
5237 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5238 // Allocate enough memory for both images
5239 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005240 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005241 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005242 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005243 ASSERT_VK_SUCCESS(err);
5244 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5245 ASSERT_VK_SUCCESS(err);
5246 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005247 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005248 ASSERT_VK_SUCCESS(err);
5249
5250 VkImageViewCreateInfo image_view_create_info = {};
5251 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5252 image_view_create_info.image = image;
5253 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5254 image_view_create_info.format = tex_format;
5255 image_view_create_info.subresourceRange.layerCount = 1;
5256 image_view_create_info.subresourceRange.baseMipLevel = 0;
5257 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005258 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005259
5260 VkImageView view;
5261 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005262 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005263 ASSERT_VK_SUCCESS(err);
5264 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005265 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005266 ASSERT_VK_SUCCESS(err);
5267 // Create Samplers
5268 VkSamplerCreateInfo sampler_ci = {};
5269 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5270 sampler_ci.pNext = NULL;
5271 sampler_ci.magFilter = VK_FILTER_NEAREST;
5272 sampler_ci.minFilter = VK_FILTER_NEAREST;
5273 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5274 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5275 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5276 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5277 sampler_ci.mipLodBias = 1.0;
5278 sampler_ci.anisotropyEnable = VK_FALSE;
5279 sampler_ci.maxAnisotropy = 1;
5280 sampler_ci.compareEnable = VK_FALSE;
5281 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5282 sampler_ci.minLod = 1.0;
5283 sampler_ci.maxLod = 1.0;
5284 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5285 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5286 VkSampler sampler;
5287 VkSampler sampler2;
5288 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5289 ASSERT_VK_SUCCESS(err);
5290 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5291 ASSERT_VK_SUCCESS(err);
5292 // Update descriptor with image and sampler
5293 VkDescriptorImageInfo img_info = {};
5294 img_info.sampler = sampler;
5295 img_info.imageView = view;
5296 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5297
5298 VkWriteDescriptorSet descriptor_write;
5299 memset(&descriptor_write, 0, sizeof(descriptor_write));
5300 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5301 descriptor_write.dstSet = descriptorSet;
5302 descriptor_write.dstBinding = 0;
5303 descriptor_write.descriptorCount = 1;
5304 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5305 descriptor_write.pImageInfo = &img_info;
5306
5307 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5308
5309 // Create PSO to be used for draw-time errors below
5310 char const *vsSource = "#version 450\n"
5311 "\n"
5312 "out gl_PerVertex { \n"
5313 " vec4 gl_Position;\n"
5314 "};\n"
5315 "void main(){\n"
5316 " gl_Position = vec4(1);\n"
5317 "}\n";
5318 char const *fsSource = "#version 450\n"
5319 "\n"
5320 "layout(set=0, binding=0) uniform sampler2D s;\n"
5321 "layout(location=0) out vec4 x;\n"
5322 "void main(){\n"
5323 " x = texture(s, vec2(1));\n"
5324 "}\n";
5325 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5326 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5327 VkPipelineObj pipe(m_device);
5328 pipe.AddShader(&vs);
5329 pipe.AddShader(&fs);
5330 pipe.AddColorAttachment();
5331 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5332
5333 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005335 m_commandBuffer->BeginCommandBuffer();
5336 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005337 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5338 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5339 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005340 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5341 VkRect2D scissor = {{0, 0}, {16, 16}};
5342 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5343 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005344 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005345 m_commandBuffer->EndRenderPass();
5346 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005347 // Destroy sampler invalidates the cmd buffer, causing error on submit
5348 vkDestroySampler(m_device->device(), sampler, NULL);
5349 // Attempt to submit cmd buffer
5350 VkSubmitInfo submit_info = {};
5351 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5352 submit_info.commandBufferCount = 1;
5353 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5354 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5355 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005356
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005357 // Now re-update descriptor with valid sampler and delete image
5358 img_info.sampler = sampler2;
5359 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005361 m_commandBuffer->BeginCommandBuffer();
5362 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005363 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5364 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5365 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005366 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5367 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005368 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005369 m_commandBuffer->EndRenderPass();
5370 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005371 // Destroy image invalidates the cmd buffer, causing error on submit
5372 vkDestroyImage(m_device->device(), image, NULL);
5373 // Attempt to submit cmd buffer
5374 submit_info = {};
5375 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5376 submit_info.commandBufferCount = 1;
5377 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5378 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5379 m_errorMonitor->VerifyFound();
5380 // Now update descriptor to be valid, but then free descriptor
5381 img_info.imageView = view2;
5382 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07005383 m_commandBuffer->BeginCommandBuffer();
5384 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005385 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5386 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5387 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005388 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5389 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005390 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005391 m_commandBuffer->EndRenderPass();
5392 m_commandBuffer->EndCommandBuffer();
Dave Houltonfbf52152017-01-06 12:55:29 -07005393
5394 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005396 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005397 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005398
5399 // Try again once the queue is idle - should succeed w/o error
5400 // TODO - thought the particular error above doesn't re-occur, there are other 'unexpecteds' still to clean up
5401 vkQueueWaitIdle(m_device->m_queue);
5402 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5403
5404 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005405 submit_info = {};
5406 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5407 submit_info.commandBufferCount = 1;
5408 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005410 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5411 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005412
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005413 // Cleanup
5414 vkFreeMemory(m_device->device(), image_memory, NULL);
5415 vkDestroySampler(m_device->device(), sampler2, NULL);
5416 vkDestroyImage(m_device->device(), image2, NULL);
5417 vkDestroyImageView(m_device->device(), view, NULL);
5418 vkDestroyImageView(m_device->device(), view2, NULL);
5419 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5420 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5421 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5422}
5423
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005424TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5425 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5426 ASSERT_NO_FATAL_FAILURE(InitState());
5427 ASSERT_NO_FATAL_FAILURE(InitViewport());
5428 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5429
5430 VkDescriptorPoolSize ds_type_count = {};
5431 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5432 ds_type_count.descriptorCount = 1;
5433
5434 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5435 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5436 ds_pool_ci.pNext = NULL;
5437 ds_pool_ci.maxSets = 1;
5438 ds_pool_ci.poolSizeCount = 1;
5439 ds_pool_ci.pPoolSizes = &ds_type_count;
5440
5441 VkDescriptorPool ds_pool;
5442 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5443 ASSERT_VK_SUCCESS(err);
5444
5445 VkDescriptorSetLayoutBinding dsl_binding = {};
5446 dsl_binding.binding = 0;
5447 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5448 dsl_binding.descriptorCount = 1;
5449 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5450 dsl_binding.pImmutableSamplers = NULL;
5451
5452 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5453 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5454 ds_layout_ci.pNext = NULL;
5455 ds_layout_ci.bindingCount = 1;
5456 ds_layout_ci.pBindings = &dsl_binding;
5457 VkDescriptorSetLayout ds_layout;
5458 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5459 ASSERT_VK_SUCCESS(err);
5460
5461 VkDescriptorSet descriptor_set;
5462 VkDescriptorSetAllocateInfo alloc_info = {};
5463 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5464 alloc_info.descriptorSetCount = 1;
5465 alloc_info.descriptorPool = ds_pool;
5466 alloc_info.pSetLayouts = &ds_layout;
5467 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5468 ASSERT_VK_SUCCESS(err);
5469
5470 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5471 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5472 pipeline_layout_ci.pNext = NULL;
5473 pipeline_layout_ci.setLayoutCount = 1;
5474 pipeline_layout_ci.pSetLayouts = &ds_layout;
5475
5476 VkPipelineLayout pipeline_layout;
5477 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5478 ASSERT_VK_SUCCESS(err);
5479
5480 // Create image to update the descriptor with
5481 VkImageObj image(m_device);
5482 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5483 ASSERT_TRUE(image.initialized());
5484
5485 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5486 // Create Sampler
5487 VkSamplerCreateInfo sampler_ci = {};
5488 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5489 sampler_ci.pNext = NULL;
5490 sampler_ci.magFilter = VK_FILTER_NEAREST;
5491 sampler_ci.minFilter = VK_FILTER_NEAREST;
5492 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5493 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5494 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5495 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5496 sampler_ci.mipLodBias = 1.0;
5497 sampler_ci.anisotropyEnable = VK_FALSE;
5498 sampler_ci.maxAnisotropy = 1;
5499 sampler_ci.compareEnable = VK_FALSE;
5500 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5501 sampler_ci.minLod = 1.0;
5502 sampler_ci.maxLod = 1.0;
5503 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5504 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5505 VkSampler sampler;
5506 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5507 ASSERT_VK_SUCCESS(err);
5508 // Update descriptor with image and sampler
5509 VkDescriptorImageInfo img_info = {};
5510 img_info.sampler = sampler;
5511 img_info.imageView = view;
5512 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5513
5514 VkWriteDescriptorSet descriptor_write;
5515 memset(&descriptor_write, 0, sizeof(descriptor_write));
5516 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5517 descriptor_write.dstSet = descriptor_set;
5518 descriptor_write.dstBinding = 0;
5519 descriptor_write.descriptorCount = 1;
5520 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5521 descriptor_write.pImageInfo = &img_info;
5522
5523 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5524
5525 // Create PSO to be used for draw-time errors below
5526 char const *vsSource = "#version 450\n"
5527 "\n"
5528 "out gl_PerVertex { \n"
5529 " vec4 gl_Position;\n"
5530 "};\n"
5531 "void main(){\n"
5532 " gl_Position = vec4(1);\n"
5533 "}\n";
5534 char const *fsSource = "#version 450\n"
5535 "\n"
5536 "layout(set=0, binding=0) uniform sampler2D s;\n"
5537 "layout(location=0) out vec4 x;\n"
5538 "void main(){\n"
5539 " x = texture(s, vec2(1));\n"
5540 "}\n";
5541 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5542 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5543 VkPipelineObj pipe(m_device);
5544 pipe.AddShader(&vs);
5545 pipe.AddShader(&fs);
5546 pipe.AddColorAttachment();
5547 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5548
Tony Barbour552f6c02016-12-21 14:34:07 -07005549 m_commandBuffer->BeginCommandBuffer();
5550 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005551 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5552 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5553 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005554
5555 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5556 VkRect2D scissor = {{0, 0}, {16, 16}};
5557 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5558 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
5559
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005560 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005561 m_commandBuffer->EndRenderPass();
5562 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005563 // Submit cmd buffer to put pool in-flight
5564 VkSubmitInfo submit_info = {};
5565 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5566 submit_info.commandBufferCount = 1;
5567 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5568 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5569 // Destroy pool while in-flight, causing error
5570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5571 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5572 m_errorMonitor->VerifyFound();
5573 vkQueueWaitIdle(m_device->m_queue);
5574 // Cleanup
5575 vkDestroySampler(m_device->device(), sampler, NULL);
5576 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5577 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5578 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005579 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005580}
5581
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005582TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5583 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5584 ASSERT_NO_FATAL_FAILURE(InitState());
5585 ASSERT_NO_FATAL_FAILURE(InitViewport());
5586 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5587
5588 VkDescriptorPoolSize ds_type_count = {};
5589 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5590 ds_type_count.descriptorCount = 1;
5591
5592 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5593 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5594 ds_pool_ci.pNext = NULL;
5595 ds_pool_ci.maxSets = 1;
5596 ds_pool_ci.poolSizeCount = 1;
5597 ds_pool_ci.pPoolSizes = &ds_type_count;
5598
5599 VkDescriptorPool ds_pool;
5600 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5601 ASSERT_VK_SUCCESS(err);
5602
5603 VkDescriptorSetLayoutBinding dsl_binding = {};
5604 dsl_binding.binding = 0;
5605 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5606 dsl_binding.descriptorCount = 1;
5607 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5608 dsl_binding.pImmutableSamplers = NULL;
5609
5610 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5611 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5612 ds_layout_ci.pNext = NULL;
5613 ds_layout_ci.bindingCount = 1;
5614 ds_layout_ci.pBindings = &dsl_binding;
5615 VkDescriptorSetLayout ds_layout;
5616 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5617 ASSERT_VK_SUCCESS(err);
5618
5619 VkDescriptorSet descriptorSet;
5620 VkDescriptorSetAllocateInfo alloc_info = {};
5621 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5622 alloc_info.descriptorSetCount = 1;
5623 alloc_info.descriptorPool = ds_pool;
5624 alloc_info.pSetLayouts = &ds_layout;
5625 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5626 ASSERT_VK_SUCCESS(err);
5627
5628 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5629 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5630 pipeline_layout_ci.pNext = NULL;
5631 pipeline_layout_ci.setLayoutCount = 1;
5632 pipeline_layout_ci.pSetLayouts = &ds_layout;
5633
5634 VkPipelineLayout pipeline_layout;
5635 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5636 ASSERT_VK_SUCCESS(err);
5637
5638 // Create images to update the descriptor with
5639 VkImage image;
5640 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5641 const int32_t tex_width = 32;
5642 const int32_t tex_height = 32;
5643 VkImageCreateInfo image_create_info = {};
5644 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5645 image_create_info.pNext = NULL;
5646 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5647 image_create_info.format = tex_format;
5648 image_create_info.extent.width = tex_width;
5649 image_create_info.extent.height = tex_height;
5650 image_create_info.extent.depth = 1;
5651 image_create_info.mipLevels = 1;
5652 image_create_info.arrayLayers = 1;
5653 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5654 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5655 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5656 image_create_info.flags = 0;
5657 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5658 ASSERT_VK_SUCCESS(err);
5659 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5660 VkMemoryRequirements memory_reqs;
5661 VkDeviceMemory image_memory;
5662 bool pass;
5663 VkMemoryAllocateInfo memory_info = {};
5664 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5665 memory_info.pNext = NULL;
5666 memory_info.allocationSize = 0;
5667 memory_info.memoryTypeIndex = 0;
5668 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5669 // Allocate enough memory for image
5670 memory_info.allocationSize = memory_reqs.size;
5671 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5672 ASSERT_TRUE(pass);
5673 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5674 ASSERT_VK_SUCCESS(err);
5675 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5676 ASSERT_VK_SUCCESS(err);
5677
5678 VkImageViewCreateInfo image_view_create_info = {};
5679 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5680 image_view_create_info.image = image;
5681 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5682 image_view_create_info.format = tex_format;
5683 image_view_create_info.subresourceRange.layerCount = 1;
5684 image_view_create_info.subresourceRange.baseMipLevel = 0;
5685 image_view_create_info.subresourceRange.levelCount = 1;
5686 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5687
5688 VkImageView view;
5689 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5690 ASSERT_VK_SUCCESS(err);
5691 // Create Samplers
5692 VkSamplerCreateInfo sampler_ci = {};
5693 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5694 sampler_ci.pNext = NULL;
5695 sampler_ci.magFilter = VK_FILTER_NEAREST;
5696 sampler_ci.minFilter = VK_FILTER_NEAREST;
5697 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5698 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5699 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5700 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5701 sampler_ci.mipLodBias = 1.0;
5702 sampler_ci.anisotropyEnable = VK_FALSE;
5703 sampler_ci.maxAnisotropy = 1;
5704 sampler_ci.compareEnable = VK_FALSE;
5705 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5706 sampler_ci.minLod = 1.0;
5707 sampler_ci.maxLod = 1.0;
5708 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5709 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5710 VkSampler sampler;
5711 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5712 ASSERT_VK_SUCCESS(err);
5713 // Update descriptor with image and sampler
5714 VkDescriptorImageInfo img_info = {};
5715 img_info.sampler = sampler;
5716 img_info.imageView = view;
5717 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5718
5719 VkWriteDescriptorSet descriptor_write;
5720 memset(&descriptor_write, 0, sizeof(descriptor_write));
5721 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5722 descriptor_write.dstSet = descriptorSet;
5723 descriptor_write.dstBinding = 0;
5724 descriptor_write.descriptorCount = 1;
5725 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5726 descriptor_write.pImageInfo = &img_info;
5727 // Break memory binding and attempt update
5728 vkFreeMemory(m_device->device(), image_memory, nullptr);
5729 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005730 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5732 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5733 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5734 m_errorMonitor->VerifyFound();
5735 // Cleanup
5736 vkDestroyImage(m_device->device(), image, NULL);
5737 vkDestroySampler(m_device->device(), sampler, NULL);
5738 vkDestroyImageView(m_device->device(), view, NULL);
5739 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5740 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5741 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5742}
5743
Karl Schultz6addd812016-02-02 17:17:23 -07005744TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005745 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5746 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005747 // Create a valid cmd buffer
5748 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005749 uint64_t fake_pipeline_handle = 0xbaad6001;
5750 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005751 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5753
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005755 m_commandBuffer->BeginCommandBuffer();
5756 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005757 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005758 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005759
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005760 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005761 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 -06005762 Draw(1, 0, 0, 0);
5763 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005764
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005765 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005767 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005768 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5769 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005770}
5771
Karl Schultz6addd812016-02-02 17:17:23 -07005772TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005773 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005774 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005775
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005777
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005778 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005779 ASSERT_NO_FATAL_FAILURE(InitViewport());
5780 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005781 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005782 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5783 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005784
5785 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005786 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5787 ds_pool_ci.pNext = NULL;
5788 ds_pool_ci.maxSets = 1;
5789 ds_pool_ci.poolSizeCount = 1;
5790 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005791
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005792 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005794 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005795
Tony Barboureb254902015-07-15 12:50:33 -06005796 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005797 dsl_binding.binding = 0;
5798 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5799 dsl_binding.descriptorCount = 1;
5800 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5801 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005802
Tony Barboureb254902015-07-15 12:50:33 -06005803 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005804 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5805 ds_layout_ci.pNext = NULL;
5806 ds_layout_ci.bindingCount = 1;
5807 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005808 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005809 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005810 ASSERT_VK_SUCCESS(err);
5811
5812 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08005813 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005814 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005815 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06005816 alloc_info.descriptorPool = ds_pool;
5817 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005818 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005819 ASSERT_VK_SUCCESS(err);
5820
Tony Barboureb254902015-07-15 12:50:33 -06005821 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005822 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5823 pipeline_layout_ci.pNext = NULL;
5824 pipeline_layout_ci.setLayoutCount = 1;
5825 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005826
5827 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005828 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005829 ASSERT_VK_SUCCESS(err);
5830
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005831 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06005832 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07005833 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005834 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005835
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005836 VkPipelineObj pipe(m_device);
5837 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06005838 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06005839 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06005840 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06005841
Tony Barbour552f6c02016-12-21 14:34:07 -07005842 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005843 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5844 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5845 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005846
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005847 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06005848
Chia-I Wuf7458c52015-10-26 21:10:41 +08005849 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5851 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06005852}
5853
Karl Schultz6addd812016-02-02 17:17:23 -07005854TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005855 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07005856 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005857
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005859
5860 ASSERT_NO_FATAL_FAILURE(InitState());
5861 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005862 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5863 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005864
5865 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005866 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5867 ds_pool_ci.pNext = NULL;
5868 ds_pool_ci.maxSets = 1;
5869 ds_pool_ci.poolSizeCount = 1;
5870 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005871
5872 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005873 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005874 ASSERT_VK_SUCCESS(err);
5875
5876 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005877 dsl_binding.binding = 0;
5878 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5879 dsl_binding.descriptorCount = 1;
5880 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5881 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005882
5883 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005884 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5885 ds_layout_ci.pNext = NULL;
5886 ds_layout_ci.bindingCount = 1;
5887 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005888 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005889 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005890 ASSERT_VK_SUCCESS(err);
5891
5892 VkDescriptorSet descriptorSet;
5893 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08005894 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07005895 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005896 alloc_info.descriptorPool = ds_pool;
5897 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005898 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005899 ASSERT_VK_SUCCESS(err);
5900
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005901 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005902 VkWriteDescriptorSet descriptor_write;
5903 memset(&descriptor_write, 0, sizeof(descriptor_write));
5904 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5905 descriptor_write.dstSet = descriptorSet;
5906 descriptor_write.dstBinding = 0;
5907 descriptor_write.descriptorCount = 1;
5908 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
5909 descriptor_write.pTexelBufferView = &view;
5910
5911 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5912
Chris Forbes8f36a8a2016-04-07 13:21:07 +12005913 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07005914
5915 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5916 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5917}
5918
Mark Youngd339ba32016-05-30 13:28:35 -06005919TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005920 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 -06005921
5922 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005924 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06005925
5926 ASSERT_NO_FATAL_FAILURE(InitState());
5927
5928 // Create a buffer with no bound memory and then attempt to create
5929 // a buffer view.
5930 VkBufferCreateInfo buff_ci = {};
5931 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12005932 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06005933 buff_ci.size = 256;
5934 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5935 VkBuffer buffer;
5936 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
5937 ASSERT_VK_SUCCESS(err);
5938
5939 VkBufferViewCreateInfo buff_view_ci = {};
5940 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
5941 buff_view_ci.buffer = buffer;
5942 buff_view_ci.format = VK_FORMAT_R8_UNORM;
5943 buff_view_ci.range = VK_WHOLE_SIZE;
5944 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005945 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06005946
5947 m_errorMonitor->VerifyFound();
5948 vkDestroyBuffer(m_device->device(), buffer, NULL);
5949 // If last error is success, it still created the view, so delete it.
5950 if (err == VK_SUCCESS) {
5951 vkDestroyBufferView(m_device->device(), buff_view, NULL);
5952 }
5953}
5954
Karl Schultz6addd812016-02-02 17:17:23 -07005955TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
5956 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
5957 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07005958 // 1. No dynamicOffset supplied
5959 // 2. Too many dynamicOffsets supplied
5960 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07005961 VkResult err;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " requires 1 dynamicOffsets, but only "
5963 "0 dynamicOffsets are left in "
5964 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005965
5966 ASSERT_NO_FATAL_FAILURE(InitState());
5967 ASSERT_NO_FATAL_FAILURE(InitViewport());
5968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5969
5970 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005971 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5972 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005973
5974 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005975 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5976 ds_pool_ci.pNext = NULL;
5977 ds_pool_ci.maxSets = 1;
5978 ds_pool_ci.poolSizeCount = 1;
5979 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005980
5981 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005982 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005983 ASSERT_VK_SUCCESS(err);
5984
5985 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005986 dsl_binding.binding = 0;
5987 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
5988 dsl_binding.descriptorCount = 1;
5989 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5990 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005991
5992 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005993 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5994 ds_layout_ci.pNext = NULL;
5995 ds_layout_ci.bindingCount = 1;
5996 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005997 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005998 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07005999 ASSERT_VK_SUCCESS(err);
6000
6001 VkDescriptorSet descriptorSet;
6002 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006003 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006004 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006005 alloc_info.descriptorPool = ds_pool;
6006 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006007 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006008 ASSERT_VK_SUCCESS(err);
6009
6010 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006011 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6012 pipeline_layout_ci.pNext = NULL;
6013 pipeline_layout_ci.setLayoutCount = 1;
6014 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006015
6016 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006017 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006018 ASSERT_VK_SUCCESS(err);
6019
6020 // Create a buffer to update the descriptor with
6021 uint32_t qfi = 0;
6022 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006023 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6024 buffCI.size = 1024;
6025 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6026 buffCI.queueFamilyIndexCount = 1;
6027 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006028
6029 VkBuffer dyub;
6030 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6031 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006032 // Allocate memory and bind to buffer so we can make it to the appropriate
6033 // error
6034 VkMemoryAllocateInfo mem_alloc = {};
6035 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6036 mem_alloc.pNext = NULL;
6037 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006038 mem_alloc.memoryTypeIndex = 0;
6039
6040 VkMemoryRequirements memReqs;
6041 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006042 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006043 if (!pass) {
6044 vkDestroyBuffer(m_device->device(), dyub, NULL);
6045 return;
6046 }
6047
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006048 VkDeviceMemory mem;
6049 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6050 ASSERT_VK_SUCCESS(err);
6051 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6052 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006053 // Correctly update descriptor to avoid "NOT_UPDATED" error
6054 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006055 buffInfo.buffer = dyub;
6056 buffInfo.offset = 0;
6057 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006058
6059 VkWriteDescriptorSet descriptor_write;
6060 memset(&descriptor_write, 0, sizeof(descriptor_write));
6061 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6062 descriptor_write.dstSet = descriptorSet;
6063 descriptor_write.dstBinding = 0;
6064 descriptor_write.descriptorCount = 1;
6065 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6066 descriptor_write.pBufferInfo = &buffInfo;
6067
6068 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6069
Tony Barbour552f6c02016-12-21 14:34:07 -07006070 m_commandBuffer->BeginCommandBuffer();
6071 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006072 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6073 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006074 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006075 uint32_t pDynOff[2] = {512, 756};
6076 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6078 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6079 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6080 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006081 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006082 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " dynamic offset 512 combined with "
6084 "offset 0 and range 1024 that "
6085 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006086 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006087 char const *vsSource = "#version 450\n"
6088 "\n"
6089 "out gl_PerVertex { \n"
6090 " vec4 gl_Position;\n"
6091 "};\n"
6092 "void main(){\n"
6093 " gl_Position = vec4(1);\n"
6094 "}\n";
6095 char const *fsSource = "#version 450\n"
6096 "\n"
6097 "layout(location=0) out vec4 x;\n"
6098 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6099 "void main(){\n"
6100 " x = vec4(bar.y);\n"
6101 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006102 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6103 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6104 VkPipelineObj pipe(m_device);
6105 pipe.AddShader(&vs);
6106 pipe.AddShader(&fs);
6107 pipe.AddColorAttachment();
6108 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6109
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006110 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6111 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6112 VkRect2D scissor = {{0, 0}, {16, 16}};
6113 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6114
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006115 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006116 // This update should succeed, but offset size of 512 will overstep buffer
6117 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006118 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6119 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006120 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006121 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006122
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006123 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006124 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006125
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006126 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006127 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006128 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6129}
6130
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006131TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
6132 TEST_DESCRIPTION("Attempt to update a descriptor with a non-sparse buffer "
6133 "that doesn't have memory bound");
6134 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006136 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6138 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006139
6140 ASSERT_NO_FATAL_FAILURE(InitState());
6141 ASSERT_NO_FATAL_FAILURE(InitViewport());
6142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6143
6144 VkDescriptorPoolSize ds_type_count = {};
6145 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6146 ds_type_count.descriptorCount = 1;
6147
6148 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6149 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6150 ds_pool_ci.pNext = NULL;
6151 ds_pool_ci.maxSets = 1;
6152 ds_pool_ci.poolSizeCount = 1;
6153 ds_pool_ci.pPoolSizes = &ds_type_count;
6154
6155 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006156 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006157 ASSERT_VK_SUCCESS(err);
6158
6159 VkDescriptorSetLayoutBinding dsl_binding = {};
6160 dsl_binding.binding = 0;
6161 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6162 dsl_binding.descriptorCount = 1;
6163 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6164 dsl_binding.pImmutableSamplers = NULL;
6165
6166 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6167 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6168 ds_layout_ci.pNext = NULL;
6169 ds_layout_ci.bindingCount = 1;
6170 ds_layout_ci.pBindings = &dsl_binding;
6171 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006172 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006173 ASSERT_VK_SUCCESS(err);
6174
6175 VkDescriptorSet descriptorSet;
6176 VkDescriptorSetAllocateInfo alloc_info = {};
6177 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6178 alloc_info.descriptorSetCount = 1;
6179 alloc_info.descriptorPool = ds_pool;
6180 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006181 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006182 ASSERT_VK_SUCCESS(err);
6183
6184 // Create a buffer to update the descriptor with
6185 uint32_t qfi = 0;
6186 VkBufferCreateInfo buffCI = {};
6187 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6188 buffCI.size = 1024;
6189 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6190 buffCI.queueFamilyIndexCount = 1;
6191 buffCI.pQueueFamilyIndices = &qfi;
6192
6193 VkBuffer dyub;
6194 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6195 ASSERT_VK_SUCCESS(err);
6196
6197 // Attempt to update descriptor without binding memory to it
6198 VkDescriptorBufferInfo buffInfo = {};
6199 buffInfo.buffer = dyub;
6200 buffInfo.offset = 0;
6201 buffInfo.range = 1024;
6202
6203 VkWriteDescriptorSet descriptor_write;
6204 memset(&descriptor_write, 0, sizeof(descriptor_write));
6205 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6206 descriptor_write.dstSet = descriptorSet;
6207 descriptor_write.dstBinding = 0;
6208 descriptor_write.descriptorCount = 1;
6209 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6210 descriptor_write.pBufferInfo = &buffInfo;
6211
6212 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6213 m_errorMonitor->VerifyFound();
6214
6215 vkDestroyBuffer(m_device->device(), dyub, NULL);
6216 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6217 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6218}
6219
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006220TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006221 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006222 ASSERT_NO_FATAL_FAILURE(InitState());
6223 ASSERT_NO_FATAL_FAILURE(InitViewport());
6224 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6225
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006226 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006227 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006228 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6229 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6230 pipeline_layout_ci.pushConstantRangeCount = 1;
6231 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6232
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006233 //
6234 // Check for invalid push constant ranges in pipeline layouts.
6235 //
6236 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006237 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006238 char const *msg;
6239 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006240
Karl Schultzc81037d2016-05-12 08:11:23 -06006241 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6242 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6243 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6244 "vkCreatePipelineLayout() call has push constants index 0 with "
6245 "size 0."},
6246 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6247 "vkCreatePipelineLayout() call has push constants index 0 with "
6248 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006249 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006250 "vkCreatePipelineLayout() call has push constants index 0 with "
6251 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006252 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006253 "vkCreatePipelineLayout() call has push constants index 0 with "
6254 "size 0."},
6255 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6256 "vkCreatePipelineLayout() call has push constants index 0 with "
6257 "offset 1. Offset must"},
6258 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6259 "vkCreatePipelineLayout() call has push constants index 0 "
6260 "with offset "},
6261 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6262 "vkCreatePipelineLayout() call has push constants "
6263 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006264 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006265 "vkCreatePipelineLayout() call has push constants index 0 "
6266 "with offset "},
6267 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6268 "vkCreatePipelineLayout() call has push "
6269 "constants index 0 with offset "},
6270 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6271 "vkCreatePipelineLayout() call has push "
6272 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006273 }};
6274
6275 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006276 for (const auto &iter : range_tests) {
6277 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6279 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006280 m_errorMonitor->VerifyFound();
6281 if (VK_SUCCESS == err) {
6282 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6283 }
6284 }
6285
6286 // Check for invalid stage flag
6287 pc_range.offset = 0;
6288 pc_range.size = 16;
6289 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006290 m_errorMonitor->SetDesiredFailureMsg(
6291 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6292 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006293 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006294 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006295 if (VK_SUCCESS == err) {
6296 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6297 }
6298
6299 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006300 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006301 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006302 VkPushConstantRange const ranges[ranges_per_test];
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006303 char const *msg;
6304 };
6305
Karl Schultzc81037d2016-05-12 08:11:23 -06006306 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006307 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6308 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6309 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6310 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6311 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006312 "vkCreatePipelineLayout() call has push constants with overlapping ranges:"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006313 {
6314 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6315 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6316 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6317 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6318 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006319 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006320 },
6321 {
6322 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6323 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6324 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6325 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6326 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006327 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006328 },
6329 {
6330 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6331 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6332 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6333 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6334 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006335 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006336 },
6337 {
6338 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6339 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6340 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6341 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6342 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006343 "vkCreatePipelineLayout() call has push constants with overlapping ranges:",
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006344 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006345
Karl Schultzc81037d2016-05-12 08:11:23 -06006346 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006347 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006348 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg);
6350 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006351 m_errorMonitor->VerifyFound();
6352 if (VK_SUCCESS == err) {
6353 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6354 }
6355 }
6356
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006357 //
6358 // CmdPushConstants tests
6359 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006360 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006361
6362 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006363 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6364 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006365 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006366 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6367 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006368 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006369 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6370 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006371 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006372 "vkCmdPushConstants() call has push constants with offset 1. "
6373 "Offset must be a multiple of 4."},
6374 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6375 "vkCmdPushConstants() call has push constants with offset 1. "
6376 "Offset must be a multiple of 4."},
6377 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6378 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6379 "0x1 not within flag-matching ranges in pipeline layout"},
6380 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6381 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6382 "0x1 not within flag-matching ranges in pipeline layout"},
6383 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6384 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6385 "0x1 not within flag-matching ranges in pipeline layout"},
6386 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6387 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6388 "0x1 not within flag-matching ranges in pipeline layout"},
6389 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6390 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6391 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006392 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006393 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6394 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006395 }};
6396
Tony Barbour552f6c02016-12-21 14:34:07 -07006397 m_commandBuffer->BeginCommandBuffer();
6398 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006399
6400 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006401 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006402 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006403 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006404 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006405 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006406 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006407 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006408 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6410 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006411 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006412 m_errorMonitor->VerifyFound();
6413 }
6414
6415 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006417 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006418 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006419 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006420
Karl Schultzc81037d2016-05-12 08:11:23 -06006421 // overlapping range tests with cmd
6422 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6423 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6424 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6425 "0x1 not within flag-matching ranges in pipeline layout"},
6426 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6427 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6428 "0x1 not within flag-matching ranges in pipeline layout"},
6429 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6430 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6431 "0x1 not within flag-matching ranges in pipeline layout"},
6432 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006433 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006434 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006435 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6436 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006437 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006439 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006440 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006441 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006442 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6444 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006445 iter.range.size, dummy_values);
6446 m_errorMonitor->VerifyFound();
6447 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006448 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6449
Tony Barbour552f6c02016-12-21 14:34:07 -07006450 m_commandBuffer->EndRenderPass();
6451 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006452}
6453
Karl Schultz6addd812016-02-02 17:17:23 -07006454TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006455 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006456 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006457
6458 ASSERT_NO_FATAL_FAILURE(InitState());
6459 ASSERT_NO_FATAL_FAILURE(InitViewport());
6460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6461
Mike Stroyanb8a61002016-06-20 16:00:28 -06006462 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
6463 VkImageTiling tiling;
6464 VkFormatProperties format_properties;
6465 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006466 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006467 tiling = VK_IMAGE_TILING_LINEAR;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006468 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
Mike Stroyanb8a61002016-06-20 16:00:28 -06006469 tiling = VK_IMAGE_TILING_OPTIMAL;
6470 } else {
6471 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
6472 "skipped.\n");
6473 return;
6474 }
6475
Tobin Ehlis559c6382015-11-05 09:52:49 -07006476 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6477 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006478 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6479 ds_type_count[0].descriptorCount = 10;
6480 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6481 ds_type_count[1].descriptorCount = 2;
6482 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6483 ds_type_count[2].descriptorCount = 2;
6484 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6485 ds_type_count[3].descriptorCount = 5;
6486 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6487 // type
6488 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6489 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6490 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006491
6492 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006493 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6494 ds_pool_ci.pNext = NULL;
6495 ds_pool_ci.maxSets = 5;
6496 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6497 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006498
6499 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006500 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006501 ASSERT_VK_SUCCESS(err);
6502
6503 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6504 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006505 dsl_binding[0].binding = 0;
6506 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6507 dsl_binding[0].descriptorCount = 5;
6508 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6509 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006510
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006511 // Create layout identical to set0 layout but w/ different stageFlags
6512 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006513 dsl_fs_stage_only.binding = 0;
6514 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6515 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006516 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6517 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006518 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006519 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006520 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6521 ds_layout_ci.pNext = NULL;
6522 ds_layout_ci.bindingCount = 1;
6523 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006524 static const uint32_t NUM_LAYOUTS = 4;
6525 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006526 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006527 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6528 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006529 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006530 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006531 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006532 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006533 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006534 dsl_binding[0].binding = 0;
6535 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006536 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006537 dsl_binding[1].binding = 1;
6538 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6539 dsl_binding[1].descriptorCount = 2;
6540 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6541 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006542 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006543 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006544 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006545 ASSERT_VK_SUCCESS(err);
6546 dsl_binding[0].binding = 0;
6547 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006548 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006549 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006550 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006551 ASSERT_VK_SUCCESS(err);
6552 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006553 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006554 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006555 ASSERT_VK_SUCCESS(err);
6556
6557 static const uint32_t NUM_SETS = 4;
6558 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6559 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006560 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006561 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006562 alloc_info.descriptorPool = ds_pool;
6563 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006564 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006565 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006566 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006567 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006568 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006569 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006570 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006571
6572 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006573 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6574 pipeline_layout_ci.pNext = NULL;
6575 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6576 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006577
6578 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006579 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006580 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006581 // Create pipelineLayout with only one setLayout
6582 pipeline_layout_ci.setLayoutCount = 1;
6583 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006584 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006585 ASSERT_VK_SUCCESS(err);
6586 // Create pipelineLayout with 2 descriptor setLayout at index 0
6587 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6588 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006589 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006590 ASSERT_VK_SUCCESS(err);
6591 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6592 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6593 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006594 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006595 ASSERT_VK_SUCCESS(err);
6596 // Create pipelineLayout with UB type, but stageFlags for FS only
6597 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6598 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006599 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006600 ASSERT_VK_SUCCESS(err);
6601 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6602 VkDescriptorSetLayout pl_bad_s0[2] = {};
6603 pl_bad_s0[0] = ds_layout_fs_only;
6604 pl_bad_s0[1] = ds_layout[1];
6605 pipeline_layout_ci.setLayoutCount = 2;
6606 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6607 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006608 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006609 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006610
6611 // Create a buffer to update the descriptor with
6612 uint32_t qfi = 0;
6613 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006614 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6615 buffCI.size = 1024;
6616 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6617 buffCI.queueFamilyIndexCount = 1;
6618 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006619
6620 VkBuffer dyub;
6621 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6622 ASSERT_VK_SUCCESS(err);
6623 // Correctly update descriptor to avoid "NOT_UPDATED" error
6624 static const uint32_t NUM_BUFFS = 5;
6625 VkDescriptorBufferInfo buffInfo[NUM_BUFFS] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006626 for (uint32_t i = 0; i < NUM_BUFFS; ++i) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006627 buffInfo[i].buffer = dyub;
6628 buffInfo[i].offset = 0;
6629 buffInfo[i].range = 1024;
6630 }
Karl Schultz6addd812016-02-02 17:17:23 -07006631 VkImage image;
Karl Schultz6addd812016-02-02 17:17:23 -07006632 const int32_t tex_width = 32;
6633 const int32_t tex_height = 32;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006634 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006635 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6636 image_create_info.pNext = NULL;
6637 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6638 image_create_info.format = tex_format;
6639 image_create_info.extent.width = tex_width;
6640 image_create_info.extent.height = tex_height;
6641 image_create_info.extent.depth = 1;
6642 image_create_info.mipLevels = 1;
6643 image_create_info.arrayLayers = 1;
6644 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyanb8a61002016-06-20 16:00:28 -06006645 image_create_info.tiling = tiling;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006646 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -07006647 image_create_info.flags = 0;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006648 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6649 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006650
Karl Schultz6addd812016-02-02 17:17:23 -07006651 VkMemoryRequirements memReqs;
6652 VkDeviceMemory imageMem;
6653 bool pass;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006654 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006655 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6656 memAlloc.pNext = NULL;
6657 memAlloc.allocationSize = 0;
6658 memAlloc.memoryTypeIndex = 0;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006659 vkGetImageMemoryRequirements(m_device->device(), image, &memReqs);
6660 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006661 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006662 ASSERT_TRUE(pass);
6663 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &imageMem);
6664 ASSERT_VK_SUCCESS(err);
6665 err = vkBindImageMemory(m_device->device(), image, imageMem, 0);
6666 ASSERT_VK_SUCCESS(err);
6667
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006668 VkImageViewCreateInfo image_view_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006669 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6670 image_view_create_info.image = image;
6671 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6672 image_view_create_info.format = tex_format;
6673 image_view_create_info.subresourceRange.layerCount = 1;
6674 image_view_create_info.subresourceRange.baseMipLevel = 0;
6675 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006676 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006677
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006678 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006679 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006680 ASSERT_VK_SUCCESS(err);
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006681 VkDescriptorImageInfo imageInfo[4] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006682 imageInfo[0].imageView = view;
6683 imageInfo[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6684 imageInfo[1].imageView = view;
6685 imageInfo[1].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006686 imageInfo[2].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006687 imageInfo[2].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006688 imageInfo[3].imageView = view;
Tobin Ehlisa1fccbc2016-10-10 14:54:43 -06006689 imageInfo[3].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006690
6691 static const uint32_t NUM_SET_UPDATES = 3;
6692 VkWriteDescriptorSet descriptor_write[NUM_SET_UPDATES] = {};
6693 descriptor_write[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6694 descriptor_write[0].dstSet = descriptorSet[0];
6695 descriptor_write[0].dstBinding = 0;
6696 descriptor_write[0].descriptorCount = 5;
6697 descriptor_write[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6698 descriptor_write[0].pBufferInfo = buffInfo;
6699 descriptor_write[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6700 descriptor_write[1].dstSet = descriptorSet[1];
6701 descriptor_write[1].dstBinding = 0;
6702 descriptor_write[1].descriptorCount = 2;
6703 descriptor_write[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6704 descriptor_write[1].pImageInfo = imageInfo;
6705 descriptor_write[2].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6706 descriptor_write[2].dstSet = descriptorSet[1];
6707 descriptor_write[2].dstBinding = 1;
6708 descriptor_write[2].descriptorCount = 2;
6709 descriptor_write[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006710 descriptor_write[2].pImageInfo = &imageInfo[2];
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006711
6712 vkUpdateDescriptorSets(m_device->device(), 3, descriptor_write, 0, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006713
Tobin Ehlis88452832015-12-03 09:40:56 -07006714 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006715 char const *vsSource = "#version 450\n"
6716 "\n"
6717 "out gl_PerVertex {\n"
6718 " vec4 gl_Position;\n"
6719 "};\n"
6720 "void main(){\n"
6721 " gl_Position = vec4(1);\n"
6722 "}\n";
6723 char const *fsSource = "#version 450\n"
6724 "\n"
6725 "layout(location=0) out vec4 x;\n"
6726 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6727 "void main(){\n"
6728 " x = vec4(bar.y);\n"
6729 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006730 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6731 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006732 VkPipelineObj pipe(m_device);
6733 pipe.AddShader(&vs);
6734 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006735 pipe.AddColorAttachment();
6736 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006737
Tony Barbour552f6c02016-12-21 14:34:07 -07006738 m_commandBuffer->BeginCommandBuffer();
6739 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006741 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006742 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6743 // of PSO
6744 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6745 // cmd_pipeline.c
6746 // due to the fact that cmd_alloc_dset_data() has not been called in
6747 // cmd_bind_graphics_pipeline()
6748 // TODO : Want to cause various binding incompatibility issues here to test
6749 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006750 // First cause various verify_layout_compatibility() fails
6751 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006752 // verify_set_layout_compatibility fail cases:
6753 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006755 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6756 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006757 m_errorMonitor->VerifyFound();
6758
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006759 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006760 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6761 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6762 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006763 m_errorMonitor->VerifyFound();
6764
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006765 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006766 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6767 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6769 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6770 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006771 m_errorMonitor->VerifyFound();
6772
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006773 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6774 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6776 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6777 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006778 m_errorMonitor->VerifyFound();
6779
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006780 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6781 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6783 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6784 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6785 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006786 m_errorMonitor->VerifyFound();
6787
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006788 // Cause INFO messages due to disturbing previously bound Sets
6789 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006790 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6791 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006792 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6794 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6795 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006796 m_errorMonitor->VerifyFound();
6797
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006798 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6799 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006800 // 2. Disturb set after last bound set
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " newly bound as set #0 so set #1 and "
6802 "any subsequent sets were disturbed ");
6803 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6804 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006805 m_errorMonitor->VerifyFound();
6806
Tobin Ehlis10fad692016-07-07 12:00:36 -06006807 // Now that we're done actively using the pipelineLayout that gfx pipeline
6808 // was created with, we should be able to delete it. Do that now to verify
6809 // that validation obeys pipelineLayout lifetime
6810 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6811
Tobin Ehlis88452832015-12-03 09:40:56 -07006812 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006813 // 1. Error due to not binding required set (we actually use same code as
6814 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006815 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6816 &descriptorSet[0], 0, NULL);
6817 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6818 &descriptorSet[1], 0, NULL);
6819 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 -07006820
6821 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6822 VkRect2D scissor = {{0, 0}, {16, 16}};
6823 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6824 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6825
Tobin Ehlis88452832015-12-03 09:40:56 -07006826 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006827 m_errorMonitor->VerifyFound();
6828
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006829 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006830 // 2. Error due to bound set not being compatible with PSO's
6831 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006832 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6833 &descriptorSet[0], 0, NULL);
6834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006835 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006836 m_errorMonitor->VerifyFound();
6837
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006838 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006839 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6841 }
6842 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006843 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006844 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6845 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006846 vkFreeMemory(m_device->device(), imageMem, NULL);
6847 vkDestroyImage(m_device->device(), image, NULL);
6848 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006849}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006850
Karl Schultz6addd812016-02-02 17:17:23 -07006851TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006852
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6854 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006855
6856 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006857 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006858 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006859 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006860
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006861 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006862}
6863
Karl Schultz6addd812016-02-02 17:17:23 -07006864TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6865 VkResult err;
6866 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006867
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006869
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006870 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006871
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006872 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006873 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006874 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006875 cmd.commandPool = m_commandPool;
6876 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006877 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006878
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006879 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006880 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006881
6882 // Force the failure by not setting the Renderpass and Framebuffer fields
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006883 VkCommandBufferBeginInfo cmd_buf_info = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006884 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006885 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006886 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006887 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 -07006888 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006889
6890 // The error should be caught by validation of the BeginCommandBuffer call
6891 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6892
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006893 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006894 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006895}
6896
Karl Schultz6addd812016-02-02 17:17:23 -07006897TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006898 // Cause error due to Begin while recording CB
6899 // Then cause 2 errors for attempting to reset CB w/o having
6900 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
6901 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06006902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006903
6904 ASSERT_NO_FATAL_FAILURE(InitState());
6905
6906 // Calls AllocateCommandBuffers
6907 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
6908
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006909 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07006910 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006911 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6912 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006913 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
6914 cmd_buf_info.pNext = NULL;
6915 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006916 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006917
6918 // Begin CB to transition to recording state
6919 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
6920 // Can't re-begin. This should trigger error
6921 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006922 m_errorMonitor->VerifyFound();
6923
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006925 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
6926 // Reset attempt will trigger error due to incorrect CommandPool state
6927 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006928 m_errorMonitor->VerifyFound();
6929
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07006930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006931 // Transition CB to RECORDED state
6932 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
6933 // Now attempting to Begin will implicitly reset, which triggers error
6934 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006935 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07006936}
6937
Karl Schultz6addd812016-02-02 17:17:23 -07006938TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006939 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07006940 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006941
Mike Weiblencce7ec72016-10-17 19:33:05 -06006942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006943
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006944 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06006945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006946
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006947 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006948 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6949 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006950
6951 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006952 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6953 ds_pool_ci.pNext = NULL;
6954 ds_pool_ci.maxSets = 1;
6955 ds_pool_ci.poolSizeCount = 1;
6956 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06006957
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006958 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006959 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006960 ASSERT_VK_SUCCESS(err);
6961
Tony Barboureb254902015-07-15 12:50:33 -06006962 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006963 dsl_binding.binding = 0;
6964 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6965 dsl_binding.descriptorCount = 1;
6966 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6967 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006968
Tony Barboureb254902015-07-15 12:50:33 -06006969 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006970 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6971 ds_layout_ci.pNext = NULL;
6972 ds_layout_ci.bindingCount = 1;
6973 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06006974
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006975 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006976 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006977 ASSERT_VK_SUCCESS(err);
6978
6979 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006980 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006981 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006982 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006983 alloc_info.descriptorPool = ds_pool;
6984 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006985 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006986 ASSERT_VK_SUCCESS(err);
6987
Tony Barboureb254902015-07-15 12:50:33 -06006988 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006989 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6990 pipeline_layout_ci.setLayoutCount = 1;
6991 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006992
6993 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006994 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006995 ASSERT_VK_SUCCESS(err);
6996
Tobin Ehlise68360f2015-10-01 11:15:13 -06006997 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07006998 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06006999
7000 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007001 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7002 vp_state_ci.scissorCount = 1;
7003 vp_state_ci.pScissors = &sc;
7004 vp_state_ci.viewportCount = 1;
7005 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007006
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007007 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7008 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7009 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7010 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7011 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7012 rs_state_ci.depthClampEnable = VK_FALSE;
7013 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7014 rs_state_ci.depthBiasEnable = VK_FALSE;
7015
Tony Barboureb254902015-07-15 12:50:33 -06007016 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007017 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7018 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007019 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007020 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7021 gp_ci.layout = pipeline_layout;
7022 gp_ci.renderPass = renderPass();
Tony Barboureb254902015-07-15 12:50:33 -06007023
7024 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007025 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7026 pc_ci.initialDataSize = 0;
7027 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007028
7029 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007030 VkPipelineCache pipelineCache;
7031
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007032 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007033 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007034 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06007035
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007036 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007037
Chia-I Wuf7458c52015-10-26 21:10:41 +08007038 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7039 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7040 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7041 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007042}
Tobin Ehlis912df022015-09-17 08:46:18 -06007043/*// TODO : This test should be good, but needs Tess support in compiler to run
7044TEST_F(VkLayerTest, InvalidPatchControlPoints)
7045{
7046 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007047 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007048
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007049 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007050 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7051primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007052
Tobin Ehlis912df022015-09-17 08:46:18 -06007053 ASSERT_NO_FATAL_FAILURE(InitState());
7054 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007055
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007056 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007057 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007058 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007059
7060 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7061 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7062 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007063 ds_pool_ci.poolSizeCount = 1;
7064 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007065
7066 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007067 err = vkCreateDescriptorPool(m_device->device(),
7068VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007069 ASSERT_VK_SUCCESS(err);
7070
7071 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007072 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007073 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007074 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007075 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7076 dsl_binding.pImmutableSamplers = NULL;
7077
7078 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007079 ds_layout_ci.sType =
7080VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007081 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007082 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007083 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007084
7085 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007086 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7087&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007088 ASSERT_VK_SUCCESS(err);
7089
7090 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007091 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7092VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007093 ASSERT_VK_SUCCESS(err);
7094
7095 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007096 pipeline_layout_ci.sType =
7097VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007098 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007099 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007100 pipeline_layout_ci.pSetLayouts = &ds_layout;
7101
7102 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007103 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7104&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007105 ASSERT_VK_SUCCESS(err);
7106
7107 VkPipelineShaderStageCreateInfo shaderStages[3];
7108 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7109
Karl Schultz6addd812016-02-02 17:17:23 -07007110 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7111this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007112 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007113 VkShaderObj
7114tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7115this);
7116 VkShaderObj
7117te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7118this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007119
Karl Schultz6addd812016-02-02 17:17:23 -07007120 shaderStages[0].sType =
7121VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007122 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007123 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007124 shaderStages[1].sType =
7125VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007126 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007127 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007128 shaderStages[2].sType =
7129VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007130 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007131 shaderStages[2].shader = te.handle();
7132
7133 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007134 iaCI.sType =
7135VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007136 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007137
7138 VkPipelineTessellationStateCreateInfo tsCI = {};
7139 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7140 tsCI.patchControlPoints = 0; // This will cause an error
7141
7142 VkGraphicsPipelineCreateInfo gp_ci = {};
7143 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7144 gp_ci.pNext = NULL;
7145 gp_ci.stageCount = 3;
7146 gp_ci.pStages = shaderStages;
7147 gp_ci.pVertexInputState = NULL;
7148 gp_ci.pInputAssemblyState = &iaCI;
7149 gp_ci.pTessellationState = &tsCI;
7150 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007151 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007152 gp_ci.pMultisampleState = NULL;
7153 gp_ci.pDepthStencilState = NULL;
7154 gp_ci.pColorBlendState = NULL;
7155 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7156 gp_ci.layout = pipeline_layout;
7157 gp_ci.renderPass = renderPass();
7158
7159 VkPipelineCacheCreateInfo pc_ci = {};
7160 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7161 pc_ci.pNext = NULL;
7162 pc_ci.initialSize = 0;
7163 pc_ci.initialData = 0;
7164 pc_ci.maxSize = 0;
7165
7166 VkPipeline pipeline;
7167 VkPipelineCache pipelineCache;
7168
Karl Schultz6addd812016-02-02 17:17:23 -07007169 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7170&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007171 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007172 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7173&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007174
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007175 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007176
Chia-I Wuf7458c52015-10-26 21:10:41 +08007177 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7178 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7179 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7180 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007181}
7182*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007183
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007184TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007185 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007186
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007187 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007188
Tobin Ehlise68360f2015-10-01 11:15:13 -06007189 ASSERT_NO_FATAL_FAILURE(InitState());
7190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007191
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007192 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007193 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7194 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007195
7196 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007197 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7198 ds_pool_ci.maxSets = 1;
7199 ds_pool_ci.poolSizeCount = 1;
7200 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007201
7202 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007203 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007204 ASSERT_VK_SUCCESS(err);
7205
7206 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007207 dsl_binding.binding = 0;
7208 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7209 dsl_binding.descriptorCount = 1;
7210 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007211
7212 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007213 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7214 ds_layout_ci.bindingCount = 1;
7215 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007216
7217 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007218 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007219 ASSERT_VK_SUCCESS(err);
7220
7221 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007222 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007223 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007224 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007225 alloc_info.descriptorPool = ds_pool;
7226 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007227 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007228 ASSERT_VK_SUCCESS(err);
7229
7230 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007231 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7232 pipeline_layout_ci.setLayoutCount = 1;
7233 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007234
7235 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007236 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007237 ASSERT_VK_SUCCESS(err);
7238
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007239 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007240 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007241 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007242 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007243 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007244 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007245
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007246 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7247 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7248 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7249 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7250 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7251 rs_state_ci.depthClampEnable = VK_FALSE;
7252 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7253 rs_state_ci.depthBiasEnable = VK_FALSE;
7254
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007255 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7256 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7257 vi_ci.pNext = nullptr;
7258 vi_ci.vertexBindingDescriptionCount = 0;
7259 vi_ci.pVertexBindingDescriptions = nullptr;
7260 vi_ci.vertexAttributeDescriptionCount = 0;
7261 vi_ci.pVertexAttributeDescriptions = nullptr;
7262
7263 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7264 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7265 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7266
7267 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7268 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7269 pipe_ms_state_ci.pNext = NULL;
7270 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7271 pipe_ms_state_ci.sampleShadingEnable = 0;
7272 pipe_ms_state_ci.minSampleShading = 1.0;
7273 pipe_ms_state_ci.pSampleMask = NULL;
7274
Cody Northropeb3a6c12015-10-05 14:44:45 -06007275 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007276 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007277
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007278 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007279 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007280 shaderStages[0] = vs.GetStageCreateInfo();
7281 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007282
7283 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007284 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7285 gp_ci.stageCount = 2;
7286 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007287 gp_ci.pVertexInputState = &vi_ci;
7288 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007289 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007290 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007291 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007292 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7293 gp_ci.layout = pipeline_layout;
7294 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007295
7296 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007297 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007298
7299 VkPipeline pipeline;
7300 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007301 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007302 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007303
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007304 if (!m_device->phy().features().multiViewport) {
7305 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7306
7307 // Check case where multiViewport is disabled and viewport count is not 1
7308 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7311 vp_state_ci.scissorCount = 0;
7312 vp_state_ci.viewportCount = 0;
7313 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7314 m_errorMonitor->VerifyFound();
7315 } else {
7316 if (m_device->props.limits.maxViewports == 1) {
7317 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7318 } else {
7319 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7320
7321 // Check is that viewportcount and scissorcount match
7322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7323 vp_state_ci.scissorCount = 1;
7324 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7325 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7326 m_errorMonitor->VerifyFound();
7327
7328
7329 // Check case where multiViewport is enabled and viewport count is greater than max
7330 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7331 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7333 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7334 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7335 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7336 m_errorMonitor->VerifyFound();
7337 }
7338 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007339
Chia-I Wuf7458c52015-10-26 21:10:41 +08007340 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7341 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7342 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7343 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007344}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007345
7346// 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
7347// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007348TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007349 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007350
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007351 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7352
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007354
Tobin Ehlise68360f2015-10-01 11:15:13 -06007355 ASSERT_NO_FATAL_FAILURE(InitState());
7356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007357
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007358 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007359 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7360 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007361
7362 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007363 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7364 ds_pool_ci.maxSets = 1;
7365 ds_pool_ci.poolSizeCount = 1;
7366 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007367
7368 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007369 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007370 ASSERT_VK_SUCCESS(err);
7371
7372 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007373 dsl_binding.binding = 0;
7374 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7375 dsl_binding.descriptorCount = 1;
7376 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007377
7378 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007379 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7380 ds_layout_ci.bindingCount = 1;
7381 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007382
7383 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007384 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007385 ASSERT_VK_SUCCESS(err);
7386
7387 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007388 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007389 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007390 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007391 alloc_info.descriptorPool = ds_pool;
7392 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007393 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007394 ASSERT_VK_SUCCESS(err);
7395
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007396 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7397 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7398 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7399
7400 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7401 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7402 vi_ci.pNext = nullptr;
7403 vi_ci.vertexBindingDescriptionCount = 0;
7404 vi_ci.pVertexBindingDescriptions = nullptr;
7405 vi_ci.vertexAttributeDescriptionCount = 0;
7406 vi_ci.pVertexAttributeDescriptions = nullptr;
7407
7408 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7409 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7410 pipe_ms_state_ci.pNext = NULL;
7411 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7412 pipe_ms_state_ci.sampleShadingEnable = 0;
7413 pipe_ms_state_ci.minSampleShading = 1.0;
7414 pipe_ms_state_ci.pSampleMask = NULL;
7415
Tobin Ehlise68360f2015-10-01 11:15:13 -06007416 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007417 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7418 pipeline_layout_ci.setLayoutCount = 1;
7419 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007420
7421 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007422 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007423 ASSERT_VK_SUCCESS(err);
7424
7425 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7426 // Set scissor as dynamic to avoid second error
7427 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007428 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7429 dyn_state_ci.dynamicStateCount = 1;
7430 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007431
Cody Northropeb3a6c12015-10-05 14:44:45 -06007432 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007433 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007435 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007436 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7437 // 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 +08007438 shaderStages[0] = vs.GetStageCreateInfo();
7439 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007440
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007441 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7442 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7443 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7444 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7445 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7446 rs_state_ci.depthClampEnable = VK_FALSE;
7447 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7448 rs_state_ci.depthBiasEnable = VK_FALSE;
7449
Tobin Ehlise68360f2015-10-01 11:15:13 -06007450 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007451 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7452 gp_ci.stageCount = 2;
7453 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007454 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007455 // Not setting VP state w/o dynamic vp state should cause validation error
7456 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007457 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007458 gp_ci.pVertexInputState = &vi_ci;
7459 gp_ci.pInputAssemblyState = &ia_ci;
7460 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007461 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7462 gp_ci.layout = pipeline_layout;
7463 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007464
7465 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007466 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007467
7468 VkPipeline pipeline;
7469 VkPipelineCache pipelineCache;
7470
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007471 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007472 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007473 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007474
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007475 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007476
Chia-I Wuf7458c52015-10-26 21:10:41 +08007477 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7478 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7479 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7480 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007481}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007482
7483// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7484// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007485TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7486 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007487
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007489
Tobin Ehlise68360f2015-10-01 11:15:13 -06007490 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007491
7492 if (!m_device->phy().features().multiViewport) {
7493 printf("Device does not support multiple viewports/scissors; skipped.\n");
7494 return;
7495 }
7496
Tobin Ehlise68360f2015-10-01 11:15:13 -06007497 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007498
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007499 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007500 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7501 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007502
7503 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007504 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7505 ds_pool_ci.maxSets = 1;
7506 ds_pool_ci.poolSizeCount = 1;
7507 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007508
7509 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007510 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007511 ASSERT_VK_SUCCESS(err);
7512
7513 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007514 dsl_binding.binding = 0;
7515 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7516 dsl_binding.descriptorCount = 1;
7517 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007518
7519 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007520 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7521 ds_layout_ci.bindingCount = 1;
7522 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007523
7524 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007525 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007526 ASSERT_VK_SUCCESS(err);
7527
7528 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007529 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007530 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007531 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007532 alloc_info.descriptorPool = ds_pool;
7533 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007534 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007535 ASSERT_VK_SUCCESS(err);
7536
7537 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007538 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7539 pipeline_layout_ci.setLayoutCount = 1;
7540 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007541
7542 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007543 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007544 ASSERT_VK_SUCCESS(err);
7545
7546 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007547 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7548 vp_state_ci.viewportCount = 1;
7549 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
7550 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007551 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007552
7553 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7554 // Set scissor as dynamic to avoid that error
7555 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007556 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7557 dyn_state_ci.dynamicStateCount = 1;
7558 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007559
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007560 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7561 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7562 pipe_ms_state_ci.pNext = NULL;
7563 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7564 pipe_ms_state_ci.sampleShadingEnable = 0;
7565 pipe_ms_state_ci.minSampleShading = 1.0;
7566 pipe_ms_state_ci.pSampleMask = NULL;
7567
Cody Northropeb3a6c12015-10-05 14:44:45 -06007568 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007569 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007570
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007571 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007572 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7573 // 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 +08007574 shaderStages[0] = vs.GetStageCreateInfo();
7575 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007576
Cody Northropf6622dc2015-10-06 10:33:21 -06007577 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7578 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7579 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007580 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007581 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007582 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007583 vi_ci.pVertexAttributeDescriptions = nullptr;
7584
7585 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7586 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7587 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7588
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007589 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007590 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007591 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007592 rs_ci.pNext = nullptr;
7593
Mark Youngc89c6312016-03-31 16:03:20 -06007594 VkPipelineColorBlendAttachmentState att = {};
7595 att.blendEnable = VK_FALSE;
7596 att.colorWriteMask = 0xf;
7597
Cody Northropf6622dc2015-10-06 10:33:21 -06007598 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7599 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7600 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007601 cb_ci.attachmentCount = 1;
7602 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007603
Tobin Ehlise68360f2015-10-01 11:15:13 -06007604 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007605 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7606 gp_ci.stageCount = 2;
7607 gp_ci.pStages = shaderStages;
7608 gp_ci.pVertexInputState = &vi_ci;
7609 gp_ci.pInputAssemblyState = &ia_ci;
7610 gp_ci.pViewportState = &vp_state_ci;
7611 gp_ci.pRasterizationState = &rs_ci;
7612 gp_ci.pColorBlendState = &cb_ci;
7613 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007614 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007615 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7616 gp_ci.layout = pipeline_layout;
7617 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007618
7619 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007620 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007621
7622 VkPipeline pipeline;
7623 VkPipelineCache pipelineCache;
7624
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007625 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007626 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007627 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007628
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007629 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007630
Tobin Ehlisd332f282015-10-02 11:00:56 -06007631 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007632 // First need to successfully create the PSO from above by setting
7633 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007634 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 -07007635
7636 VkViewport vp = {}; // Just need dummy vp to point to
7637 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007638 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007639 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007640 m_commandBuffer->BeginCommandBuffer();
7641 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007642 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007643 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007644 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007645 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007646 Draw(1, 0, 0, 0);
7647
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007648 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007649
7650 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7651 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7652 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7653 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007654 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007655}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007656
7657// 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 -07007658// viewportCount
7659TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7660 VkResult err;
7661
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007663
7664 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007665
7666 if (!m_device->phy().features().multiViewport) {
7667 printf("Device does not support multiple viewports/scissors; skipped.\n");
7668 return;
7669 }
7670
Karl Schultz6addd812016-02-02 17:17:23 -07007671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7672
7673 VkDescriptorPoolSize ds_type_count = {};
7674 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7675 ds_type_count.descriptorCount = 1;
7676
7677 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7678 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7679 ds_pool_ci.maxSets = 1;
7680 ds_pool_ci.poolSizeCount = 1;
7681 ds_pool_ci.pPoolSizes = &ds_type_count;
7682
7683 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007684 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007685 ASSERT_VK_SUCCESS(err);
7686
7687 VkDescriptorSetLayoutBinding dsl_binding = {};
7688 dsl_binding.binding = 0;
7689 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7690 dsl_binding.descriptorCount = 1;
7691 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7692
7693 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7694 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7695 ds_layout_ci.bindingCount = 1;
7696 ds_layout_ci.pBindings = &dsl_binding;
7697
7698 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007699 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007700 ASSERT_VK_SUCCESS(err);
7701
7702 VkDescriptorSet descriptorSet;
7703 VkDescriptorSetAllocateInfo alloc_info = {};
7704 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7705 alloc_info.descriptorSetCount = 1;
7706 alloc_info.descriptorPool = ds_pool;
7707 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007708 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007709 ASSERT_VK_SUCCESS(err);
7710
7711 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7712 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7713 pipeline_layout_ci.setLayoutCount = 1;
7714 pipeline_layout_ci.pSetLayouts = &ds_layout;
7715
7716 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007717 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007718 ASSERT_VK_SUCCESS(err);
7719
7720 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7721 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7722 vp_state_ci.scissorCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007723 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007724 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007725 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007726
7727 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7728 // Set scissor as dynamic to avoid that error
7729 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7730 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7731 dyn_state_ci.dynamicStateCount = 1;
7732 dyn_state_ci.pDynamicStates = &vp_state;
7733
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007734 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7735 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7736 pipe_ms_state_ci.pNext = NULL;
7737 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7738 pipe_ms_state_ci.sampleShadingEnable = 0;
7739 pipe_ms_state_ci.minSampleShading = 1.0;
7740 pipe_ms_state_ci.pSampleMask = NULL;
7741
Karl Schultz6addd812016-02-02 17:17:23 -07007742 VkPipelineShaderStageCreateInfo shaderStages[2];
7743 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7744
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007745 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007746 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7747 // 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 -07007748 shaderStages[0] = vs.GetStageCreateInfo();
7749 shaderStages[1] = fs.GetStageCreateInfo();
7750
7751 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7752 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7753 vi_ci.pNext = nullptr;
7754 vi_ci.vertexBindingDescriptionCount = 0;
7755 vi_ci.pVertexBindingDescriptions = nullptr;
7756 vi_ci.vertexAttributeDescriptionCount = 0;
7757 vi_ci.pVertexAttributeDescriptions = nullptr;
7758
7759 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7760 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7761 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7762
7763 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7764 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007765 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007766 rs_ci.pNext = nullptr;
7767
Mark Youngc89c6312016-03-31 16:03:20 -06007768 VkPipelineColorBlendAttachmentState att = {};
7769 att.blendEnable = VK_FALSE;
7770 att.colorWriteMask = 0xf;
7771
Karl Schultz6addd812016-02-02 17:17:23 -07007772 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7773 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7774 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007775 cb_ci.attachmentCount = 1;
7776 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007777
7778 VkGraphicsPipelineCreateInfo gp_ci = {};
7779 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7780 gp_ci.stageCount = 2;
7781 gp_ci.pStages = shaderStages;
7782 gp_ci.pVertexInputState = &vi_ci;
7783 gp_ci.pInputAssemblyState = &ia_ci;
7784 gp_ci.pViewportState = &vp_state_ci;
7785 gp_ci.pRasterizationState = &rs_ci;
7786 gp_ci.pColorBlendState = &cb_ci;
7787 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007788 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007789 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7790 gp_ci.layout = pipeline_layout;
7791 gp_ci.renderPass = renderPass();
7792
7793 VkPipelineCacheCreateInfo pc_ci = {};
7794 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7795
7796 VkPipeline pipeline;
7797 VkPipelineCache pipelineCache;
7798
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007799 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007800 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007801 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007802
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007803 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007804
7805 // Now hit second fail case where we set scissor w/ different count than PSO
7806 // First need to successfully create the PSO from above by setting
7807 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007809
Tobin Ehlisd332f282015-10-02 11:00:56 -06007810 VkRect2D sc = {}; // Just need dummy vp to point to
7811 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007812 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007813 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007814 m_commandBuffer->BeginCommandBuffer();
7815 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007816 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007817 VkViewport viewports[1] = {};
7818 viewports[0].width = 8;
7819 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007820 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007821 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007822 Draw(1, 0, 0, 0);
7823
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007824 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007825
Chia-I Wuf7458c52015-10-26 21:10:41 +08007826 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7827 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7828 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7829 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007830 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007831}
7832
Mark Young7394fdd2016-03-31 14:56:43 -06007833TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7834 VkResult err;
7835
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007837
7838 ASSERT_NO_FATAL_FAILURE(InitState());
7839 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7840
7841 VkDescriptorPoolSize ds_type_count = {};
7842 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7843 ds_type_count.descriptorCount = 1;
7844
7845 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7846 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7847 ds_pool_ci.maxSets = 1;
7848 ds_pool_ci.poolSizeCount = 1;
7849 ds_pool_ci.pPoolSizes = &ds_type_count;
7850
7851 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007852 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007853 ASSERT_VK_SUCCESS(err);
7854
7855 VkDescriptorSetLayoutBinding dsl_binding = {};
7856 dsl_binding.binding = 0;
7857 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7858 dsl_binding.descriptorCount = 1;
7859 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7860
7861 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7862 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7863 ds_layout_ci.bindingCount = 1;
7864 ds_layout_ci.pBindings = &dsl_binding;
7865
7866 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007867 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007868 ASSERT_VK_SUCCESS(err);
7869
7870 VkDescriptorSet descriptorSet;
7871 VkDescriptorSetAllocateInfo alloc_info = {};
7872 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7873 alloc_info.descriptorSetCount = 1;
7874 alloc_info.descriptorPool = ds_pool;
7875 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007876 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06007877 ASSERT_VK_SUCCESS(err);
7878
7879 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7880 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7881 pipeline_layout_ci.setLayoutCount = 1;
7882 pipeline_layout_ci.pSetLayouts = &ds_layout;
7883
7884 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007885 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06007886 ASSERT_VK_SUCCESS(err);
7887
7888 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7889 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7890 vp_state_ci.scissorCount = 1;
7891 vp_state_ci.pScissors = NULL;
7892 vp_state_ci.viewportCount = 1;
7893 vp_state_ci.pViewports = NULL;
7894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007895 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06007896 // Set scissor as dynamic to avoid that error
7897 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7898 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7899 dyn_state_ci.dynamicStateCount = 2;
7900 dyn_state_ci.pDynamicStates = dynamic_states;
7901
7902 VkPipelineShaderStageCreateInfo shaderStages[2];
7903 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7904
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007905 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7906 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Young7394fdd2016-03-31 14:56:43 -06007907 this); // TODO - We shouldn't need a fragment shader
7908 // but add it to be able to run on more devices
7909 shaderStages[0] = vs.GetStageCreateInfo();
7910 shaderStages[1] = fs.GetStageCreateInfo();
7911
7912 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7913 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7914 vi_ci.pNext = nullptr;
7915 vi_ci.vertexBindingDescriptionCount = 0;
7916 vi_ci.pVertexBindingDescriptions = nullptr;
7917 vi_ci.vertexAttributeDescriptionCount = 0;
7918 vi_ci.pVertexAttributeDescriptions = nullptr;
7919
7920 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7921 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7922 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7923
7924 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7925 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7926 rs_ci.pNext = nullptr;
7927
Mark Young47107952016-05-02 15:59:55 -06007928 // Check too low (line width of -1.0f).
7929 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007930
7931 VkPipelineColorBlendAttachmentState att = {};
7932 att.blendEnable = VK_FALSE;
7933 att.colorWriteMask = 0xf;
7934
7935 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7936 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7937 cb_ci.pNext = nullptr;
7938 cb_ci.attachmentCount = 1;
7939 cb_ci.pAttachments = &att;
7940
7941 VkGraphicsPipelineCreateInfo gp_ci = {};
7942 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7943 gp_ci.stageCount = 2;
7944 gp_ci.pStages = shaderStages;
7945 gp_ci.pVertexInputState = &vi_ci;
7946 gp_ci.pInputAssemblyState = &ia_ci;
7947 gp_ci.pViewportState = &vp_state_ci;
7948 gp_ci.pRasterizationState = &rs_ci;
7949 gp_ci.pColorBlendState = &cb_ci;
7950 gp_ci.pDynamicState = &dyn_state_ci;
7951 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7952 gp_ci.layout = pipeline_layout;
7953 gp_ci.renderPass = renderPass();
7954
7955 VkPipelineCacheCreateInfo pc_ci = {};
7956 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7957
7958 VkPipeline pipeline;
7959 VkPipelineCache pipelineCache;
7960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007961 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007962 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007963 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007964
7965 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007966 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007967
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007969
7970 // Check too high (line width of 65536.0f).
7971 rs_ci.lineWidth = 65536.0f;
7972
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007973 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007974 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007975 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007976
7977 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007978 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007979
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007980 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007981
7982 dyn_state_ci.dynamicStateCount = 3;
7983
7984 rs_ci.lineWidth = 1.0f;
7985
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007986 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007987 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007988 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07007989 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007990 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007991
7992 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007993 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007994 m_errorMonitor->VerifyFound();
7995
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007997
7998 // Check too high with dynamic setting.
7999 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8000 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008001 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008002
8003 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8004 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8005 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8006 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008007 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008008}
8009
Karl Schultz6addd812016-02-02 17:17:23 -07008010TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008011 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008013 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008014
8015 ASSERT_NO_FATAL_FAILURE(InitState());
8016 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008017
Tony Barbour552f6c02016-12-21 14:34:07 -07008018 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008019 // Don't care about RenderPass handle b/c error should be flagged before
8020 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008021 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008022
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008023 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008024}
8025
Karl Schultz6addd812016-02-02 17:17:23 -07008026TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008027 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008028 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8029 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008030
8031 ASSERT_NO_FATAL_FAILURE(InitState());
8032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008033
Tony Barbour552f6c02016-12-21 14:34:07 -07008034 m_commandBuffer->BeginCommandBuffer();
8035 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008036 // Just create a dummy Renderpass that's non-NULL so we can get to the
8037 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008038 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008040 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008041}
8042
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008043TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
8044 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
8045 "the number of renderPass attachments that use loadOp"
8046 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8047
8048 ASSERT_NO_FATAL_FAILURE(InitState());
8049 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8050
8051 // Create a renderPass with a single attachment that uses loadOp CLEAR
8052 VkAttachmentReference attach = {};
8053 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8054 VkSubpassDescription subpass = {};
8055 subpass.inputAttachmentCount = 1;
8056 subpass.pInputAttachments = &attach;
8057 VkRenderPassCreateInfo rpci = {};
8058 rpci.subpassCount = 1;
8059 rpci.pSubpasses = &subpass;
8060 rpci.attachmentCount = 1;
8061 VkAttachmentDescription attach_desc = {};
8062 attach_desc.format = VK_FORMAT_UNDEFINED;
8063 // Set loadOp to CLEAR
8064 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8065 rpci.pAttachments = &attach_desc;
8066 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8067 VkRenderPass rp;
8068 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8069
8070 VkCommandBufferInheritanceInfo hinfo = {};
8071 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8072 hinfo.renderPass = VK_NULL_HANDLE;
8073 hinfo.subpass = 0;
8074 hinfo.framebuffer = VK_NULL_HANDLE;
8075 hinfo.occlusionQueryEnable = VK_FALSE;
8076 hinfo.queryFlags = 0;
8077 hinfo.pipelineStatistics = 0;
8078 VkCommandBufferBeginInfo info = {};
8079 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8080 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8081 info.pInheritanceInfo = &hinfo;
8082
8083 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8084 VkRenderPassBeginInfo rp_begin = {};
8085 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8086 rp_begin.pNext = NULL;
8087 rp_begin.renderPass = renderPass();
8088 rp_begin.framebuffer = framebuffer();
8089 rp_begin.clearValueCount = 0; // Should be 1
8090
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008092
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008093 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008094
8095 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008096
8097 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008098}
8099
Slawomir Cygan0808f392016-11-28 17:53:23 +01008100TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
8101 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
8102 "the number of renderPass attachments that use loadOp"
8103 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8104
8105 ASSERT_NO_FATAL_FAILURE(InitState());
8106 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8107
8108 // Create a renderPass with a single attachment that uses loadOp CLEAR
8109 VkAttachmentReference attach = {};
8110 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8111 VkSubpassDescription subpass = {};
8112 subpass.inputAttachmentCount = 1;
8113 subpass.pInputAttachments = &attach;
8114 VkRenderPassCreateInfo rpci = {};
8115 rpci.subpassCount = 1;
8116 rpci.pSubpasses = &subpass;
8117 rpci.attachmentCount = 1;
8118 VkAttachmentDescription attach_desc = {};
8119 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8120 // Set loadOp to CLEAR
8121 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8122 rpci.pAttachments = &attach_desc;
8123 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8124 VkRenderPass rp;
8125 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8126
8127 VkCommandBufferBeginInfo info = {};
8128 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8129 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8130
8131 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8132 VkRenderPassBeginInfo rp_begin = {};
8133 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8134 rp_begin.pNext = NULL;
8135 rp_begin.renderPass = renderPass();
8136 rp_begin.framebuffer = framebuffer();
8137 rp_begin.clearValueCount = 2; // Should be 1
8138
8139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8140 " 2 but only first 1 entries in pClearValues array are used");
8141
8142 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8143
8144 m_errorMonitor->VerifyFound();
8145
8146 vkDestroyRenderPass(m_device->device(), rp, NULL);
8147}
8148
8149
Cody Northrop3bb4d962016-05-09 16:15:57 -06008150TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8151
8152 TEST_DESCRIPTION("End a command buffer with an active render pass");
8153
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008154 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8155 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008156
8157 ASSERT_NO_FATAL_FAILURE(InitState());
8158 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8159
Tony Barbour552f6c02016-12-21 14:34:07 -07008160 m_commandBuffer->BeginCommandBuffer();
8161 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8162 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008163
8164 m_errorMonitor->VerifyFound();
8165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008166 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8167 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008168}
8169
Karl Schultz6addd812016-02-02 17:17:23 -07008170TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008171 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8173 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008174
8175 ASSERT_NO_FATAL_FAILURE(InitState());
8176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008177
Tony Barbour552f6c02016-12-21 14:34:07 -07008178 m_commandBuffer->BeginCommandBuffer();
8179 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008180
8181 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008182 vk_testing::Buffer dstBuffer;
8183 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008184
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008185 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008187 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008188}
8189
Karl Schultz6addd812016-02-02 17:17:23 -07008190TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008191 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8193 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008194
8195 ASSERT_NO_FATAL_FAILURE(InitState());
8196 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008197
Tony Barbour552f6c02016-12-21 14:34:07 -07008198 m_commandBuffer->BeginCommandBuffer();
8199 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008200
8201 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008202 vk_testing::Buffer dstBuffer;
8203 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008204
Karl Schultz6addd812016-02-02 17:17:23 -07008205 VkDeviceSize dstOffset = 0;
8206 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008207 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008209 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008210
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008211 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008212}
8213
Karl Schultz6addd812016-02-02 17:17:23 -07008214TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008215 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8217 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008218
8219 ASSERT_NO_FATAL_FAILURE(InitState());
8220 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008221
Tony Barbour552f6c02016-12-21 14:34:07 -07008222 m_commandBuffer->BeginCommandBuffer();
8223 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008224
Michael Lentine0a369f62016-02-03 16:51:46 -06008225 VkClearColorValue clear_color;
8226 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008227 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8228 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8229 const int32_t tex_width = 32;
8230 const int32_t tex_height = 32;
8231 VkImageCreateInfo image_create_info = {};
8232 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8233 image_create_info.pNext = NULL;
8234 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8235 image_create_info.format = tex_format;
8236 image_create_info.extent.width = tex_width;
8237 image_create_info.extent.height = tex_height;
8238 image_create_info.extent.depth = 1;
8239 image_create_info.mipLevels = 1;
8240 image_create_info.arrayLayers = 1;
8241 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8242 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8243 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008244
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008245 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008246 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008247
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008248 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008249
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008250 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008251
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008252 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008253}
8254
Karl Schultz6addd812016-02-02 17:17:23 -07008255TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008256 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8258 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008259
8260 ASSERT_NO_FATAL_FAILURE(InitState());
8261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008262
Tony Barbour552f6c02016-12-21 14:34:07 -07008263 m_commandBuffer->BeginCommandBuffer();
8264 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008265
8266 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008267 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008268 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8269 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8270 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8271 image_create_info.extent.width = 64;
8272 image_create_info.extent.height = 64;
8273 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8274 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008275
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008276 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008277 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008278
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008279 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008280
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008281 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
Rene Lindsay8247f392017-01-18 13:35:47 -07008282 VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008283
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008284 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008285}
8286
Karl Schultz6addd812016-02-02 17:17:23 -07008287TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008288 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008289 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8292 "must be issued inside an active "
8293 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008294
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008295 ASSERT_NO_FATAL_FAILURE(InitState());
8296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008297
8298 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008299 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008300 ASSERT_VK_SUCCESS(err);
8301
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008302 VkClearAttachment color_attachment;
8303 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8304 color_attachment.clearValue.color.float32[0] = 0;
8305 color_attachment.clearValue.color.float32[1] = 0;
8306 color_attachment.clearValue.color.float32[2] = 0;
8307 color_attachment.clearValue.color.float32[3] = 0;
8308 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008309 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008310 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008311
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008312 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008313}
8314
Chris Forbes3b97e932016-09-07 11:29:24 +12008315TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8316 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8317 "called too many times in a renderpass instance");
8318
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8320 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008321
8322 ASSERT_NO_FATAL_FAILURE(InitState());
8323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8324
Tony Barbour552f6c02016-12-21 14:34:07 -07008325 m_commandBuffer->BeginCommandBuffer();
8326 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008327
8328 // error here.
8329 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8330 m_errorMonitor->VerifyFound();
8331
Tony Barbour552f6c02016-12-21 14:34:07 -07008332 m_commandBuffer->EndRenderPass();
8333 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008334}
8335
Chris Forbes6d624702016-09-07 13:57:05 +12008336TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8337 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8338 "called before the final subpass has been reached");
8339
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8341 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008342
8343 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008344 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8345 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008346
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008347 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008348
8349 VkRenderPass rp;
8350 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8351 ASSERT_VK_SUCCESS(err);
8352
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008353 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008354
8355 VkFramebuffer fb;
8356 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8357 ASSERT_VK_SUCCESS(err);
8358
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008359 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008360
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008361 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 +12008362
8363 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8364
8365 // Error here.
8366 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8367 m_errorMonitor->VerifyFound();
8368
8369 // Clean up.
8370 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8371 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8372}
8373
Karl Schultz9e66a292016-04-21 15:57:51 -06008374TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8375 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8377 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008378
8379 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008380 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008381
8382 VkBufferMemoryBarrier buf_barrier = {};
8383 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8384 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8385 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8386 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8387 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8388 buf_barrier.buffer = VK_NULL_HANDLE;
8389 buf_barrier.offset = 0;
8390 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008391 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8392 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008393
8394 m_errorMonitor->VerifyFound();
8395}
8396
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008397TEST_F(VkLayerTest, InvalidBarriers) {
8398 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8399
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008401
8402 ASSERT_NO_FATAL_FAILURE(InitState());
8403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8404
8405 VkMemoryBarrier mem_barrier = {};
8406 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8407 mem_barrier.pNext = NULL;
8408 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8409 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008410 m_commandBuffer->BeginCommandBuffer();
8411 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008412 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008413 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008414 &mem_barrier, 0, nullptr, 0, nullptr);
8415 m_errorMonitor->VerifyFound();
8416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008418 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008419 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 -06008420 ASSERT_TRUE(image.initialized());
8421 VkImageMemoryBarrier img_barrier = {};
8422 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8423 img_barrier.pNext = NULL;
8424 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8425 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8426 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8427 // New layout can't be UNDEFINED
8428 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8429 img_barrier.image = image.handle();
8430 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8431 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8432 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8433 img_barrier.subresourceRange.baseArrayLayer = 0;
8434 img_barrier.subresourceRange.baseMipLevel = 0;
8435 img_barrier.subresourceRange.layerCount = 1;
8436 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008437 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8438 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008439 m_errorMonitor->VerifyFound();
8440 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8441
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8443 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008444 // baseArrayLayer + layerCount must be <= image's arrayLayers
8445 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008446 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8447 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008448 m_errorMonitor->VerifyFound();
8449 img_barrier.subresourceRange.baseArrayLayer = 0;
8450
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008452 // baseMipLevel + levelCount must be <= image's mipLevels
8453 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8455 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008456 m_errorMonitor->VerifyFound();
8457 img_barrier.subresourceRange.baseMipLevel = 0;
8458
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008459 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 -06008460 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008461 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8462 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008463 VkBufferMemoryBarrier buf_barrier = {};
8464 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8465 buf_barrier.pNext = NULL;
8466 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8467 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8468 buf_barrier.buffer = buffer.handle();
8469 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8470 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8471 buf_barrier.offset = 0;
8472 buf_barrier.size = VK_WHOLE_SIZE;
8473 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8475 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008476 m_errorMonitor->VerifyFound();
8477 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8478
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008480 buf_barrier.offset = 257;
8481 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008482 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8483 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008484 m_errorMonitor->VerifyFound();
8485 buf_barrier.offset = 0;
8486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008488 buf_barrier.size = 257;
8489 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008490 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8491 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008492 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008493
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008494 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008495 m_errorMonitor->SetDesiredFailureMsg(
8496 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008497 "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 -06008498 VkDepthStencilObj ds_image(m_device);
8499 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8500 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008501 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8502 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008503 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008504
8505 // Not having DEPTH or STENCIL set is an error
8506 img_barrier.subresourceRange.aspectMask = 0;
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, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008509 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07008510
8511 // Having anything other than DEPTH or STENCIL is an error
8512 m_errorMonitor->SetDesiredFailureMsg(
8513 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8514 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8515 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
8516 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8517 nullptr, 0, nullptr, 1, &img_barrier);
8518 m_errorMonitor->VerifyFound();
8519
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008520 // Now test depth-only
8521 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8523 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008524 VkDepthStencilObj d_image(m_device);
8525 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8526 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008527 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008528 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008529 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008530
8531 // DEPTH bit must be set
8532 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8533 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8534 img_barrier.subresourceRange.aspectMask = 0;
8535 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8536 0, nullptr, 0, nullptr, 1, &img_barrier);
8537 m_errorMonitor->VerifyFound();
8538
8539 // No bits other than DEPTH may be set
8540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8541 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8542 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008543 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8544 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008545 m_errorMonitor->VerifyFound();
8546 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008547
8548 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008549 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8550 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8552 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008553 VkDepthStencilObj s_image(m_device);
8554 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8555 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008556 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008557 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008558 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008559 // Use of COLOR aspect on depth image is error
8560 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008561 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8562 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008563 m_errorMonitor->VerifyFound();
8564 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008565
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008566 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008567 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008568 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 -06008569 ASSERT_TRUE(c_image.initialized());
8570 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8571 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8572 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008573
8574 // COLOR bit must be set
8575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8576 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8577 img_barrier.subresourceRange.aspectMask = 0;
8578 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8579 nullptr, 0, nullptr, 1, &img_barrier);
8580 m_errorMonitor->VerifyFound();
8581
8582 // No bits other than COLOR may be set
8583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8584 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
8585 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008586 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8587 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008588 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008589
8590 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8591
8592 // Create command pool with incompatible queueflags
8593 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8594 uint32_t queue_family_index = UINT32_MAX;
8595 for (uint32_t i = 0; i < queue_props.size(); i++) {
8596 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8597 queue_family_index = i;
8598 break;
8599 }
8600 }
8601 if (queue_family_index == UINT32_MAX) {
8602 printf("No non-compute queue found; skipped.\n");
8603 return;
8604 }
8605 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8606
8607 VkCommandPool command_pool;
8608 VkCommandPoolCreateInfo pool_create_info{};
8609 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8610 pool_create_info.queueFamilyIndex = queue_family_index;
8611 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8612 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8613
8614 // Allocate a command buffer
8615 VkCommandBuffer bad_command_buffer;
8616 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8617 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8618 command_buffer_allocate_info.commandPool = command_pool;
8619 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8620 command_buffer_allocate_info.commandBufferCount = 1;
8621 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8622
8623 VkCommandBufferBeginInfo cbbi = {};
8624 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8625 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8626 buf_barrier.offset = 0;
8627 buf_barrier.size = VK_WHOLE_SIZE;
8628 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8629 &buf_barrier, 0, nullptr);
8630 m_errorMonitor->VerifyFound();
8631
8632 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8633 vkEndCommandBuffer(bad_command_buffer);
8634 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8635 printf("The non-compute queue does not support graphics; skipped.\n");
8636 return;
8637 }
8638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8639 VkEvent event;
8640 VkEventCreateInfo event_create_info{};
8641 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8642 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8643 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8644 nullptr, 0, nullptr);
8645 m_errorMonitor->VerifyFound();
8646
8647 vkEndCommandBuffer(bad_command_buffer);
8648 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008649}
8650
Tony Barbour18ba25c2016-09-29 13:42:40 -06008651TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8652 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8653
8654 m_errorMonitor->SetDesiredFailureMsg(
8655 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8656 "must have required access bit");
8657 ASSERT_NO_FATAL_FAILURE(InitState());
8658 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008659 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 -06008660 ASSERT_TRUE(image.initialized());
8661
8662 VkImageMemoryBarrier barrier = {};
8663 VkImageSubresourceRange range;
8664 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8665 barrier.srcAccessMask = 0;
8666 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8667 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8668 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8669 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8670 barrier.image = image.handle();
8671 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8672 range.baseMipLevel = 0;
8673 range.levelCount = 1;
8674 range.baseArrayLayer = 0;
8675 range.layerCount = 1;
8676 barrier.subresourceRange = range;
8677 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8678 cmdbuf.BeginCommandBuffer();
8679 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8680 &barrier);
8681 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8682 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8683 barrier.srcAccessMask = 0;
8684 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8685 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8686 &barrier);
8687
8688 m_errorMonitor->VerifyFound();
8689}
8690
Karl Schultz6addd812016-02-02 17:17:23 -07008691TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008692 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008693 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008694
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008696
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008697 ASSERT_NO_FATAL_FAILURE(InitState());
8698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008699 uint32_t qfi = 0;
8700 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008701 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8702 buffCI.size = 1024;
8703 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8704 buffCI.queueFamilyIndexCount = 1;
8705 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008706
8707 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008708 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008709 ASSERT_VK_SUCCESS(err);
8710
Tony Barbour552f6c02016-12-21 14:34:07 -07008711 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008712 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008713 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8714 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008715 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008716 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008717
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008718 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008719
Chia-I Wuf7458c52015-10-26 21:10:41 +08008720 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008721}
8722
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008723TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8724 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8726 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8727 "of the indices specified when the device was created, via the "
8728 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008729
8730 ASSERT_NO_FATAL_FAILURE(InitState());
8731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8732 VkBufferCreateInfo buffCI = {};
8733 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8734 buffCI.size = 1024;
8735 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8736 buffCI.queueFamilyIndexCount = 1;
8737 // Introduce failure by specifying invalid queue_family_index
8738 uint32_t qfi = 777;
8739 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008740 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008741
8742 VkBuffer ib;
8743 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8744
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008745 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008746 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008747}
8748
Karl Schultz6addd812016-02-02 17:17:23 -07008749TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008750TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008751 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008752
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008753 ASSERT_NO_FATAL_FAILURE(InitState());
8754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008755
Chris Forbesf29a84f2016-10-06 18:39:28 +13008756 // An empty primary command buffer
8757 VkCommandBufferObj cb(m_device, m_commandPool);
8758 cb.BeginCommandBuffer();
8759 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008760
Chris Forbesf29a84f2016-10-06 18:39:28 +13008761 m_commandBuffer->BeginCommandBuffer();
8762 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8763 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008764
Chris Forbesf29a84f2016-10-06 18:39:28 +13008765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8766 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008767 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008768}
8769
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008770TEST_F(VkLayerTest, DSUsageBitsErrors) {
8771 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8772 "that do not have correct usage bits sets.");
8773 VkResult err;
8774
8775 ASSERT_NO_FATAL_FAILURE(InitState());
8776 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8777 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8778 ds_type_count[i].type = VkDescriptorType(i);
8779 ds_type_count[i].descriptorCount = 1;
8780 }
8781 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8782 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8783 ds_pool_ci.pNext = NULL;
8784 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8785 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8786 ds_pool_ci.pPoolSizes = ds_type_count;
8787
8788 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008789 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008790 ASSERT_VK_SUCCESS(err);
8791
8792 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008793 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008794 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8795 dsl_binding[i].binding = 0;
8796 dsl_binding[i].descriptorType = VkDescriptorType(i);
8797 dsl_binding[i].descriptorCount = 1;
8798 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8799 dsl_binding[i].pImmutableSamplers = NULL;
8800 }
8801
8802 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8803 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8804 ds_layout_ci.pNext = NULL;
8805 ds_layout_ci.bindingCount = 1;
8806 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8807 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8808 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008809 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008810 ASSERT_VK_SUCCESS(err);
8811 }
8812 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8813 VkDescriptorSetAllocateInfo alloc_info = {};
8814 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8815 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8816 alloc_info.descriptorPool = ds_pool;
8817 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008818 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008819 ASSERT_VK_SUCCESS(err);
8820
8821 // Create a buffer & bufferView to be used for invalid updates
8822 VkBufferCreateInfo buff_ci = {};
8823 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8824 // This usage is not valid for any descriptor type
8825 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8826 buff_ci.size = 256;
8827 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8828 VkBuffer buffer;
8829 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8830 ASSERT_VK_SUCCESS(err);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008831 VkMemoryRequirements mem_reqs;
8832 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8833 VkMemoryAllocateInfo mem_alloc_info = {};
8834 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8835 mem_alloc_info.pNext = NULL;
8836 mem_alloc_info.memoryTypeIndex = 0;
8837 mem_alloc_info.allocationSize = mem_reqs.size;
8838 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8839 if (!pass) {
8840 vkDestroyBuffer(m_device->device(), buffer, NULL);
8841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8842 return;
8843 }
8844 VkDeviceMemory mem;
8845 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
8846 ASSERT_VK_SUCCESS(err);
8847 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8848 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008849
8850 VkBufferViewCreateInfo buff_view_ci = {};
8851 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8852 buff_view_ci.buffer = buffer;
8853 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8854 buff_view_ci.range = VK_WHOLE_SIZE;
8855 VkBufferView buff_view;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008856 // Note that this hits VALIDATION_ERROR_00694 due to no usage bit set, but we want call to go through
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008857 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008858 ASSERT_VK_SUCCESS(err);
8859
8860 // Create an image to be used for invalid updates
8861 VkImageCreateInfo image_ci = {};
8862 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8863 image_ci.imageType = VK_IMAGE_TYPE_2D;
8864 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8865 image_ci.extent.width = 64;
8866 image_ci.extent.height = 64;
8867 image_ci.extent.depth = 1;
8868 image_ci.mipLevels = 1;
8869 image_ci.arrayLayers = 1;
8870 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8871 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8872 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8873 // This usage is not valid for any descriptor type
8874 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8875 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8876 VkImage image;
8877 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8878 ASSERT_VK_SUCCESS(err);
8879 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008880 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008881
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008882 VkMemoryAllocateInfo mem_alloc = {};
8883 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8884 mem_alloc.pNext = NULL;
8885 mem_alloc.allocationSize = 0;
8886 mem_alloc.memoryTypeIndex = 0;
8887 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8888 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008889 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008890 ASSERT_TRUE(pass);
8891 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8892 ASSERT_VK_SUCCESS(err);
8893 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8894 ASSERT_VK_SUCCESS(err);
8895 // Now create view for image
8896 VkImageViewCreateInfo image_view_ci = {};
8897 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8898 image_view_ci.image = image;
8899 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8900 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8901 image_view_ci.subresourceRange.layerCount = 1;
8902 image_view_ci.subresourceRange.baseArrayLayer = 0;
8903 image_view_ci.subresourceRange.levelCount = 1;
8904 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8905 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008906 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008907 ASSERT_VK_SUCCESS(err);
8908
8909 VkDescriptorBufferInfo buff_info = {};
8910 buff_info.buffer = buffer;
8911 VkDescriptorImageInfo img_info = {};
8912 img_info.imageView = image_view;
8913 VkWriteDescriptorSet descriptor_write = {};
8914 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8915 descriptor_write.dstBinding = 0;
8916 descriptor_write.descriptorCount = 1;
8917 descriptor_write.pTexelBufferView = &buff_view;
8918 descriptor_write.pBufferInfo = &buff_info;
8919 descriptor_write.pImageInfo = &img_info;
8920
8921 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008922 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
8923 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
8924 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
8925 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
8926 VALIDATION_ERROR_00943, // STORAGE_IMAGE
8927 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
8928 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
8929 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
8930 VALIDATION_ERROR_00947, // STORAGE_BUFFER
8931 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
8932 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
8933 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
8934 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008935 // Start loop at 1 as SAMPLER desc type has no usage bit error
8936 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8937 descriptor_write.descriptorType = VkDescriptorType(i);
8938 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008940
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008941 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008942
8943 m_errorMonitor->VerifyFound();
8944 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8945 }
8946 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8947 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008948 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008949 vkDestroyImageView(m_device->device(), image_view, NULL);
8950 vkDestroyBuffer(m_device->device(), buffer, NULL);
8951 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008952 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008953 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8954}
8955
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008956TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008957 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8958 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8959 "1. offset value greater than buffer size\n"
8960 "2. range value of 0\n"
8961 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008962 VkResult err;
8963
8964 ASSERT_NO_FATAL_FAILURE(InitState());
8965 VkDescriptorPoolSize ds_type_count = {};
8966 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8967 ds_type_count.descriptorCount = 1;
8968
8969 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8970 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8971 ds_pool_ci.pNext = NULL;
8972 ds_pool_ci.maxSets = 1;
8973 ds_pool_ci.poolSizeCount = 1;
8974 ds_pool_ci.pPoolSizes = &ds_type_count;
8975
8976 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008977 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008978 ASSERT_VK_SUCCESS(err);
8979
8980 // Create layout with single uniform buffer descriptor
8981 VkDescriptorSetLayoutBinding dsl_binding = {};
8982 dsl_binding.binding = 0;
8983 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8984 dsl_binding.descriptorCount = 1;
8985 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8986 dsl_binding.pImmutableSamplers = NULL;
8987
8988 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8989 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8990 ds_layout_ci.pNext = NULL;
8991 ds_layout_ci.bindingCount = 1;
8992 ds_layout_ci.pBindings = &dsl_binding;
8993 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008994 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008995 ASSERT_VK_SUCCESS(err);
8996
8997 VkDescriptorSet descriptor_set = {};
8998 VkDescriptorSetAllocateInfo alloc_info = {};
8999 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9000 alloc_info.descriptorSetCount = 1;
9001 alloc_info.descriptorPool = ds_pool;
9002 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009003 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009004 ASSERT_VK_SUCCESS(err);
9005
9006 // Create a buffer to be used for invalid updates
9007 VkBufferCreateInfo buff_ci = {};
9008 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9009 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9010 buff_ci.size = 256;
9011 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9012 VkBuffer buffer;
9013 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9014 ASSERT_VK_SUCCESS(err);
9015 // Have to bind memory to buffer before descriptor update
9016 VkMemoryAllocateInfo mem_alloc = {};
9017 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9018 mem_alloc.pNext = NULL;
9019 mem_alloc.allocationSize = 256;
9020 mem_alloc.memoryTypeIndex = 0;
9021
9022 VkMemoryRequirements mem_reqs;
9023 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009024 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009025 if (!pass) {
9026 vkDestroyBuffer(m_device->device(), buffer, NULL);
9027 return;
9028 }
9029
9030 VkDeviceMemory mem;
9031 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9032 ASSERT_VK_SUCCESS(err);
9033 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9034 ASSERT_VK_SUCCESS(err);
9035
9036 VkDescriptorBufferInfo buff_info = {};
9037 buff_info.buffer = buffer;
9038 // First make offset 1 larger than buffer size
9039 buff_info.offset = 257;
9040 buff_info.range = VK_WHOLE_SIZE;
9041 VkWriteDescriptorSet descriptor_write = {};
9042 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9043 descriptor_write.dstBinding = 0;
9044 descriptor_write.descriptorCount = 1;
9045 descriptor_write.pTexelBufferView = nullptr;
9046 descriptor_write.pBufferInfo = &buff_info;
9047 descriptor_write.pImageInfo = nullptr;
9048
9049 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9050 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009052
9053 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9054
9055 m_errorMonitor->VerifyFound();
9056 // Now cause error due to range of 0
9057 buff_info.offset = 0;
9058 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009060
9061 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9062
9063 m_errorMonitor->VerifyFound();
9064 // Now cause error due to range exceeding buffer size - offset
9065 buff_info.offset = 128;
9066 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009068
9069 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9070
9071 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009072 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009073 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9074 vkDestroyBuffer(m_device->device(), buffer, NULL);
9075 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9076 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9077}
9078
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009079TEST_F(VkLayerTest, DSAspectBitsErrors) {
9080 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9081 // are set, but could expand this test to hit more cases.
9082 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
9083 "that do not have correct aspect bits sets.");
9084 VkResult err;
9085
9086 ASSERT_NO_FATAL_FAILURE(InitState());
9087 VkDescriptorPoolSize ds_type_count = {};
9088 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9089 ds_type_count.descriptorCount = 1;
9090
9091 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9092 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9093 ds_pool_ci.pNext = NULL;
9094 ds_pool_ci.maxSets = 5;
9095 ds_pool_ci.poolSizeCount = 1;
9096 ds_pool_ci.pPoolSizes = &ds_type_count;
9097
9098 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009099 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009100 ASSERT_VK_SUCCESS(err);
9101
9102 VkDescriptorSetLayoutBinding dsl_binding = {};
9103 dsl_binding.binding = 0;
9104 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9105 dsl_binding.descriptorCount = 1;
9106 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9107 dsl_binding.pImmutableSamplers = NULL;
9108
9109 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9110 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9111 ds_layout_ci.pNext = NULL;
9112 ds_layout_ci.bindingCount = 1;
9113 ds_layout_ci.pBindings = &dsl_binding;
9114 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009115 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009116 ASSERT_VK_SUCCESS(err);
9117
9118 VkDescriptorSet descriptor_set = {};
9119 VkDescriptorSetAllocateInfo alloc_info = {};
9120 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9121 alloc_info.descriptorSetCount = 1;
9122 alloc_info.descriptorPool = ds_pool;
9123 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009124 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009125 ASSERT_VK_SUCCESS(err);
9126
9127 // Create an image to be used for invalid updates
9128 VkImageCreateInfo image_ci = {};
9129 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9130 image_ci.imageType = VK_IMAGE_TYPE_2D;
9131 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9132 image_ci.extent.width = 64;
9133 image_ci.extent.height = 64;
9134 image_ci.extent.depth = 1;
9135 image_ci.mipLevels = 1;
9136 image_ci.arrayLayers = 1;
9137 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9138 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9139 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9140 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9141 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9142 VkImage image;
9143 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9144 ASSERT_VK_SUCCESS(err);
9145 // Bind memory to image
9146 VkMemoryRequirements mem_reqs;
9147 VkDeviceMemory image_mem;
9148 bool pass;
9149 VkMemoryAllocateInfo mem_alloc = {};
9150 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9151 mem_alloc.pNext = NULL;
9152 mem_alloc.allocationSize = 0;
9153 mem_alloc.memoryTypeIndex = 0;
9154 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9155 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009156 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009157 ASSERT_TRUE(pass);
9158 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9159 ASSERT_VK_SUCCESS(err);
9160 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9161 ASSERT_VK_SUCCESS(err);
9162 // Now create view for image
9163 VkImageViewCreateInfo image_view_ci = {};
9164 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9165 image_view_ci.image = image;
9166 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9167 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9168 image_view_ci.subresourceRange.layerCount = 1;
9169 image_view_ci.subresourceRange.baseArrayLayer = 0;
9170 image_view_ci.subresourceRange.levelCount = 1;
9171 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009172 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009173
9174 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009175 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009176 ASSERT_VK_SUCCESS(err);
9177
9178 VkDescriptorImageInfo img_info = {};
9179 img_info.imageView = image_view;
9180 VkWriteDescriptorSet descriptor_write = {};
9181 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9182 descriptor_write.dstBinding = 0;
9183 descriptor_write.descriptorCount = 1;
9184 descriptor_write.pTexelBufferView = NULL;
9185 descriptor_write.pBufferInfo = NULL;
9186 descriptor_write.pImageInfo = &img_info;
9187 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9188 descriptor_write.dstSet = descriptor_set;
9189 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9190 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009192
9193 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9194
9195 m_errorMonitor->VerifyFound();
9196 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9197 vkDestroyImage(m_device->device(), image, NULL);
9198 vkFreeMemory(m_device->device(), image_mem, NULL);
9199 vkDestroyImageView(m_device->device(), image_view, NULL);
9200 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9201 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9202}
9203
Karl Schultz6addd812016-02-02 17:17:23 -07009204TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009205 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009206 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009207
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9209 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9210 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009211
Tobin Ehlis3b780662015-05-28 12:11:26 -06009212 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009213 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009214 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009215 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9216 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009217
9218 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009219 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9220 ds_pool_ci.pNext = NULL;
9221 ds_pool_ci.maxSets = 1;
9222 ds_pool_ci.poolSizeCount = 1;
9223 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009224
Tobin Ehlis3b780662015-05-28 12:11:26 -06009225 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009226 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009227 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009228 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009229 dsl_binding.binding = 0;
9230 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9231 dsl_binding.descriptorCount = 1;
9232 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9233 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009234
Tony Barboureb254902015-07-15 12:50:33 -06009235 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009236 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9237 ds_layout_ci.pNext = NULL;
9238 ds_layout_ci.bindingCount = 1;
9239 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009240
Tobin Ehlis3b780662015-05-28 12:11:26 -06009241 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009242 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009243 ASSERT_VK_SUCCESS(err);
9244
9245 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009246 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009247 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009248 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009249 alloc_info.descriptorPool = ds_pool;
9250 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009251 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009252 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009253
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009254 VkSamplerCreateInfo sampler_ci = {};
9255 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9256 sampler_ci.pNext = NULL;
9257 sampler_ci.magFilter = VK_FILTER_NEAREST;
9258 sampler_ci.minFilter = VK_FILTER_NEAREST;
9259 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9260 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9261 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9262 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9263 sampler_ci.mipLodBias = 1.0;
9264 sampler_ci.anisotropyEnable = VK_FALSE;
9265 sampler_ci.maxAnisotropy = 1;
9266 sampler_ci.compareEnable = VK_FALSE;
9267 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9268 sampler_ci.minLod = 1.0;
9269 sampler_ci.maxLod = 1.0;
9270 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9271 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9272 VkSampler sampler;
9273 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9274 ASSERT_VK_SUCCESS(err);
9275
9276 VkDescriptorImageInfo info = {};
9277 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009278
9279 VkWriteDescriptorSet descriptor_write;
9280 memset(&descriptor_write, 0, sizeof(descriptor_write));
9281 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009282 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009283 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009284 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009285 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009286 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009287
9288 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9289
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009290 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009291
Chia-I Wuf7458c52015-10-26 21:10:41 +08009292 vkDestroySampler(m_device->device(), sampler, NULL);
9293 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9294 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009295}
9296
Karl Schultz6addd812016-02-02 17:17:23 -07009297TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009298 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009299 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009300
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009302
Tobin Ehlis3b780662015-05-28 12:11:26 -06009303 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009304 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009305 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009306 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9307 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009308
9309 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009310 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9311 ds_pool_ci.pNext = NULL;
9312 ds_pool_ci.maxSets = 1;
9313 ds_pool_ci.poolSizeCount = 1;
9314 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009315
Tobin Ehlis3b780662015-05-28 12:11:26 -06009316 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009317 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009318 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009319
Tony Barboureb254902015-07-15 12:50:33 -06009320 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009321 dsl_binding.binding = 0;
9322 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9323 dsl_binding.descriptorCount = 1;
9324 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9325 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009326
9327 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009328 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9329 ds_layout_ci.pNext = NULL;
9330 ds_layout_ci.bindingCount = 1;
9331 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009332
Tobin Ehlis3b780662015-05-28 12:11:26 -06009333 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009334 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009335 ASSERT_VK_SUCCESS(err);
9336
9337 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009338 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009339 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009340 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009341 alloc_info.descriptorPool = ds_pool;
9342 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009343 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009344 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009345
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009346 // Correctly update descriptor to avoid "NOT_UPDATED" error
9347 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009348 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009349 buff_info.offset = 0;
9350 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009351
9352 VkWriteDescriptorSet descriptor_write;
9353 memset(&descriptor_write, 0, sizeof(descriptor_write));
9354 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009355 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009356 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009357 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009358 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9359 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009360
9361 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9362
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009363 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009364
Chia-I Wuf7458c52015-10-26 21:10:41 +08009365 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9366 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009367}
9368
Karl Schultz6addd812016-02-02 17:17:23 -07009369TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009370 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009371 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009372
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009374
Tobin Ehlis3b780662015-05-28 12:11:26 -06009375 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009376 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009377 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009378 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9379 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009380
9381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9383 ds_pool_ci.pNext = NULL;
9384 ds_pool_ci.maxSets = 1;
9385 ds_pool_ci.poolSizeCount = 1;
9386 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009387
Tobin Ehlis3b780662015-05-28 12:11:26 -06009388 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009389 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009390 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009391
Tony Barboureb254902015-07-15 12:50:33 -06009392 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009393 dsl_binding.binding = 0;
9394 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9395 dsl_binding.descriptorCount = 1;
9396 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9397 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009398
9399 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009400 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9401 ds_layout_ci.pNext = NULL;
9402 ds_layout_ci.bindingCount = 1;
9403 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009404 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009405 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009406 ASSERT_VK_SUCCESS(err);
9407
9408 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009409 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009410 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009411 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009412 alloc_info.descriptorPool = ds_pool;
9413 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009414 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009415 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009416
Tony Barboureb254902015-07-15 12:50:33 -06009417 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009418 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9419 sampler_ci.pNext = NULL;
9420 sampler_ci.magFilter = VK_FILTER_NEAREST;
9421 sampler_ci.minFilter = VK_FILTER_NEAREST;
9422 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9423 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9424 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9425 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9426 sampler_ci.mipLodBias = 1.0;
9427 sampler_ci.anisotropyEnable = VK_FALSE;
9428 sampler_ci.maxAnisotropy = 1;
9429 sampler_ci.compareEnable = VK_FALSE;
9430 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9431 sampler_ci.minLod = 1.0;
9432 sampler_ci.maxLod = 1.0;
9433 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9434 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009435
Tobin Ehlis3b780662015-05-28 12:11:26 -06009436 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009437 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009438 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009439
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009440 VkDescriptorImageInfo info = {};
9441 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009442
9443 VkWriteDescriptorSet descriptor_write;
9444 memset(&descriptor_write, 0, sizeof(descriptor_write));
9445 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009446 descriptor_write.dstSet = descriptorSet;
9447 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009448 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009449 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009450 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009451 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009452
9453 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9454
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009455 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009456
Chia-I Wuf7458c52015-10-26 21:10:41 +08009457 vkDestroySampler(m_device->device(), sampler, NULL);
9458 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9459 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009460}
9461
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009462TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9463 // Create layout w/ empty binding and attempt to update it
9464 VkResult err;
9465
9466 ASSERT_NO_FATAL_FAILURE(InitState());
9467
9468 VkDescriptorPoolSize ds_type_count = {};
9469 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9470 ds_type_count.descriptorCount = 1;
9471
9472 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9473 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9474 ds_pool_ci.pNext = NULL;
9475 ds_pool_ci.maxSets = 1;
9476 ds_pool_ci.poolSizeCount = 1;
9477 ds_pool_ci.pPoolSizes = &ds_type_count;
9478
9479 VkDescriptorPool ds_pool;
9480 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9481 ASSERT_VK_SUCCESS(err);
9482
9483 VkDescriptorSetLayoutBinding dsl_binding = {};
9484 dsl_binding.binding = 0;
9485 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9486 dsl_binding.descriptorCount = 0;
9487 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9488 dsl_binding.pImmutableSamplers = NULL;
9489
9490 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9491 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9492 ds_layout_ci.pNext = NULL;
9493 ds_layout_ci.bindingCount = 1;
9494 ds_layout_ci.pBindings = &dsl_binding;
9495 VkDescriptorSetLayout ds_layout;
9496 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9497 ASSERT_VK_SUCCESS(err);
9498
9499 VkDescriptorSet descriptor_set;
9500 VkDescriptorSetAllocateInfo alloc_info = {};
9501 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9502 alloc_info.descriptorSetCount = 1;
9503 alloc_info.descriptorPool = ds_pool;
9504 alloc_info.pSetLayouts = &ds_layout;
9505 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9506 ASSERT_VK_SUCCESS(err);
9507
9508 VkSamplerCreateInfo sampler_ci = {};
9509 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9510 sampler_ci.magFilter = VK_FILTER_NEAREST;
9511 sampler_ci.minFilter = VK_FILTER_NEAREST;
9512 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9513 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9514 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9515 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9516 sampler_ci.mipLodBias = 1.0;
9517 sampler_ci.maxAnisotropy = 1;
9518 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9519 sampler_ci.minLod = 1.0;
9520 sampler_ci.maxLod = 1.0;
9521 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9522
9523 VkSampler sampler;
9524 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9525 ASSERT_VK_SUCCESS(err);
9526
9527 VkDescriptorImageInfo info = {};
9528 info.sampler = sampler;
9529
9530 VkWriteDescriptorSet descriptor_write;
9531 memset(&descriptor_write, 0, sizeof(descriptor_write));
9532 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9533 descriptor_write.dstSet = descriptor_set;
9534 descriptor_write.dstBinding = 0;
9535 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9536 // This is the wrong type, but empty binding error will be flagged first
9537 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9538 descriptor_write.pImageInfo = &info;
9539
9540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9541 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9542 m_errorMonitor->VerifyFound();
9543
9544 vkDestroySampler(m_device->device(), sampler, NULL);
9545 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9546 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9547}
9548
Karl Schultz6addd812016-02-02 17:17:23 -07009549TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9550 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9551 // types
9552 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009553
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009554 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 -06009555
Tobin Ehlis3b780662015-05-28 12:11:26 -06009556 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009557
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009558 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009559 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9560 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009561
9562 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009563 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9564 ds_pool_ci.pNext = NULL;
9565 ds_pool_ci.maxSets = 1;
9566 ds_pool_ci.poolSizeCount = 1;
9567 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009568
Tobin Ehlis3b780662015-05-28 12:11:26 -06009569 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009570 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009571 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009572 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009573 dsl_binding.binding = 0;
9574 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9575 dsl_binding.descriptorCount = 1;
9576 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9577 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009578
Tony Barboureb254902015-07-15 12:50:33 -06009579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9581 ds_layout_ci.pNext = NULL;
9582 ds_layout_ci.bindingCount = 1;
9583 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009584
Tobin Ehlis3b780662015-05-28 12:11:26 -06009585 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009586 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009587 ASSERT_VK_SUCCESS(err);
9588
9589 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009590 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009591 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009592 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009593 alloc_info.descriptorPool = ds_pool;
9594 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009595 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009596 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009597
Tony Barboureb254902015-07-15 12:50:33 -06009598 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009599 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9600 sampler_ci.pNext = NULL;
9601 sampler_ci.magFilter = VK_FILTER_NEAREST;
9602 sampler_ci.minFilter = VK_FILTER_NEAREST;
9603 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9604 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9605 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9606 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9607 sampler_ci.mipLodBias = 1.0;
9608 sampler_ci.anisotropyEnable = VK_FALSE;
9609 sampler_ci.maxAnisotropy = 1;
9610 sampler_ci.compareEnable = VK_FALSE;
9611 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9612 sampler_ci.minLod = 1.0;
9613 sampler_ci.maxLod = 1.0;
9614 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9615 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009616 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009617 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009618 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009619
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009620 VkDescriptorImageInfo info = {};
9621 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009622
9623 VkWriteDescriptorSet descriptor_write;
9624 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009625 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009626 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009627 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009628 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009629 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009630 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009631
9632 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9633
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009634 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009635
Chia-I Wuf7458c52015-10-26 21:10:41 +08009636 vkDestroySampler(m_device->device(), sampler, NULL);
9637 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9638 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009639}
9640
Karl Schultz6addd812016-02-02 17:17:23 -07009641TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009642 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009643 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009644
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009646
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009647 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009648 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9649 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009650 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009651 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9652 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009653
9654 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009655 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9656 ds_pool_ci.pNext = NULL;
9657 ds_pool_ci.maxSets = 1;
9658 ds_pool_ci.poolSizeCount = 1;
9659 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009660
9661 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009662 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009663 ASSERT_VK_SUCCESS(err);
9664
9665 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009666 dsl_binding.binding = 0;
9667 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9668 dsl_binding.descriptorCount = 1;
9669 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9670 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009671
9672 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009673 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9674 ds_layout_ci.pNext = NULL;
9675 ds_layout_ci.bindingCount = 1;
9676 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009677 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009678 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009679 ASSERT_VK_SUCCESS(err);
9680
9681 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009682 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009683 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009684 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009685 alloc_info.descriptorPool = ds_pool;
9686 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009687 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009688 ASSERT_VK_SUCCESS(err);
9689
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009690 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009691
9692 VkDescriptorImageInfo descriptor_info;
9693 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9694 descriptor_info.sampler = sampler;
9695
9696 VkWriteDescriptorSet descriptor_write;
9697 memset(&descriptor_write, 0, sizeof(descriptor_write));
9698 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009699 descriptor_write.dstSet = descriptorSet;
9700 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009701 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009702 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9703 descriptor_write.pImageInfo = &descriptor_info;
9704
9705 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9706
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009707 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009708
Chia-I Wuf7458c52015-10-26 21:10:41 +08009709 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9710 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009711}
9712
Karl Schultz6addd812016-02-02 17:17:23 -07009713TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9714 // Create a single combined Image/Sampler descriptor and send it an invalid
9715 // imageView
9716 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009717
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009719
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009720 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009721 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009722 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9723 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009724
9725 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009726 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9727 ds_pool_ci.pNext = NULL;
9728 ds_pool_ci.maxSets = 1;
9729 ds_pool_ci.poolSizeCount = 1;
9730 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009731
9732 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009734 ASSERT_VK_SUCCESS(err);
9735
9736 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009737 dsl_binding.binding = 0;
9738 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9739 dsl_binding.descriptorCount = 1;
9740 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9741 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009742
9743 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009744 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9745 ds_layout_ci.pNext = NULL;
9746 ds_layout_ci.bindingCount = 1;
9747 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009748 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009749 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009750 ASSERT_VK_SUCCESS(err);
9751
9752 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009753 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009754 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009755 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009756 alloc_info.descriptorPool = ds_pool;
9757 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009758 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009759 ASSERT_VK_SUCCESS(err);
9760
9761 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009762 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9763 sampler_ci.pNext = NULL;
9764 sampler_ci.magFilter = VK_FILTER_NEAREST;
9765 sampler_ci.minFilter = VK_FILTER_NEAREST;
9766 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9767 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9768 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9769 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9770 sampler_ci.mipLodBias = 1.0;
9771 sampler_ci.anisotropyEnable = VK_FALSE;
9772 sampler_ci.maxAnisotropy = 1;
9773 sampler_ci.compareEnable = VK_FALSE;
9774 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9775 sampler_ci.minLod = 1.0;
9776 sampler_ci.maxLod = 1.0;
9777 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9778 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009779
9780 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009781 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009782 ASSERT_VK_SUCCESS(err);
9783
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009784 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009785
9786 VkDescriptorImageInfo descriptor_info;
9787 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9788 descriptor_info.sampler = sampler;
9789 descriptor_info.imageView = view;
9790
9791 VkWriteDescriptorSet descriptor_write;
9792 memset(&descriptor_write, 0, sizeof(descriptor_write));
9793 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009794 descriptor_write.dstSet = descriptorSet;
9795 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009796 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009797 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9798 descriptor_write.pImageInfo = &descriptor_info;
9799
9800 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9801
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009802 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009803
Chia-I Wuf7458c52015-10-26 21:10:41 +08009804 vkDestroySampler(m_device->device(), sampler, NULL);
9805 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9806 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009807}
9808
Karl Schultz6addd812016-02-02 17:17:23 -07009809TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9810 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9811 // into the other
9812 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009813
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9815 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9816 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009817
Tobin Ehlis04356f92015-10-27 16:35:27 -06009818 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009819 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009820 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009821 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9822 ds_type_count[0].descriptorCount = 1;
9823 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9824 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009825
9826 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009827 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9828 ds_pool_ci.pNext = NULL;
9829 ds_pool_ci.maxSets = 1;
9830 ds_pool_ci.poolSizeCount = 2;
9831 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009832
9833 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009834 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009835 ASSERT_VK_SUCCESS(err);
9836 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009837 dsl_binding[0].binding = 0;
9838 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9839 dsl_binding[0].descriptorCount = 1;
9840 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9841 dsl_binding[0].pImmutableSamplers = NULL;
9842 dsl_binding[1].binding = 1;
9843 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9844 dsl_binding[1].descriptorCount = 1;
9845 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9846 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009847
9848 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009849 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9850 ds_layout_ci.pNext = NULL;
9851 ds_layout_ci.bindingCount = 2;
9852 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009853
9854 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009855 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009856 ASSERT_VK_SUCCESS(err);
9857
9858 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009859 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009860 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009861 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009862 alloc_info.descriptorPool = ds_pool;
9863 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009864 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009865 ASSERT_VK_SUCCESS(err);
9866
9867 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009868 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9869 sampler_ci.pNext = NULL;
9870 sampler_ci.magFilter = VK_FILTER_NEAREST;
9871 sampler_ci.minFilter = VK_FILTER_NEAREST;
9872 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9873 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9874 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9875 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9876 sampler_ci.mipLodBias = 1.0;
9877 sampler_ci.anisotropyEnable = VK_FALSE;
9878 sampler_ci.maxAnisotropy = 1;
9879 sampler_ci.compareEnable = VK_FALSE;
9880 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9881 sampler_ci.minLod = 1.0;
9882 sampler_ci.maxLod = 1.0;
9883 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9884 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009885
9886 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009887 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009888 ASSERT_VK_SUCCESS(err);
9889
9890 VkDescriptorImageInfo info = {};
9891 info.sampler = sampler;
9892
9893 VkWriteDescriptorSet descriptor_write;
9894 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9895 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009896 descriptor_write.dstSet = descriptorSet;
9897 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009898 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009899 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9900 descriptor_write.pImageInfo = &info;
9901 // This write update should succeed
9902 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9903 // Now perform a copy update that fails due to type mismatch
9904 VkCopyDescriptorSet copy_ds_update;
9905 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9906 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9907 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009908 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009909 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009910 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009911 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009912 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9913
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009914 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009915 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009916 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 -06009917 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9918 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9919 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009920 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009921 copy_ds_update.dstSet = descriptorSet;
9922 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009923 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009924 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9925
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009926 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009927
Tobin Ehlis04356f92015-10-27 16:35:27 -06009928 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9930 "update array offset of 0 and update of "
9931 "5 descriptors oversteps total number "
9932 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009933
Tobin Ehlis04356f92015-10-27 16:35:27 -06009934 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9935 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9936 copy_ds_update.srcSet = descriptorSet;
9937 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009938 copy_ds_update.dstSet = descriptorSet;
9939 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009940 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009941 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9942
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009943 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009944
Chia-I Wuf7458c52015-10-26 21:10:41 +08009945 vkDestroySampler(m_device->device(), sampler, NULL);
9946 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9947 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009948}
9949
Karl Schultz6addd812016-02-02 17:17:23 -07009950TEST_F(VkLayerTest, NumSamplesMismatch) {
9951 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9952 // sampleCount
9953 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009954
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009955 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009956
Tobin Ehlis3b780662015-05-28 12:11:26 -06009957 ASSERT_NO_FATAL_FAILURE(InitState());
9958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009959 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009960 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009961 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009962
9963 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009964 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9965 ds_pool_ci.pNext = NULL;
9966 ds_pool_ci.maxSets = 1;
9967 ds_pool_ci.poolSizeCount = 1;
9968 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009969
Tobin Ehlis3b780662015-05-28 12:11:26 -06009970 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009971 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009972 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009973
Tony Barboureb254902015-07-15 12:50:33 -06009974 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009975 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009976 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009977 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009978 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9979 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009980
Tony Barboureb254902015-07-15 12:50:33 -06009981 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9982 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9983 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009984 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009985 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009986
Tobin Ehlis3b780662015-05-28 12:11:26 -06009987 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009988 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009989 ASSERT_VK_SUCCESS(err);
9990
9991 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009992 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009993 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009994 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009995 alloc_info.descriptorPool = ds_pool;
9996 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009997 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009998 ASSERT_VK_SUCCESS(err);
9999
Tony Barboureb254902015-07-15 12:50:33 -060010000 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010001 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010002 pipe_ms_state_ci.pNext = NULL;
10003 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10004 pipe_ms_state_ci.sampleShadingEnable = 0;
10005 pipe_ms_state_ci.minSampleShading = 1.0;
10006 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010007
Tony Barboureb254902015-07-15 12:50:33 -060010008 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010009 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10010 pipeline_layout_ci.pNext = NULL;
10011 pipeline_layout_ci.setLayoutCount = 1;
10012 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010013
10014 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010015 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010016 ASSERT_VK_SUCCESS(err);
10017
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010018 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10019 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10020 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010021 VkPipelineObj pipe(m_device);
10022 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010023 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010024 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010025 pipe.SetMSAA(&pipe_ms_state_ci);
10026 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010027
Tony Barbour552f6c02016-12-21 14:34:07 -070010028 m_commandBuffer->BeginCommandBuffer();
10029 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010030 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010031
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010032 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10033 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10034 VkRect2D scissor = {{0, 0}, {16, 16}};
10035 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10036
Mark Young29927482016-05-04 14:38:51 -060010037 // Render triangle (the error should trigger on the attempt to draw).
10038 Draw(3, 1, 0, 0);
10039
10040 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010041 m_commandBuffer->EndRenderPass();
10042 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010043
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010044 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010045
Chia-I Wuf7458c52015-10-26 21:10:41 +080010046 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10047 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10048 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010049}
Mark Young29927482016-05-04 14:38:51 -060010050
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010051TEST_F(VkLayerTest, RenderPassIncompatible) {
10052 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
10053 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -060010054 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010055 VkResult err;
10056
10057 ASSERT_NO_FATAL_FAILURE(InitState());
10058 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10059
10060 VkDescriptorSetLayoutBinding dsl_binding = {};
10061 dsl_binding.binding = 0;
10062 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10063 dsl_binding.descriptorCount = 1;
10064 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10065 dsl_binding.pImmutableSamplers = NULL;
10066
10067 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10068 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10069 ds_layout_ci.pNext = NULL;
10070 ds_layout_ci.bindingCount = 1;
10071 ds_layout_ci.pBindings = &dsl_binding;
10072
10073 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010074 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010075 ASSERT_VK_SUCCESS(err);
10076
10077 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10078 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10079 pipeline_layout_ci.pNext = NULL;
10080 pipeline_layout_ci.setLayoutCount = 1;
10081 pipeline_layout_ci.pSetLayouts = &ds_layout;
10082
10083 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010084 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010085 ASSERT_VK_SUCCESS(err);
10086
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010087 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10088 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10089 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010090 // Create a renderpass that will be incompatible with default renderpass
10091 VkAttachmentReference attach = {};
10092 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10093 VkAttachmentReference color_att = {};
10094 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10095 VkSubpassDescription subpass = {};
10096 subpass.inputAttachmentCount = 1;
10097 subpass.pInputAttachments = &attach;
10098 subpass.colorAttachmentCount = 1;
10099 subpass.pColorAttachments = &color_att;
10100 VkRenderPassCreateInfo rpci = {};
10101 rpci.subpassCount = 1;
10102 rpci.pSubpasses = &subpass;
10103 rpci.attachmentCount = 1;
10104 VkAttachmentDescription attach_desc = {};
10105 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010106 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10107 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010108 rpci.pAttachments = &attach_desc;
10109 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10110 VkRenderPass rp;
10111 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10112 VkPipelineObj pipe(m_device);
10113 pipe.AddShader(&vs);
10114 pipe.AddShader(&fs);
10115 pipe.AddColorAttachment();
10116 VkViewport view_port = {};
10117 m_viewports.push_back(view_port);
10118 pipe.SetViewport(m_viewports);
10119 VkRect2D rect = {};
10120 m_scissors.push_back(rect);
10121 pipe.SetScissor(m_scissors);
10122 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10123
10124 VkCommandBufferInheritanceInfo cbii = {};
10125 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10126 cbii.renderPass = rp;
10127 cbii.subpass = 0;
10128 VkCommandBufferBeginInfo cbbi = {};
10129 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10130 cbbi.pInheritanceInfo = &cbii;
10131 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10132 VkRenderPassBeginInfo rpbi = {};
10133 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10134 rpbi.framebuffer = m_framebuffer;
10135 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010136 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10137 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010138
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010140 // Render triangle (the error should trigger on the attempt to draw).
10141 Draw(3, 1, 0, 0);
10142
10143 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010144 m_commandBuffer->EndRenderPass();
10145 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010146
10147 m_errorMonitor->VerifyFound();
10148
10149 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10150 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10151 vkDestroyRenderPass(m_device->device(), rp, NULL);
10152}
10153
Mark Youngc89c6312016-03-31 16:03:20 -060010154TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10155 // Create Pipeline where the number of blend attachments doesn't match the
10156 // number of color attachments. In this case, we don't add any color
10157 // blend attachments even though we have a color attachment.
10158 VkResult err;
10159
10160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010161 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010162
10163 ASSERT_NO_FATAL_FAILURE(InitState());
10164 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10165 VkDescriptorPoolSize ds_type_count = {};
10166 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10167 ds_type_count.descriptorCount = 1;
10168
10169 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10170 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10171 ds_pool_ci.pNext = NULL;
10172 ds_pool_ci.maxSets = 1;
10173 ds_pool_ci.poolSizeCount = 1;
10174 ds_pool_ci.pPoolSizes = &ds_type_count;
10175
10176 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010177 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010178 ASSERT_VK_SUCCESS(err);
10179
10180 VkDescriptorSetLayoutBinding dsl_binding = {};
10181 dsl_binding.binding = 0;
10182 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10183 dsl_binding.descriptorCount = 1;
10184 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10185 dsl_binding.pImmutableSamplers = NULL;
10186
10187 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10188 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10189 ds_layout_ci.pNext = NULL;
10190 ds_layout_ci.bindingCount = 1;
10191 ds_layout_ci.pBindings = &dsl_binding;
10192
10193 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010194 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010195 ASSERT_VK_SUCCESS(err);
10196
10197 VkDescriptorSet descriptorSet;
10198 VkDescriptorSetAllocateInfo alloc_info = {};
10199 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10200 alloc_info.descriptorSetCount = 1;
10201 alloc_info.descriptorPool = ds_pool;
10202 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010203 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010204 ASSERT_VK_SUCCESS(err);
10205
10206 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010207 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010208 pipe_ms_state_ci.pNext = NULL;
10209 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10210 pipe_ms_state_ci.sampleShadingEnable = 0;
10211 pipe_ms_state_ci.minSampleShading = 1.0;
10212 pipe_ms_state_ci.pSampleMask = NULL;
10213
10214 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10215 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10216 pipeline_layout_ci.pNext = NULL;
10217 pipeline_layout_ci.setLayoutCount = 1;
10218 pipeline_layout_ci.pSetLayouts = &ds_layout;
10219
10220 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010221 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010222 ASSERT_VK_SUCCESS(err);
10223
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010224 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10225 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10226 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010227 VkPipelineObj pipe(m_device);
10228 pipe.AddShader(&vs);
10229 pipe.AddShader(&fs);
10230 pipe.SetMSAA(&pipe_ms_state_ci);
10231 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10232
Tony Barbour552f6c02016-12-21 14:34:07 -070010233 m_commandBuffer->BeginCommandBuffer();
10234 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010235 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010236
Rene Lindsay6d5c4fe2017-01-13 09:41:19 -070010237 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10238 VkRect2D scissor = {{0, 0}, {16, 16}};
10239 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10240 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10241
Mark Young29927482016-05-04 14:38:51 -060010242 // Render triangle (the error should trigger on the attempt to draw).
10243 Draw(3, 1, 0, 0);
10244
10245 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010246 m_commandBuffer->EndRenderPass();
10247 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010248
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010249 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010250
10251 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10252 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10253 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10254}
Mark Young29927482016-05-04 14:38:51 -060010255
Mark Muellerd4914412016-06-13 17:52:06 -060010256TEST_F(VkLayerTest, MissingClearAttachment) {
10257 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10258 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010259 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010261
10262 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10263 m_errorMonitor->VerifyFound();
10264}
10265
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010266TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010267
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010268 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10269 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010270
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010271 ASSERT_NO_FATAL_FAILURE(InitState());
10272 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010273
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010274 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010275 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10276 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010277
10278 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010279 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10280 ds_pool_ci.pNext = NULL;
10281 ds_pool_ci.maxSets = 1;
10282 ds_pool_ci.poolSizeCount = 1;
10283 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010284
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010285 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010286 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010287 ASSERT_VK_SUCCESS(err);
10288
Tony Barboureb254902015-07-15 12:50:33 -060010289 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010290 dsl_binding.binding = 0;
10291 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10292 dsl_binding.descriptorCount = 1;
10293 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10294 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010295
Tony Barboureb254902015-07-15 12:50:33 -060010296 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010297 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10298 ds_layout_ci.pNext = NULL;
10299 ds_layout_ci.bindingCount = 1;
10300 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010301
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010302 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010303 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010304 ASSERT_VK_SUCCESS(err);
10305
10306 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010307 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010308 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010309 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010310 alloc_info.descriptorPool = ds_pool;
10311 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010312 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010313 ASSERT_VK_SUCCESS(err);
10314
Tony Barboureb254902015-07-15 12:50:33 -060010315 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010316 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010317 pipe_ms_state_ci.pNext = NULL;
10318 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10319 pipe_ms_state_ci.sampleShadingEnable = 0;
10320 pipe_ms_state_ci.minSampleShading = 1.0;
10321 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010322
Tony Barboureb254902015-07-15 12:50:33 -060010323 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010324 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10325 pipeline_layout_ci.pNext = NULL;
10326 pipeline_layout_ci.setLayoutCount = 1;
10327 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010328
10329 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010331 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010332
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010333 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010334 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010335 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010336 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010337
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010338 VkPipelineObj pipe(m_device);
10339 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010340 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010341 pipe.SetMSAA(&pipe_ms_state_ci);
10342 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010343
Tony Barbour552f6c02016-12-21 14:34:07 -070010344 m_commandBuffer->BeginCommandBuffer();
10345 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010346
Karl Schultz6addd812016-02-02 17:17:23 -070010347 // Main thing we care about for this test is that the VkImage obj we're
10348 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010349 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010350 VkClearAttachment color_attachment;
10351 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10352 color_attachment.clearValue.color.float32[0] = 1.0;
10353 color_attachment.clearValue.color.float32[1] = 1.0;
10354 color_attachment.clearValue.color.float32[2] = 1.0;
10355 color_attachment.clearValue.color.float32[3] = 1.0;
10356 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010357 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010358
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010359 // Call for full-sized FB Color attachment prior to issuing a Draw
10360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10361 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010362 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010363 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010364
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010365
10366 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10367 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10369 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10370 m_errorMonitor->VerifyFound();
10371
10372 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10373 clear_rect.layerCount = 2;
10374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10375 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010376 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010377
Chia-I Wuf7458c52015-10-26 21:10:41 +080010378 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10379 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10380 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010381}
10382
Karl Schultz6addd812016-02-02 17:17:23 -070010383TEST_F(VkLayerTest, VtxBufferBadIndex) {
10384 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010385
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10387 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010388
Tobin Ehlis502480b2015-06-24 15:53:07 -060010389 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010390 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010392
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010393 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010394 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10395 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010396
10397 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010398 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10399 ds_pool_ci.pNext = NULL;
10400 ds_pool_ci.maxSets = 1;
10401 ds_pool_ci.poolSizeCount = 1;
10402 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010403
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010404 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010405 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010406 ASSERT_VK_SUCCESS(err);
10407
Tony Barboureb254902015-07-15 12:50:33 -060010408 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010409 dsl_binding.binding = 0;
10410 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10411 dsl_binding.descriptorCount = 1;
10412 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10413 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010414
Tony Barboureb254902015-07-15 12:50:33 -060010415 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010416 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10417 ds_layout_ci.pNext = NULL;
10418 ds_layout_ci.bindingCount = 1;
10419 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010420
Tobin Ehlis502480b2015-06-24 15:53:07 -060010421 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010422 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010423 ASSERT_VK_SUCCESS(err);
10424
10425 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010426 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010427 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010428 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010429 alloc_info.descriptorPool = ds_pool;
10430 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010431 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010432 ASSERT_VK_SUCCESS(err);
10433
Tony Barboureb254902015-07-15 12:50:33 -060010434 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010435 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010436 pipe_ms_state_ci.pNext = NULL;
10437 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10438 pipe_ms_state_ci.sampleShadingEnable = 0;
10439 pipe_ms_state_ci.minSampleShading = 1.0;
10440 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010441
Tony Barboureb254902015-07-15 12:50:33 -060010442 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010443 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10444 pipeline_layout_ci.pNext = NULL;
10445 pipeline_layout_ci.setLayoutCount = 1;
10446 pipeline_layout_ci.pSetLayouts = &ds_layout;
10447 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010449 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010450 ASSERT_VK_SUCCESS(err);
10451
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010452 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10453 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10454 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010455 VkPipelineObj pipe(m_device);
10456 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010457 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010458 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010459 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010460 pipe.SetViewport(m_viewports);
10461 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010462 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010463
Tony Barbour552f6c02016-12-21 14:34:07 -070010464 m_commandBuffer->BeginCommandBuffer();
10465 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010466 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010467 // Don't care about actual data, just need to get to draw to flag error
10468 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010469 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010470 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010471 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010472
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010473 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010474
Chia-I Wuf7458c52015-10-26 21:10:41 +080010475 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10476 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10477 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010478}
Mark Muellerdfe37552016-07-07 14:47:42 -060010479
Mark Mueller2ee294f2016-08-04 12:59:48 -060010480TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10481 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10482 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010483 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010484
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010485 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10486 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010488 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010489
Mark Mueller880fce52016-08-17 15:23:23 -060010490 // The following test fails with recent NVidia drivers.
10491 // By the time core_validation is reached, the NVidia
10492 // driver has sanitized the invalid condition and core_validation
10493 // is not introduced to the failure condition. This is not the case
10494 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010495 // uint32_t count = static_cast<uint32_t>(~0);
10496 // VkPhysicalDevice physical_device;
10497 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10498 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010499
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010500 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010501 float queue_priority = 0.0;
10502
10503 VkDeviceQueueCreateInfo queue_create_info = {};
10504 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10505 queue_create_info.queueCount = 1;
10506 queue_create_info.pQueuePriorities = &queue_priority;
10507 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10508
10509 VkPhysicalDeviceFeatures features = m_device->phy().features();
10510 VkDevice testDevice;
10511 VkDeviceCreateInfo device_create_info = {};
10512 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10513 device_create_info.queueCreateInfoCount = 1;
10514 device_create_info.pQueueCreateInfos = &queue_create_info;
10515 device_create_info.pEnabledFeatures = &features;
10516 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10517 m_errorMonitor->VerifyFound();
10518
10519 queue_create_info.queueFamilyIndex = 1;
10520
10521 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10522 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10523 for (unsigned i = 0; i < feature_count; i++) {
10524 if (VK_FALSE == feature_array[i]) {
10525 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010527 device_create_info.pEnabledFeatures = &features;
10528 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10529 m_errorMonitor->VerifyFound();
10530 break;
10531 }
10532 }
10533}
10534
Tobin Ehlis16edf082016-11-21 12:33:49 -070010535TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10536 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10537
10538 ASSERT_NO_FATAL_FAILURE(InitState());
10539
10540 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10541 std::vector<VkDeviceQueueCreateInfo> queue_info;
10542 queue_info.reserve(queue_props.size());
10543 std::vector<std::vector<float>> queue_priorities;
10544 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10545 VkDeviceQueueCreateInfo qi{};
10546 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10547 qi.queueFamilyIndex = i;
10548 qi.queueCount = queue_props[i].queueCount;
10549 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10550 qi.pQueuePriorities = queue_priorities[i].data();
10551 queue_info.push_back(qi);
10552 }
10553
10554 std::vector<const char *> device_extension_names;
10555
10556 VkDevice local_device;
10557 VkDeviceCreateInfo device_create_info = {};
10558 auto features = m_device->phy().features();
10559 // Intentionally disable pipeline stats
10560 features.pipelineStatisticsQuery = VK_FALSE;
10561 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10562 device_create_info.pNext = NULL;
10563 device_create_info.queueCreateInfoCount = queue_info.size();
10564 device_create_info.pQueueCreateInfos = queue_info.data();
10565 device_create_info.enabledLayerCount = 0;
10566 device_create_info.ppEnabledLayerNames = NULL;
10567 device_create_info.pEnabledFeatures = &features;
10568 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10569 ASSERT_VK_SUCCESS(err);
10570
10571 VkQueryPoolCreateInfo qpci{};
10572 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10573 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10574 qpci.queryCount = 1;
10575 VkQueryPool query_pool;
10576
10577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10578 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10579 m_errorMonitor->VerifyFound();
10580
10581 vkDestroyDevice(local_device, nullptr);
10582}
10583
Mark Mueller2ee294f2016-08-04 12:59:48 -060010584TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10585 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10586 "End a command buffer with a query still in progress.");
10587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010588 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10589 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10590 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010591
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010592 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010593
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010595
10596 ASSERT_NO_FATAL_FAILURE(InitState());
10597
10598 VkEvent event;
10599 VkEventCreateInfo event_create_info{};
10600 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10601 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10602
Mark Mueller2ee294f2016-08-04 12:59:48 -060010603 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010604 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010605
Tony Barbour552f6c02016-12-21 14:34:07 -070010606 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010607
10608 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010609 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 -060010610 ASSERT_TRUE(image.initialized());
10611 VkImageMemoryBarrier img_barrier = {};
10612 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10613 img_barrier.pNext = NULL;
10614 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10615 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10616 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10617 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10618 img_barrier.image = image.handle();
10619 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010620
10621 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10622 // that layer validation catches the case when it is not.
10623 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010624 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10625 img_barrier.subresourceRange.baseArrayLayer = 0;
10626 img_barrier.subresourceRange.baseMipLevel = 0;
10627 img_barrier.subresourceRange.layerCount = 1;
10628 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010629 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10630 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010631 m_errorMonitor->VerifyFound();
10632
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010634
10635 VkQueryPool query_pool;
10636 VkQueryPoolCreateInfo query_pool_create_info = {};
10637 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10638 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10639 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010640 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010641
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010642 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010643 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10644
10645 vkEndCommandBuffer(m_commandBuffer->handle());
10646 m_errorMonitor->VerifyFound();
10647
10648 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10649 vkDestroyEvent(m_device->device(), event, nullptr);
10650}
10651
Mark Muellerdfe37552016-07-07 14:47:42 -060010652TEST_F(VkLayerTest, VertexBufferInvalid) {
10653 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10654 "delete a buffer twice, use an invalid offset for each "
10655 "buffer type, and attempt to bind a null buffer");
10656
10657 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10658 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010659 const char *invalid_offset_message = "vkBindBufferMemory(): "
10660 "memoryOffset is 0x";
10661 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10662 "storage memoryOffset "
10663 "is 0x";
10664 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10665 "texel memoryOffset "
10666 "is 0x";
10667 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10668 "uniform memoryOffset "
10669 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010670
10671 ASSERT_NO_FATAL_FAILURE(InitState());
10672 ASSERT_NO_FATAL_FAILURE(InitViewport());
10673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10674
10675 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010676 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010677 pipe_ms_state_ci.pNext = NULL;
10678 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10679 pipe_ms_state_ci.sampleShadingEnable = 0;
10680 pipe_ms_state_ci.minSampleShading = 1.0;
10681 pipe_ms_state_ci.pSampleMask = nullptr;
10682
10683 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10684 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10685 VkPipelineLayout pipeline_layout;
10686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010687 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010688 ASSERT_VK_SUCCESS(err);
10689
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010690 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10691 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010692 VkPipelineObj pipe(m_device);
10693 pipe.AddShader(&vs);
10694 pipe.AddShader(&fs);
10695 pipe.AddColorAttachment();
10696 pipe.SetMSAA(&pipe_ms_state_ci);
10697 pipe.SetViewport(m_viewports);
10698 pipe.SetScissor(m_scissors);
10699 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10700
Tony Barbour552f6c02016-12-21 14:34:07 -070010701 m_commandBuffer->BeginCommandBuffer();
10702 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010703 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010704
10705 {
10706 // Create and bind a vertex buffer in a reduced scope, which will cause
10707 // it to be deleted upon leaving this scope
10708 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010709 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010710 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10711 draw_verticies.AddVertexInputToPipe(pipe);
10712 }
10713
10714 Draw(1, 0, 0, 0);
10715
Tony Barbour552f6c02016-12-21 14:34:07 -070010716 m_commandBuffer->EndRenderPass();
10717 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010718
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010720 QueueCommandBuffer(false);
10721 m_errorMonitor->VerifyFound();
10722
10723 {
10724 // Create and bind a vertex buffer in a reduced scope, and delete it
10725 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010726 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010728 buffer_test.TestDoubleDestroy();
10729 }
10730 m_errorMonitor->VerifyFound();
10731
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010732 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010733 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10735 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10736 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010737 m_errorMonitor->VerifyFound();
10738 }
10739
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010740 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10741 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010742 // Create and bind a memory buffer with an invalid offset again,
10743 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10745 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10746 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010747 m_errorMonitor->VerifyFound();
10748 }
10749
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010750 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010751 // Create and bind a memory buffer with an invalid offset again, but
10752 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10754 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10755 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010756 m_errorMonitor->VerifyFound();
10757 }
10758
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010759 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010760 // Create and bind a memory buffer with an invalid offset again, but
10761 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10763 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10764 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010765 m_errorMonitor->VerifyFound();
10766 }
10767
10768 {
10769 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010771 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10772 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010773 m_errorMonitor->VerifyFound();
10774 }
10775
10776 {
10777 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010779 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10780 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010781 }
10782 m_errorMonitor->VerifyFound();
10783
10784 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10785}
10786
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010787// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10788TEST_F(VkLayerTest, InvalidImageLayout) {
10789 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010790 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10791 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010792 // 3 in ValidateCmdBufImageLayouts
10793 // * -1 Attempt to submit cmd buf w/ deleted image
10794 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10795 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010796
10797 ASSERT_NO_FATAL_FAILURE(InitState());
10798 // Create src & dst images to use for copy operations
10799 VkImage src_image;
10800 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010801 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010802
10803 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10804 const int32_t tex_width = 32;
10805 const int32_t tex_height = 32;
10806
10807 VkImageCreateInfo image_create_info = {};
10808 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10809 image_create_info.pNext = NULL;
10810 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10811 image_create_info.format = tex_format;
10812 image_create_info.extent.width = tex_width;
10813 image_create_info.extent.height = tex_height;
10814 image_create_info.extent.depth = 1;
10815 image_create_info.mipLevels = 1;
10816 image_create_info.arrayLayers = 4;
10817 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10818 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10819 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010820 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010821 image_create_info.flags = 0;
10822
10823 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10824 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010825 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010826 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10827 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010828 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10829 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10830 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10831 ASSERT_VK_SUCCESS(err);
10832
10833 // Allocate memory
10834 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010835 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010836 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010837 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10838 mem_alloc.pNext = NULL;
10839 mem_alloc.allocationSize = 0;
10840 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010841
10842 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010843 mem_alloc.allocationSize = img_mem_reqs.size;
10844 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010845 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010846 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010847 ASSERT_VK_SUCCESS(err);
10848
10849 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010850 mem_alloc.allocationSize = img_mem_reqs.size;
10851 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010852 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010853 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010854 ASSERT_VK_SUCCESS(err);
10855
10856 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010857 mem_alloc.allocationSize = img_mem_reqs.size;
10858 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010859 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010860 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010861 ASSERT_VK_SUCCESS(err);
10862
10863 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10864 ASSERT_VK_SUCCESS(err);
10865 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10866 ASSERT_VK_SUCCESS(err);
10867 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10868 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010869
Tony Barbour552f6c02016-12-21 14:34:07 -070010870 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010871 VkImageCopy copy_region;
10872 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10873 copy_region.srcSubresource.mipLevel = 0;
10874 copy_region.srcSubresource.baseArrayLayer = 0;
10875 copy_region.srcSubresource.layerCount = 1;
10876 copy_region.srcOffset.x = 0;
10877 copy_region.srcOffset.y = 0;
10878 copy_region.srcOffset.z = 0;
10879 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10880 copy_region.dstSubresource.mipLevel = 0;
10881 copy_region.dstSubresource.baseArrayLayer = 0;
10882 copy_region.dstSubresource.layerCount = 1;
10883 copy_region.dstOffset.x = 0;
10884 copy_region.dstOffset.y = 0;
10885 copy_region.dstOffset.z = 0;
10886 copy_region.extent.width = 1;
10887 copy_region.extent.height = 1;
10888 copy_region.extent.depth = 1;
10889
10890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10891 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10892 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 -060010893 m_errorMonitor->VerifyFound();
10894 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010895 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10896 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10897 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010898 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 -060010899 m_errorMonitor->VerifyFound();
10900 // Final src error is due to bad layout type
10901 m_errorMonitor->SetDesiredFailureMsg(
10902 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10903 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010904 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 -060010905 m_errorMonitor->VerifyFound();
10906 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10908 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010909 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 -060010910 m_errorMonitor->VerifyFound();
10911 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10913 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10914 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010915 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 -060010916 m_errorMonitor->VerifyFound();
10917 m_errorMonitor->SetDesiredFailureMsg(
10918 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10919 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010920 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 -060010921 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010922
Cort3b021012016-12-07 12:00:57 -080010923 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10924 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10925 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10926 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10927 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10928 transfer_dst_image_barrier[0].srcAccessMask = 0;
10929 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10930 transfer_dst_image_barrier[0].image = dst_image;
10931 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10932 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10933 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10934 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10935 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10936 transfer_dst_image_barrier[0].image = depth_image;
10937 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10938 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10939 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10940
10941 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010942 VkClearColorValue color_clear_value = {};
10943 VkImageSubresourceRange clear_range;
10944 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10945 clear_range.baseMipLevel = 0;
10946 clear_range.baseArrayLayer = 0;
10947 clear_range.layerCount = 1;
10948 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010949
Cort3b021012016-12-07 12:00:57 -080010950 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10951 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010954 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010955 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010956 // Fail due to provided layout not matching actual current layout for color clear.
10957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010958 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010959 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010960
Cort530cf382016-12-08 09:59:47 -080010961 VkClearDepthStencilValue depth_clear_value = {};
10962 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010963
10964 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10965 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010968 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010969 m_errorMonitor->VerifyFound();
10970 // Fail due to provided layout not matching actual current layout for depth clear.
10971 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010972 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010973 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010974
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010975 // Now cause error due to bad image layout transition in PipelineBarrier
10976 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010977 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010978 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010979 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010980 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010981 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10982 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010983 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Alex Smithc4659e42017-01-10 09:51:22 +000010984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You cannot transition the layout of aspect 1 from "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010985 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10986 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10987 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10988 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010989 m_errorMonitor->VerifyFound();
10990
10991 // Finally some layout errors at RenderPass create time
10992 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10993 VkAttachmentReference attach = {};
10994 // perf warning for GENERAL layout w/ non-DS input attachment
10995 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10996 VkSubpassDescription subpass = {};
10997 subpass.inputAttachmentCount = 1;
10998 subpass.pInputAttachments = &attach;
10999 VkRenderPassCreateInfo rpci = {};
11000 rpci.subpassCount = 1;
11001 rpci.pSubpasses = &subpass;
11002 rpci.attachmentCount = 1;
11003 VkAttachmentDescription attach_desc = {};
11004 attach_desc.format = VK_FORMAT_UNDEFINED;
11005 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011006 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011007 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11009 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011010 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11011 m_errorMonitor->VerifyFound();
11012 // error w/ non-general layout
11013 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11014
11015 m_errorMonitor->SetDesiredFailureMsg(
11016 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11017 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11018 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11019 m_errorMonitor->VerifyFound();
11020 subpass.inputAttachmentCount = 0;
11021 subpass.colorAttachmentCount = 1;
11022 subpass.pColorAttachments = &attach;
11023 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11024 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11026 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011027 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11028 m_errorMonitor->VerifyFound();
11029 // error w/ non-color opt or GENERAL layout for color attachment
11030 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11031 m_errorMonitor->SetDesiredFailureMsg(
11032 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11033 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11034 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11035 m_errorMonitor->VerifyFound();
11036 subpass.colorAttachmentCount = 0;
11037 subpass.pDepthStencilAttachment = &attach;
11038 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11039 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11041 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011042 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11043 m_errorMonitor->VerifyFound();
11044 // error w/ non-ds opt or GENERAL layout for color attachment
11045 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11047 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11048 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011049 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11050 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011051 // For this error we need a valid renderpass so create default one
11052 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11053 attach.attachment = 0;
11054 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11055 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11056 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11057 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11058 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11059 // Can't do a CLEAR load on READ_ONLY initialLayout
11060 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11061 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11062 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
11064 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11065 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011066 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11067 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011068
Cort3b021012016-12-07 12:00:57 -080011069 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11070 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11071 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011072 vkDestroyImage(m_device->device(), src_image, NULL);
11073 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011074 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011075}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011076
Tobin Ehlise0936662016-10-11 08:10:51 -060011077TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11078 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11079 VkResult err;
11080
11081 ASSERT_NO_FATAL_FAILURE(InitState());
11082
11083 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11084 VkImageTiling tiling;
11085 VkFormatProperties format_properties;
11086 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11087 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11088 tiling = VK_IMAGE_TILING_LINEAR;
11089 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11090 tiling = VK_IMAGE_TILING_OPTIMAL;
11091 } else {
11092 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11093 "skipped.\n");
11094 return;
11095 }
11096
11097 VkDescriptorPoolSize ds_type = {};
11098 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11099 ds_type.descriptorCount = 1;
11100
11101 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11102 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11103 ds_pool_ci.maxSets = 1;
11104 ds_pool_ci.poolSizeCount = 1;
11105 ds_pool_ci.pPoolSizes = &ds_type;
11106 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11107
11108 VkDescriptorPool ds_pool;
11109 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11110 ASSERT_VK_SUCCESS(err);
11111
11112 VkDescriptorSetLayoutBinding dsl_binding = {};
11113 dsl_binding.binding = 0;
11114 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11115 dsl_binding.descriptorCount = 1;
11116 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11117 dsl_binding.pImmutableSamplers = NULL;
11118
11119 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11120 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11121 ds_layout_ci.pNext = NULL;
11122 ds_layout_ci.bindingCount = 1;
11123 ds_layout_ci.pBindings = &dsl_binding;
11124
11125 VkDescriptorSetLayout ds_layout;
11126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11127 ASSERT_VK_SUCCESS(err);
11128
11129 VkDescriptorSetAllocateInfo alloc_info = {};
11130 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11131 alloc_info.descriptorSetCount = 1;
11132 alloc_info.descriptorPool = ds_pool;
11133 alloc_info.pSetLayouts = &ds_layout;
11134 VkDescriptorSet descriptor_set;
11135 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11136 ASSERT_VK_SUCCESS(err);
11137
11138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11140 pipeline_layout_ci.pNext = NULL;
11141 pipeline_layout_ci.setLayoutCount = 1;
11142 pipeline_layout_ci.pSetLayouts = &ds_layout;
11143 VkPipelineLayout pipeline_layout;
11144 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11145 ASSERT_VK_SUCCESS(err);
11146
11147 VkImageObj image(m_device);
11148 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11149 ASSERT_TRUE(image.initialized());
11150 VkImageView view = image.targetView(tex_format);
11151
11152 VkDescriptorImageInfo image_info = {};
11153 image_info.imageView = view;
11154 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11155
11156 VkWriteDescriptorSet descriptor_write = {};
11157 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11158 descriptor_write.dstSet = descriptor_set;
11159 descriptor_write.dstBinding = 0;
11160 descriptor_write.descriptorCount = 1;
11161 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11162 descriptor_write.pImageInfo = &image_info;
11163
11164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11165 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11166 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11167 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11168 m_errorMonitor->VerifyFound();
11169
11170 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11171 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11172 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11173 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11174}
11175
Mark Mueller93b938f2016-08-18 10:27:40 -060011176TEST_F(VkLayerTest, SimultaneousUse) {
11177 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11178 "in primary and secondary command buffers.");
11179
11180 ASSERT_NO_FATAL_FAILURE(InitState());
11181 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11182
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011183 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011184 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11185 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011186
11187 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011188 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011189 command_buffer_allocate_info.commandPool = m_commandPool;
11190 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11191 command_buffer_allocate_info.commandBufferCount = 1;
11192
11193 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011194 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011195 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11196 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011197 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011198 command_buffer_inheritance_info.renderPass = m_renderPass;
11199 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011200
Mark Mueller93b938f2016-08-18 10:27:40 -060011201 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011202 command_buffer_begin_info.flags =
11203 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011204 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11205
11206 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11207 vkEndCommandBuffer(secondary_command_buffer);
11208
Mark Mueller93b938f2016-08-18 10:27:40 -060011209 VkSubmitInfo submit_info = {};
11210 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11211 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011212 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011213
Mark Mueller4042b652016-09-05 22:52:21 -060011214 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011215 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11217 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011218 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011219 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011220 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11221 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011222
Dave Houltonfbf52152017-01-06 12:55:29 -070011223 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011224 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011225 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011226
Mark Mueller4042b652016-09-05 22:52:21 -060011227 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011228 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011229 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11232 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011233 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011234 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11235 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011236
11237 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011238}
11239
Tobin Ehlisb093da82017-01-19 12:05:27 -070011240TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
11241 TEST_DESCRIPTION("Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11242 "disabled on the device.");
11243
11244 ASSERT_NO_FATAL_FAILURE(InitState());
11245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11246
11247 std::vector<const char *> device_extension_names;
11248 auto features = m_device->phy().features();
11249 // Make sure gs & ts are disabled
11250 features.geometryShader = false;
11251 features.tessellationShader = false;
11252 // The sacrificial device object
11253 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11254
11255 VkCommandPoolCreateInfo pool_create_info{};
11256 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11257 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11258
11259 VkCommandPool command_pool;
11260 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11261
11262 VkCommandBufferAllocateInfo cmd = {};
11263 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11264 cmd.pNext = NULL;
11265 cmd.commandPool = command_pool;
11266 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11267 cmd.commandBufferCount = 1;
11268
11269 VkCommandBuffer cmd_buffer;
11270 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11271 ASSERT_VK_SUCCESS(err);
11272
11273 VkEvent event;
11274 VkEventCreateInfo evci = {};
11275 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11276 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11277 ASSERT_VK_SUCCESS(result);
11278
11279 VkCommandBufferBeginInfo cbbi = {};
11280 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11281 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11283 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11284 m_errorMonitor->VerifyFound();
11285
11286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11287 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11288 m_errorMonitor->VerifyFound();
11289
11290 vkDestroyEvent(test_device.handle(), event, NULL);
11291 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11292}
11293
Mark Mueller917f6bc2016-08-30 10:57:19 -060011294TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11295 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11296 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011297 "Delete objects that are inuse. Call VkQueueSubmit "
11298 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011299
11300 ASSERT_NO_FATAL_FAILURE(InitState());
11301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11302
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011303 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011304 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011305
Tony Barbour552f6c02016-12-21 14:34:07 -070011306 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011307
11308 VkEvent event;
11309 VkEventCreateInfo event_create_info = {};
11310 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11311 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011312 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011313
Tony Barbour552f6c02016-12-21 14:34:07 -070011314 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011315 vkDestroyEvent(m_device->device(), event, nullptr);
11316
11317 VkSubmitInfo submit_info = {};
11318 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11319 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011320 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011322 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11323 m_errorMonitor->VerifyFound();
11324
Dave Houltonfbf52152017-01-06 12:55:29 -070011325 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011326 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11327
11328 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11329
Mark Mueller917f6bc2016-08-30 10:57:19 -060011330 VkSemaphoreCreateInfo semaphore_create_info = {};
11331 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11332 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011333 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011334 VkFenceCreateInfo fence_create_info = {};
11335 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11336 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011337 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011338
11339 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011340 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011341 descriptor_pool_type_count.descriptorCount = 1;
11342
11343 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11344 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11345 descriptor_pool_create_info.maxSets = 1;
11346 descriptor_pool_create_info.poolSizeCount = 1;
11347 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011348 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011349
11350 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011351 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011352
11353 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011354 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011355 descriptorset_layout_binding.descriptorCount = 1;
11356 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11357
11358 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011359 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011360 descriptorset_layout_create_info.bindingCount = 1;
11361 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11362
11363 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011364 ASSERT_VK_SUCCESS(
11365 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011366
11367 VkDescriptorSet descriptorset;
11368 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011369 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011370 descriptorset_allocate_info.descriptorSetCount = 1;
11371 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11372 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011373 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011374
Mark Mueller4042b652016-09-05 22:52:21 -060011375 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11376
11377 VkDescriptorBufferInfo buffer_info = {};
11378 buffer_info.buffer = buffer_test.GetBuffer();
11379 buffer_info.offset = 0;
11380 buffer_info.range = 1024;
11381
11382 VkWriteDescriptorSet write_descriptor_set = {};
11383 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11384 write_descriptor_set.dstSet = descriptorset;
11385 write_descriptor_set.descriptorCount = 1;
11386 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11387 write_descriptor_set.pBufferInfo = &buffer_info;
11388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011389 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011391 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11392 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011393
11394 VkPipelineObj pipe(m_device);
11395 pipe.AddColorAttachment();
11396 pipe.AddShader(&vs);
11397 pipe.AddShader(&fs);
11398
11399 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011400 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011401 pipeline_layout_create_info.setLayoutCount = 1;
11402 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11403
11404 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011405 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011406
11407 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11408
Tony Barbour552f6c02016-12-21 14:34:07 -070011409 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011410 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011411
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011412 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11413 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11414 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011415
Tony Barbour552f6c02016-12-21 14:34:07 -070011416 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011417
Mark Mueller917f6bc2016-08-30 10:57:19 -060011418 submit_info.signalSemaphoreCount = 1;
11419 submit_info.pSignalSemaphores = &semaphore;
11420 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Dave Houltonfbf52152017-01-06 12:55:29 -070011421 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011422
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011424 vkDestroyEvent(m_device->device(), event, nullptr);
11425 m_errorMonitor->VerifyFound();
11426
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011428 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11429 m_errorMonitor->VerifyFound();
11430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011432 vkDestroyFence(m_device->device(), fence, nullptr);
11433 m_errorMonitor->VerifyFound();
11434
Tobin Ehlis122207b2016-09-01 08:50:06 -070011435 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011436 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11437 vkDestroyFence(m_device->device(), fence, nullptr);
11438 vkDestroyEvent(m_device->device(), event, nullptr);
11439 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011440 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011441 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11442}
11443
Tobin Ehlis2adda372016-09-01 08:51:06 -070011444TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11445 TEST_DESCRIPTION("Delete in-use query pool.");
11446
11447 ASSERT_NO_FATAL_FAILURE(InitState());
11448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11449
11450 VkQueryPool query_pool;
11451 VkQueryPoolCreateInfo query_pool_ci{};
11452 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11453 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11454 query_pool_ci.queryCount = 1;
11455 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011456 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011457 // Reset query pool to create binding with cmd buffer
11458 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11459
Tony Barbour552f6c02016-12-21 14:34:07 -070011460 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011461
11462 VkSubmitInfo submit_info = {};
11463 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11464 submit_info.commandBufferCount = 1;
11465 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11466 // Submit cmd buffer and then destroy query pool while in-flight
11467 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11468
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011470 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11471 m_errorMonitor->VerifyFound();
11472
11473 vkQueueWaitIdle(m_device->m_queue);
11474 // Now that cmd buffer done we can safely destroy query_pool
11475 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11476}
11477
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011478TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11479 TEST_DESCRIPTION("Delete in-use pipeline.");
11480
11481 ASSERT_NO_FATAL_FAILURE(InitState());
11482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11483
11484 // Empty pipeline layout used for binding PSO
11485 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11486 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11487 pipeline_layout_ci.setLayoutCount = 0;
11488 pipeline_layout_ci.pSetLayouts = NULL;
11489
11490 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011491 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011492 ASSERT_VK_SUCCESS(err);
11493
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011495 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011496 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11497 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011498 // Store pipeline handle so we can actually delete it before test finishes
11499 VkPipeline delete_this_pipeline;
11500 { // Scope pipeline so it will be auto-deleted
11501 VkPipelineObj pipe(m_device);
11502 pipe.AddShader(&vs);
11503 pipe.AddShader(&fs);
11504 pipe.AddColorAttachment();
11505 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11506 delete_this_pipeline = pipe.handle();
11507
Tony Barbour552f6c02016-12-21 14:34:07 -070011508 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011509 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011510 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011511
Tony Barbour552f6c02016-12-21 14:34:07 -070011512 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011513
11514 VkSubmitInfo submit_info = {};
11515 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11516 submit_info.commandBufferCount = 1;
11517 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11518 // Submit cmd buffer and then pipeline destroyed while in-flight
11519 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11520 } // Pipeline deletion triggered here
11521 m_errorMonitor->VerifyFound();
11522 // Make sure queue finished and then actually delete pipeline
11523 vkQueueWaitIdle(m_device->m_queue);
11524 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11525 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11526}
11527
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011528TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11529 TEST_DESCRIPTION("Delete in-use imageView.");
11530
11531 ASSERT_NO_FATAL_FAILURE(InitState());
11532 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11533
11534 VkDescriptorPoolSize ds_type_count;
11535 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11536 ds_type_count.descriptorCount = 1;
11537
11538 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11539 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11540 ds_pool_ci.maxSets = 1;
11541 ds_pool_ci.poolSizeCount = 1;
11542 ds_pool_ci.pPoolSizes = &ds_type_count;
11543
11544 VkDescriptorPool ds_pool;
11545 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11546 ASSERT_VK_SUCCESS(err);
11547
11548 VkSamplerCreateInfo sampler_ci = {};
11549 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11550 sampler_ci.pNext = NULL;
11551 sampler_ci.magFilter = VK_FILTER_NEAREST;
11552 sampler_ci.minFilter = VK_FILTER_NEAREST;
11553 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11554 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11555 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11556 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11557 sampler_ci.mipLodBias = 1.0;
11558 sampler_ci.anisotropyEnable = VK_FALSE;
11559 sampler_ci.maxAnisotropy = 1;
11560 sampler_ci.compareEnable = VK_FALSE;
11561 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11562 sampler_ci.minLod = 1.0;
11563 sampler_ci.maxLod = 1.0;
11564 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11565 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11566 VkSampler sampler;
11567
11568 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11569 ASSERT_VK_SUCCESS(err);
11570
11571 VkDescriptorSetLayoutBinding layout_binding;
11572 layout_binding.binding = 0;
11573 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11574 layout_binding.descriptorCount = 1;
11575 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11576 layout_binding.pImmutableSamplers = NULL;
11577
11578 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11579 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11580 ds_layout_ci.bindingCount = 1;
11581 ds_layout_ci.pBindings = &layout_binding;
11582 VkDescriptorSetLayout ds_layout;
11583 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11584 ASSERT_VK_SUCCESS(err);
11585
11586 VkDescriptorSetAllocateInfo alloc_info = {};
11587 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11588 alloc_info.descriptorSetCount = 1;
11589 alloc_info.descriptorPool = ds_pool;
11590 alloc_info.pSetLayouts = &ds_layout;
11591 VkDescriptorSet descriptor_set;
11592 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11593 ASSERT_VK_SUCCESS(err);
11594
11595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11596 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11597 pipeline_layout_ci.pNext = NULL;
11598 pipeline_layout_ci.setLayoutCount = 1;
11599 pipeline_layout_ci.pSetLayouts = &ds_layout;
11600
11601 VkPipelineLayout pipeline_layout;
11602 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11603 ASSERT_VK_SUCCESS(err);
11604
11605 VkImageObj image(m_device);
11606 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11607 ASSERT_TRUE(image.initialized());
11608
11609 VkImageView view;
11610 VkImageViewCreateInfo ivci = {};
11611 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11612 ivci.image = image.handle();
11613 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11614 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11615 ivci.subresourceRange.layerCount = 1;
11616 ivci.subresourceRange.baseMipLevel = 0;
11617 ivci.subresourceRange.levelCount = 1;
11618 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11619
11620 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11621 ASSERT_VK_SUCCESS(err);
11622
11623 VkDescriptorImageInfo image_info{};
11624 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11625 image_info.imageView = view;
11626 image_info.sampler = sampler;
11627
11628 VkWriteDescriptorSet descriptor_write = {};
11629 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11630 descriptor_write.dstSet = descriptor_set;
11631 descriptor_write.dstBinding = 0;
11632 descriptor_write.descriptorCount = 1;
11633 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11634 descriptor_write.pImageInfo = &image_info;
11635
11636 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11637
11638 // Create PSO to use the sampler
11639 char const *vsSource = "#version 450\n"
11640 "\n"
11641 "out gl_PerVertex { \n"
11642 " vec4 gl_Position;\n"
11643 "};\n"
11644 "void main(){\n"
11645 " gl_Position = vec4(1);\n"
11646 "}\n";
11647 char const *fsSource = "#version 450\n"
11648 "\n"
11649 "layout(set=0, binding=0) uniform sampler2D s;\n"
11650 "layout(location=0) out vec4 x;\n"
11651 "void main(){\n"
11652 " x = texture(s, vec2(1));\n"
11653 "}\n";
11654 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11655 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11656 VkPipelineObj pipe(m_device);
11657 pipe.AddShader(&vs);
11658 pipe.AddShader(&fs);
11659 pipe.AddColorAttachment();
11660 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11661
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011663
Tony Barbour552f6c02016-12-21 14:34:07 -070011664 m_commandBuffer->BeginCommandBuffer();
11665 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011666 // Bind pipeline to cmd buffer
11667 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11669 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070011670
11671 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11672 VkRect2D scissor = {{0, 0}, {16, 16}};
11673 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11674 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11675
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011676 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011677 m_commandBuffer->EndRenderPass();
11678 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011679 // Submit cmd buffer then destroy sampler
11680 VkSubmitInfo submit_info = {};
11681 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11682 submit_info.commandBufferCount = 1;
11683 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11684 // Submit cmd buffer and then destroy imageView while in-flight
11685 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11686
11687 vkDestroyImageView(m_device->device(), view, nullptr);
11688 m_errorMonitor->VerifyFound();
11689 vkQueueWaitIdle(m_device->m_queue);
11690 // Now we can actually destroy imageView
11691 vkDestroyImageView(m_device->device(), view, NULL);
11692 vkDestroySampler(m_device->device(), sampler, nullptr);
11693 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11694 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11695 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11696}
11697
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011698TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11699 TEST_DESCRIPTION("Delete in-use bufferView.");
11700
11701 ASSERT_NO_FATAL_FAILURE(InitState());
11702 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11703
11704 VkDescriptorPoolSize ds_type_count;
11705 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11706 ds_type_count.descriptorCount = 1;
11707
11708 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11709 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11710 ds_pool_ci.maxSets = 1;
11711 ds_pool_ci.poolSizeCount = 1;
11712 ds_pool_ci.pPoolSizes = &ds_type_count;
11713
11714 VkDescriptorPool ds_pool;
11715 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11716 ASSERT_VK_SUCCESS(err);
11717
11718 VkDescriptorSetLayoutBinding layout_binding;
11719 layout_binding.binding = 0;
11720 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11721 layout_binding.descriptorCount = 1;
11722 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11723 layout_binding.pImmutableSamplers = NULL;
11724
11725 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11726 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11727 ds_layout_ci.bindingCount = 1;
11728 ds_layout_ci.pBindings = &layout_binding;
11729 VkDescriptorSetLayout ds_layout;
11730 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11731 ASSERT_VK_SUCCESS(err);
11732
11733 VkDescriptorSetAllocateInfo alloc_info = {};
11734 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11735 alloc_info.descriptorSetCount = 1;
11736 alloc_info.descriptorPool = ds_pool;
11737 alloc_info.pSetLayouts = &ds_layout;
11738 VkDescriptorSet descriptor_set;
11739 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11740 ASSERT_VK_SUCCESS(err);
11741
11742 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11743 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11744 pipeline_layout_ci.pNext = NULL;
11745 pipeline_layout_ci.setLayoutCount = 1;
11746 pipeline_layout_ci.pSetLayouts = &ds_layout;
11747
11748 VkPipelineLayout pipeline_layout;
11749 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11750 ASSERT_VK_SUCCESS(err);
11751
11752 VkBuffer buffer;
11753 uint32_t queue_family_index = 0;
11754 VkBufferCreateInfo buffer_create_info = {};
11755 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11756 buffer_create_info.size = 1024;
11757 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11758 buffer_create_info.queueFamilyIndexCount = 1;
11759 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11760
11761 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11762 ASSERT_VK_SUCCESS(err);
11763
11764 VkMemoryRequirements memory_reqs;
11765 VkDeviceMemory buffer_memory;
11766
11767 VkMemoryAllocateInfo memory_info = {};
11768 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11769 memory_info.allocationSize = 0;
11770 memory_info.memoryTypeIndex = 0;
11771
11772 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11773 memory_info.allocationSize = memory_reqs.size;
11774 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11775 ASSERT_TRUE(pass);
11776
11777 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11778 ASSERT_VK_SUCCESS(err);
11779 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11780 ASSERT_VK_SUCCESS(err);
11781
11782 VkBufferView view;
11783 VkBufferViewCreateInfo bvci = {};
11784 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11785 bvci.buffer = buffer;
11786 bvci.format = VK_FORMAT_R8_UNORM;
11787 bvci.range = VK_WHOLE_SIZE;
11788
11789 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11790 ASSERT_VK_SUCCESS(err);
11791
11792 VkWriteDescriptorSet descriptor_write = {};
11793 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11794 descriptor_write.dstSet = descriptor_set;
11795 descriptor_write.dstBinding = 0;
11796 descriptor_write.descriptorCount = 1;
11797 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11798 descriptor_write.pTexelBufferView = &view;
11799
11800 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11801
11802 char const *vsSource = "#version 450\n"
11803 "\n"
11804 "out gl_PerVertex { \n"
11805 " vec4 gl_Position;\n"
11806 "};\n"
11807 "void main(){\n"
11808 " gl_Position = vec4(1);\n"
11809 "}\n";
11810 char const *fsSource = "#version 450\n"
11811 "\n"
11812 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11813 "layout(location=0) out vec4 x;\n"
11814 "void main(){\n"
11815 " x = imageLoad(s, 0);\n"
11816 "}\n";
11817 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11818 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11819 VkPipelineObj pipe(m_device);
11820 pipe.AddShader(&vs);
11821 pipe.AddShader(&fs);
11822 pipe.AddColorAttachment();
11823 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11824
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011826
Tony Barbour552f6c02016-12-21 14:34:07 -070011827 m_commandBuffer->BeginCommandBuffer();
11828 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011829 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11830 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11831 VkRect2D scissor = {{0, 0}, {16, 16}};
11832 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11833 // Bind pipeline to cmd buffer
11834 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11835 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11836 &descriptor_set, 0, nullptr);
11837 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011838 m_commandBuffer->EndRenderPass();
11839 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011840
11841 VkSubmitInfo submit_info = {};
11842 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11843 submit_info.commandBufferCount = 1;
11844 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11845 // Submit cmd buffer and then destroy bufferView while in-flight
11846 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11847
11848 vkDestroyBufferView(m_device->device(), view, nullptr);
11849 m_errorMonitor->VerifyFound();
11850 vkQueueWaitIdle(m_device->m_queue);
11851 // Now we can actually destroy bufferView
11852 vkDestroyBufferView(m_device->device(), view, NULL);
11853 vkDestroyBuffer(m_device->device(), buffer, NULL);
11854 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11855 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11856 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11857 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11858}
11859
Tobin Ehlis209532e2016-09-07 13:52:18 -060011860TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11861 TEST_DESCRIPTION("Delete in-use sampler.");
11862
11863 ASSERT_NO_FATAL_FAILURE(InitState());
11864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11865
11866 VkDescriptorPoolSize ds_type_count;
11867 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11868 ds_type_count.descriptorCount = 1;
11869
11870 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11871 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11872 ds_pool_ci.maxSets = 1;
11873 ds_pool_ci.poolSizeCount = 1;
11874 ds_pool_ci.pPoolSizes = &ds_type_count;
11875
11876 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011877 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011878 ASSERT_VK_SUCCESS(err);
11879
11880 VkSamplerCreateInfo sampler_ci = {};
11881 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11882 sampler_ci.pNext = NULL;
11883 sampler_ci.magFilter = VK_FILTER_NEAREST;
11884 sampler_ci.minFilter = VK_FILTER_NEAREST;
11885 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11886 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11887 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11888 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11889 sampler_ci.mipLodBias = 1.0;
11890 sampler_ci.anisotropyEnable = VK_FALSE;
11891 sampler_ci.maxAnisotropy = 1;
11892 sampler_ci.compareEnable = VK_FALSE;
11893 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11894 sampler_ci.minLod = 1.0;
11895 sampler_ci.maxLod = 1.0;
11896 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11897 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11898 VkSampler sampler;
11899
11900 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11901 ASSERT_VK_SUCCESS(err);
11902
11903 VkDescriptorSetLayoutBinding layout_binding;
11904 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011905 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011906 layout_binding.descriptorCount = 1;
11907 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11908 layout_binding.pImmutableSamplers = NULL;
11909
11910 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11911 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11912 ds_layout_ci.bindingCount = 1;
11913 ds_layout_ci.pBindings = &layout_binding;
11914 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011915 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011916 ASSERT_VK_SUCCESS(err);
11917
11918 VkDescriptorSetAllocateInfo alloc_info = {};
11919 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11920 alloc_info.descriptorSetCount = 1;
11921 alloc_info.descriptorPool = ds_pool;
11922 alloc_info.pSetLayouts = &ds_layout;
11923 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011924 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011925 ASSERT_VK_SUCCESS(err);
11926
11927 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11928 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11929 pipeline_layout_ci.pNext = NULL;
11930 pipeline_layout_ci.setLayoutCount = 1;
11931 pipeline_layout_ci.pSetLayouts = &ds_layout;
11932
11933 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011934 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011935 ASSERT_VK_SUCCESS(err);
11936
11937 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011938 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 -060011939 ASSERT_TRUE(image.initialized());
11940
11941 VkImageView view;
11942 VkImageViewCreateInfo ivci = {};
11943 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11944 ivci.image = image.handle();
11945 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11946 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11947 ivci.subresourceRange.layerCount = 1;
11948 ivci.subresourceRange.baseMipLevel = 0;
11949 ivci.subresourceRange.levelCount = 1;
11950 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11951
11952 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11953 ASSERT_VK_SUCCESS(err);
11954
11955 VkDescriptorImageInfo image_info{};
11956 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11957 image_info.imageView = view;
11958 image_info.sampler = sampler;
11959
11960 VkWriteDescriptorSet descriptor_write = {};
11961 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11962 descriptor_write.dstSet = descriptor_set;
11963 descriptor_write.dstBinding = 0;
11964 descriptor_write.descriptorCount = 1;
11965 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11966 descriptor_write.pImageInfo = &image_info;
11967
11968 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11969
11970 // Create PSO to use the sampler
11971 char const *vsSource = "#version 450\n"
11972 "\n"
11973 "out gl_PerVertex { \n"
11974 " vec4 gl_Position;\n"
11975 "};\n"
11976 "void main(){\n"
11977 " gl_Position = vec4(1);\n"
11978 "}\n";
11979 char const *fsSource = "#version 450\n"
11980 "\n"
11981 "layout(set=0, binding=0) uniform sampler2D s;\n"
11982 "layout(location=0) out vec4 x;\n"
11983 "void main(){\n"
11984 " x = texture(s, vec2(1));\n"
11985 "}\n";
11986 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11987 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11988 VkPipelineObj pipe(m_device);
11989 pipe.AddShader(&vs);
11990 pipe.AddShader(&fs);
11991 pipe.AddColorAttachment();
11992 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11993
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011995
Tony Barbour552f6c02016-12-21 14:34:07 -070011996 m_commandBuffer->BeginCommandBuffer();
11997 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011998 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011999 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12000 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12001 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012002
12003 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12004 VkRect2D scissor = {{0, 0}, {16, 16}};
12005 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12006 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12007
Tobin Ehlis209532e2016-09-07 13:52:18 -060012008 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012009 m_commandBuffer->EndRenderPass();
12010 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012011 // Submit cmd buffer then destroy sampler
12012 VkSubmitInfo submit_info = {};
12013 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12014 submit_info.commandBufferCount = 1;
12015 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12016 // Submit cmd buffer and then destroy sampler while in-flight
12017 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12018
Rene Lindsay4da11732017-01-13 14:42:10 -070012019 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012020 m_errorMonitor->VerifyFound();
12021 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012022
Tobin Ehlis209532e2016-09-07 13:52:18 -060012023 // Now we can actually destroy sampler
Rene Lindsay4da11732017-01-13 14:42:10 -070012024 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012025 vkDestroyImageView(m_device->device(), view, NULL);
12026 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12027 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12028 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12029}
12030
Mark Mueller1cd9f412016-08-25 13:23:52 -060012031TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060012032 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060012033 "signaled but not waited on by the queue. Wait on a "
12034 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012035
12036 ASSERT_NO_FATAL_FAILURE(InitState());
12037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12038
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012039 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
12040 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
12041 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012042
Tony Barbour552f6c02016-12-21 14:34:07 -070012043 m_commandBuffer->BeginCommandBuffer();
12044 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012045
12046 VkSemaphoreCreateInfo semaphore_create_info = {};
12047 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12048 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012049 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012050 VkSubmitInfo submit_info = {};
12051 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12052 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012053 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012054 submit_info.signalSemaphoreCount = 1;
12055 submit_info.pSignalSemaphores = &semaphore;
12056 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012057 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012058 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012059 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012060 m_commandBuffer->BeginCommandBuffer();
12061 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012063 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12064 m_errorMonitor->VerifyFound();
12065
Mark Mueller1cd9f412016-08-25 13:23:52 -060012066 VkFenceCreateInfo fence_create_info = {};
12067 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12068 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012069 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012072 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12073 m_errorMonitor->VerifyFound();
12074
Mark Mueller4042b652016-09-05 22:52:21 -060012075 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012076 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012077 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12078}
12079
Tobin Ehlis4af23302016-07-19 10:50:30 -060012080TEST_F(VkLayerTest, FramebufferIncompatible) {
12081 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
12082 "that does not match the framebuffer for the active "
12083 "renderpass.");
12084 ASSERT_NO_FATAL_FAILURE(InitState());
12085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12086
12087 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012088 VkAttachmentDescription attachment = {0,
12089 VK_FORMAT_B8G8R8A8_UNORM,
12090 VK_SAMPLE_COUNT_1_BIT,
12091 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12092 VK_ATTACHMENT_STORE_OP_STORE,
12093 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12094 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12095 VK_IMAGE_LAYOUT_UNDEFINED,
12096 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012097
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012098 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012099
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012100 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012101
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012102 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012103
12104 VkRenderPass rp;
12105 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12106 ASSERT_VK_SUCCESS(err);
12107
12108 // A compatible framebuffer.
12109 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012110 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 -060012111 ASSERT_TRUE(image.initialized());
12112
12113 VkImageViewCreateInfo ivci = {
12114 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12115 nullptr,
12116 0,
12117 image.handle(),
12118 VK_IMAGE_VIEW_TYPE_2D,
12119 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012120 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12121 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012122 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12123 };
12124 VkImageView view;
12125 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12126 ASSERT_VK_SUCCESS(err);
12127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012128 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012129 VkFramebuffer fb;
12130 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12131 ASSERT_VK_SUCCESS(err);
12132
12133 VkCommandBufferAllocateInfo cbai = {};
12134 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12135 cbai.commandPool = m_commandPool;
12136 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12137 cbai.commandBufferCount = 1;
12138
12139 VkCommandBuffer sec_cb;
12140 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12141 ASSERT_VK_SUCCESS(err);
12142 VkCommandBufferBeginInfo cbbi = {};
12143 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012144 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012145 cbii.renderPass = renderPass();
12146 cbii.framebuffer = fb;
12147 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12148 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012149 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 -060012150 cbbi.pInheritanceInfo = &cbii;
12151 vkBeginCommandBuffer(sec_cb, &cbbi);
12152 vkEndCommandBuffer(sec_cb);
12153
Chris Forbes3400bc52016-09-13 18:10:34 +120012154 VkCommandBufferBeginInfo cbbi2 = {
12155 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12156 0, nullptr
12157 };
12158 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12159 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012160
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012162 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012163 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12164 m_errorMonitor->VerifyFound();
12165 // Cleanup
12166 vkDestroyImageView(m_device->device(), view, NULL);
12167 vkDestroyRenderPass(m_device->device(), rp, NULL);
12168 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12169}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012170
12171TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
12172 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
12173 "invalid value. If logicOp is not available, attempt to "
12174 "use it and verify that we see the correct error.");
12175 ASSERT_NO_FATAL_FAILURE(InitState());
12176 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12177
12178 auto features = m_device->phy().features();
12179 // Set the expected error depending on whether or not logicOp available
12180 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
12182 "enabled, logicOpEnable must be "
12183 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012184 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012186 }
12187 // Create a pipeline using logicOp
12188 VkResult err;
12189
12190 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12191 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12192
12193 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012194 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012195 ASSERT_VK_SUCCESS(err);
12196
12197 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12198 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12199 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012200 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012201 vp_state_ci.pViewports = &vp;
12202 vp_state_ci.scissorCount = 1;
12203 VkRect2D scissors = {}; // Dummy scissors to point to
12204 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012205
12206 VkPipelineShaderStageCreateInfo shaderStages[2];
12207 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12208
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012209 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12210 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012211 shaderStages[0] = vs.GetStageCreateInfo();
12212 shaderStages[1] = fs.GetStageCreateInfo();
12213
12214 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12215 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12216
12217 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12218 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12219 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12220
12221 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12222 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012223 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012224
12225 VkPipelineColorBlendAttachmentState att = {};
12226 att.blendEnable = VK_FALSE;
12227 att.colorWriteMask = 0xf;
12228
12229 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12230 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12231 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12232 cb_ci.logicOpEnable = VK_TRUE;
12233 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
12234 cb_ci.attachmentCount = 1;
12235 cb_ci.pAttachments = &att;
12236
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012237 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12238 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12239 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12240
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012241 VkGraphicsPipelineCreateInfo gp_ci = {};
12242 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12243 gp_ci.stageCount = 2;
12244 gp_ci.pStages = shaderStages;
12245 gp_ci.pVertexInputState = &vi_ci;
12246 gp_ci.pInputAssemblyState = &ia_ci;
12247 gp_ci.pViewportState = &vp_state_ci;
12248 gp_ci.pRasterizationState = &rs_ci;
12249 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012250 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012251 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12252 gp_ci.layout = pipeline_layout;
12253 gp_ci.renderPass = renderPass();
12254
12255 VkPipelineCacheCreateInfo pc_ci = {};
12256 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12257
12258 VkPipeline pipeline;
12259 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012260 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012261 ASSERT_VK_SUCCESS(err);
12262
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012263 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012264 m_errorMonitor->VerifyFound();
12265 if (VK_SUCCESS == err) {
12266 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12267 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012268 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12269 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12270}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012271#endif // DRAW_STATE_TESTS
12272
Tobin Ehlis0788f522015-05-26 16:11:58 -060012273#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012274#if GTEST_IS_THREADSAFE
12275struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012276 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012277 VkEvent event;
12278 bool bailout;
12279};
12280
Karl Schultz6addd812016-02-02 17:17:23 -070012281extern "C" void *AddToCommandBuffer(void *arg) {
12282 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012283
Mike Stroyana6d14942016-07-13 15:10:05 -060012284 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012285 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012286 if (data->bailout) {
12287 break;
12288 }
12289 }
12290 return NULL;
12291}
12292
Karl Schultz6addd812016-02-02 17:17:23 -070012293TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012294 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012297
Mike Stroyanaccf7692015-05-12 16:00:45 -060012298 ASSERT_NO_FATAL_FAILURE(InitState());
12299 ASSERT_NO_FATAL_FAILURE(InitViewport());
12300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12301
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012302 // Calls AllocateCommandBuffers
12303 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012304
12305 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012306 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012307
12308 VkEventCreateInfo event_info;
12309 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012310 VkResult err;
12311
12312 memset(&event_info, 0, sizeof(event_info));
12313 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12314
Chia-I Wuf7458c52015-10-26 21:10:41 +080012315 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012316 ASSERT_VK_SUCCESS(err);
12317
Mike Stroyanaccf7692015-05-12 16:00:45 -060012318 err = vkResetEvent(device(), event);
12319 ASSERT_VK_SUCCESS(err);
12320
12321 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012322 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012323 data.event = event;
12324 data.bailout = false;
12325 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012326
12327 // First do some correct operations using multiple threads.
12328 // Add many entries to command buffer from another thread.
12329 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12330 // Make non-conflicting calls from this thread at the same time.
12331 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012332 uint32_t count;
12333 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012334 }
12335 test_platform_thread_join(thread, NULL);
12336
12337 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012338 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012339 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012340 // Add many entries to command buffer from this thread at the same time.
12341 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012342
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012343 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012344 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012345
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012346 m_errorMonitor->SetBailout(NULL);
12347
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012348 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012349
Chia-I Wuf7458c52015-10-26 21:10:41 +080012350 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012351}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012352#endif // GTEST_IS_THREADSAFE
12353#endif // THREADING_TESTS
12354
Chris Forbes9f7ff632015-05-25 11:13:08 +120012355#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012356TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012357 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12358 "with an impossible code size");
12359
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012361
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012362 ASSERT_NO_FATAL_FAILURE(InitState());
12363 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12364
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012365 VkShaderModule module;
12366 VkShaderModuleCreateInfo moduleCreateInfo;
12367 struct icd_spv_header spv;
12368
12369 spv.magic = ICD_SPV_MAGIC;
12370 spv.version = ICD_SPV_VERSION;
12371 spv.gen_magic = 0;
12372
12373 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12374 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012375 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012376 moduleCreateInfo.codeSize = 4;
12377 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012378 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012379
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012380 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012381}
12382
Karl Schultz6addd812016-02-02 17:17:23 -070012383TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012384 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12385 "with a bad magic number");
12386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012388
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012389 ASSERT_NO_FATAL_FAILURE(InitState());
12390 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12391
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012392 VkShaderModule module;
12393 VkShaderModuleCreateInfo moduleCreateInfo;
12394 struct icd_spv_header spv;
12395
12396 spv.magic = ~ICD_SPV_MAGIC;
12397 spv.version = ICD_SPV_VERSION;
12398 spv.gen_magic = 0;
12399
12400 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12401 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012402 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012403 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12404 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012405 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012406
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012407 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012408}
12409
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012410#if 0
12411// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012412TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012414 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012415
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012416 ASSERT_NO_FATAL_FAILURE(InitState());
12417 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12418
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012419 VkShaderModule module;
12420 VkShaderModuleCreateInfo moduleCreateInfo;
12421 struct icd_spv_header spv;
12422
12423 spv.magic = ICD_SPV_MAGIC;
12424 spv.version = ~ICD_SPV_VERSION;
12425 spv.gen_magic = 0;
12426
12427 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12428 moduleCreateInfo.pNext = NULL;
12429
Karl Schultz6addd812016-02-02 17:17:23 -070012430 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012431 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12432 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012433 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012434
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012435 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012436}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012437#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012438
Karl Schultz6addd812016-02-02 17:17:23 -070012439TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012440 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12441 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012443
Chris Forbes9f7ff632015-05-25 11:13:08 +120012444 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012446
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012447 char const *vsSource = "#version 450\n"
12448 "\n"
12449 "layout(location=0) out float x;\n"
12450 "out gl_PerVertex {\n"
12451 " vec4 gl_Position;\n"
12452 "};\n"
12453 "void main(){\n"
12454 " gl_Position = vec4(1);\n"
12455 " x = 0;\n"
12456 "}\n";
12457 char const *fsSource = "#version 450\n"
12458 "\n"
12459 "layout(location=0) out vec4 color;\n"
12460 "void main(){\n"
12461 " color = vec4(1);\n"
12462 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012463
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012464 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12465 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012466
12467 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012468 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012469 pipe.AddShader(&vs);
12470 pipe.AddShader(&fs);
12471
Chris Forbes9f7ff632015-05-25 11:13:08 +120012472 VkDescriptorSetObj descriptorSet(m_device);
12473 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012474 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012475
Tony Barbour5781e8f2015-08-04 16:23:11 -060012476 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012477
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012478 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012479}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012480
Mark Mueller098c9cb2016-09-08 09:01:57 -060012481TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12482 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12483
12484 ASSERT_NO_FATAL_FAILURE(InitState());
12485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12486
12487 const char *bad_specialization_message =
12488 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12489
12490 char const *vsSource =
12491 "#version 450\n"
12492 "\n"
12493 "out gl_PerVertex {\n"
12494 " vec4 gl_Position;\n"
12495 "};\n"
12496 "void main(){\n"
12497 " gl_Position = vec4(1);\n"
12498 "}\n";
12499
12500 char const *fsSource =
12501 "#version 450\n"
12502 "\n"
12503 "layout (constant_id = 0) const float r = 0.0f;\n"
12504 "layout(location = 0) out vec4 uFragColor;\n"
12505 "void main(){\n"
12506 " uFragColor = vec4(r,1,0,1);\n"
12507 "}\n";
12508
12509 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12511
12512 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12513 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12514
12515 VkPipelineLayout pipeline_layout;
12516 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12517
12518 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12519 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12520 vp_state_create_info.viewportCount = 1;
12521 VkViewport viewport = {};
12522 vp_state_create_info.pViewports = &viewport;
12523 vp_state_create_info.scissorCount = 1;
12524 VkRect2D scissors = {};
12525 vp_state_create_info.pScissors = &scissors;
12526
12527 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12528
12529 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12530 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12531 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12532 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12533
12534 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12535 vs.GetStageCreateInfo(),
12536 fs.GetStageCreateInfo()
12537 };
12538
12539 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12540 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12541
12542 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12543 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12544 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12545
12546 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12547 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12548 rasterization_state_create_info.pNext = nullptr;
12549 rasterization_state_create_info.lineWidth = 1.0f;
12550 rasterization_state_create_info.rasterizerDiscardEnable = true;
12551
12552 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12553 color_blend_attachment_state.blendEnable = VK_FALSE;
12554 color_blend_attachment_state.colorWriteMask = 0xf;
12555
12556 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12557 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12558 color_blend_state_create_info.attachmentCount = 1;
12559 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12560
12561 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12562 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12563 graphicspipe_create_info.stageCount = 2;
12564 graphicspipe_create_info.pStages = shader_stage_create_info;
12565 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12566 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12567 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12568 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12569 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12570 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12571 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12572 graphicspipe_create_info.layout = pipeline_layout;
12573 graphicspipe_create_info.renderPass = renderPass();
12574
12575 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12576 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12577
12578 VkPipelineCache pipelineCache;
12579 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12580
12581 // This structure maps constant ids to data locations.
12582 const VkSpecializationMapEntry entry =
12583 // id, offset, size
12584 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12585
12586 uint32_t data = 1;
12587
12588 // Set up the info describing spec map and data
12589 const VkSpecializationInfo specialization_info = {
12590 1,
12591 &entry,
12592 1 * sizeof(float),
12593 &data,
12594 };
12595 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12596
12597 VkPipeline pipeline;
12598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12599 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12600 m_errorMonitor->VerifyFound();
12601
12602 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12603 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12604}
12605
12606TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12607 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12608
12609 ASSERT_NO_FATAL_FAILURE(InitState());
12610 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12611
12612 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12613
12614 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12615 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12616 descriptor_pool_type_count[0].descriptorCount = 1;
12617 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12618 descriptor_pool_type_count[1].descriptorCount = 1;
12619
12620 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12621 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12622 descriptor_pool_create_info.maxSets = 1;
12623 descriptor_pool_create_info.poolSizeCount = 2;
12624 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12625 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12626
12627 VkDescriptorPool descriptorset_pool;
12628 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12629
12630 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12631 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12632 descriptorset_layout_binding.descriptorCount = 1;
12633 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12634
12635 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12636 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12637 descriptorset_layout_create_info.bindingCount = 1;
12638 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12639
12640 VkDescriptorSetLayout descriptorset_layout;
12641 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12642
12643 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12644 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12645 descriptorset_allocate_info.descriptorSetCount = 1;
12646 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12647 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12648 VkDescriptorSet descriptorset;
12649 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12650
12651 // Challenge core_validation with a non uniform buffer type.
12652 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12653
Mark Mueller098c9cb2016-09-08 09:01:57 -060012654 char const *vsSource =
12655 "#version 450\n"
12656 "\n"
12657 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12658 " mat4 mvp;\n"
12659 "} ubuf;\n"
12660 "out gl_PerVertex {\n"
12661 " vec4 gl_Position;\n"
12662 "};\n"
12663 "void main(){\n"
12664 " gl_Position = ubuf.mvp * vec4(1);\n"
12665 "}\n";
12666
12667 char const *fsSource =
12668 "#version 450\n"
12669 "\n"
12670 "layout(location = 0) out vec4 uFragColor;\n"
12671 "void main(){\n"
12672 " uFragColor = vec4(0,1,0,1);\n"
12673 "}\n";
12674
12675 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12676 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12677
12678 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12679 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12680 pipeline_layout_create_info.setLayoutCount = 1;
12681 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12682
12683 VkPipelineLayout pipeline_layout;
12684 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12685
12686 VkPipelineObj pipe(m_device);
12687 pipe.AddColorAttachment();
12688 pipe.AddShader(&vs);
12689 pipe.AddShader(&fs);
12690
12691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12692 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12693 m_errorMonitor->VerifyFound();
12694
12695 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12696 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12697 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12698}
12699
12700TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12701 TEST_DESCRIPTION(
12702 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12703
12704 ASSERT_NO_FATAL_FAILURE(InitState());
12705 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12706
12707 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12708
12709 VkDescriptorPoolSize descriptor_pool_type_count = {};
12710 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12711 descriptor_pool_type_count.descriptorCount = 1;
12712
12713 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12714 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12715 descriptor_pool_create_info.maxSets = 1;
12716 descriptor_pool_create_info.poolSizeCount = 1;
12717 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12718 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12719
12720 VkDescriptorPool descriptorset_pool;
12721 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12722
12723 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12724 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12725 descriptorset_layout_binding.descriptorCount = 1;
12726 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12727 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12728
12729 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12730 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12731 descriptorset_layout_create_info.bindingCount = 1;
12732 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12733
12734 VkDescriptorSetLayout descriptorset_layout;
12735 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12736 nullptr, &descriptorset_layout));
12737
12738 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12739 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12740 descriptorset_allocate_info.descriptorSetCount = 1;
12741 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12742 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12743 VkDescriptorSet descriptorset;
12744 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12745
12746 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12747
Mark Mueller098c9cb2016-09-08 09:01:57 -060012748 char const *vsSource =
12749 "#version 450\n"
12750 "\n"
12751 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12752 " mat4 mvp;\n"
12753 "} ubuf;\n"
12754 "out gl_PerVertex {\n"
12755 " vec4 gl_Position;\n"
12756 "};\n"
12757 "void main(){\n"
12758 " gl_Position = ubuf.mvp * vec4(1);\n"
12759 "}\n";
12760
12761 char const *fsSource =
12762 "#version 450\n"
12763 "\n"
12764 "layout(location = 0) out vec4 uFragColor;\n"
12765 "void main(){\n"
12766 " uFragColor = vec4(0,1,0,1);\n"
12767 "}\n";
12768
12769 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12770 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12771
12772 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12773 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12774 pipeline_layout_create_info.setLayoutCount = 1;
12775 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12776
12777 VkPipelineLayout pipeline_layout;
12778 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12779
12780 VkPipelineObj pipe(m_device);
12781 pipe.AddColorAttachment();
12782 pipe.AddShader(&vs);
12783 pipe.AddShader(&fs);
12784
12785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12786 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12787 m_errorMonitor->VerifyFound();
12788
12789 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12790 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12791 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12792}
12793
12794TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12795 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12796 "accessible from the current shader stage.");
12797
12798 ASSERT_NO_FATAL_FAILURE(InitState());
12799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12800
12801 const char *push_constant_not_accessible_message =
12802 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12803
12804 char const *vsSource =
12805 "#version 450\n"
12806 "\n"
12807 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12808 "out gl_PerVertex {\n"
12809 " vec4 gl_Position;\n"
12810 "};\n"
12811 "void main(){\n"
12812 " gl_Position = vec4(consts.x);\n"
12813 "}\n";
12814
12815 char const *fsSource =
12816 "#version 450\n"
12817 "\n"
12818 "layout(location = 0) out vec4 uFragColor;\n"
12819 "void main(){\n"
12820 " uFragColor = vec4(0,1,0,1);\n"
12821 "}\n";
12822
12823 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12824 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12825
12826 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12827 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12828
12829 // Set up a push constant range
12830 VkPushConstantRange push_constant_ranges = {};
12831 // Set to the wrong stage to challenge core_validation
12832 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12833 push_constant_ranges.size = 4;
12834
12835 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12836 pipeline_layout_create_info.pushConstantRangeCount = 1;
12837
12838 VkPipelineLayout pipeline_layout;
12839 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12840
12841 VkPipelineObj pipe(m_device);
12842 pipe.AddColorAttachment();
12843 pipe.AddShader(&vs);
12844 pipe.AddShader(&fs);
12845
12846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12847 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12848 m_errorMonitor->VerifyFound();
12849
12850 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12851}
12852
12853TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12854 TEST_DESCRIPTION(
12855 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12856
12857 ASSERT_NO_FATAL_FAILURE(InitState());
12858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12859
12860 const char *feature_not_enabled_message =
12861 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12862
12863 // Some awkward steps are required to test with custom device features.
12864 std::vector<const char *> device_extension_names;
12865 auto features = m_device->phy().features();
12866 // Disable support for 64 bit floats
12867 features.shaderFloat64 = false;
12868 // The sacrificial device object
12869 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12870
12871 char const *vsSource = "#version 450\n"
12872 "\n"
12873 "out gl_PerVertex {\n"
12874 " vec4 gl_Position;\n"
12875 "};\n"
12876 "void main(){\n"
12877 " gl_Position = vec4(1);\n"
12878 "}\n";
12879 char const *fsSource = "#version 450\n"
12880 "\n"
12881 "layout(location=0) out vec4 color;\n"
12882 "void main(){\n"
12883 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12884 " color = vec4(green);\n"
12885 "}\n";
12886
12887 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12888 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12889
12890 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012891
12892 VkPipelineObj pipe(&test_device);
12893 pipe.AddColorAttachment();
12894 pipe.AddShader(&vs);
12895 pipe.AddShader(&fs);
12896
12897 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12898 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12899 VkPipelineLayout pipeline_layout;
12900 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12901
12902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12903 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12904 m_errorMonitor->VerifyFound();
12905
12906 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12907}
12908
12909TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12910 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12911
12912 ASSERT_NO_FATAL_FAILURE(InitState());
12913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12914
12915 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12916
12917 char const *vsSource = "#version 450\n"
12918 "\n"
12919 "out gl_PerVertex {\n"
12920 " vec4 gl_Position;\n"
12921 "};\n"
12922 "layout(xfb_buffer = 1) out;"
12923 "void main(){\n"
12924 " gl_Position = vec4(1);\n"
12925 "}\n";
12926 char const *fsSource = "#version 450\n"
12927 "\n"
12928 "layout(location=0) out vec4 color;\n"
12929 "void main(){\n"
12930 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12931 " color = vec4(green);\n"
12932 "}\n";
12933
12934 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12935 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12936
12937 VkPipelineObj pipe(m_device);
12938 pipe.AddColorAttachment();
12939 pipe.AddShader(&vs);
12940 pipe.AddShader(&fs);
12941
12942 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12943 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12944 VkPipelineLayout pipeline_layout;
12945 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12946
12947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12948 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12949 m_errorMonitor->VerifyFound();
12950
12951 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12952}
12953
Karl Schultz6addd812016-02-02 17:17:23 -070012954TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012955 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12956 "which is not present in the outputs of the previous stage");
12957
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012959
Chris Forbes59cb88d2015-05-25 11:13:13 +120012960 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012961 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012962
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012963 char const *vsSource = "#version 450\n"
12964 "\n"
12965 "out gl_PerVertex {\n"
12966 " vec4 gl_Position;\n"
12967 "};\n"
12968 "void main(){\n"
12969 " gl_Position = vec4(1);\n"
12970 "}\n";
12971 char const *fsSource = "#version 450\n"
12972 "\n"
12973 "layout(location=0) in float x;\n"
12974 "layout(location=0) out vec4 color;\n"
12975 "void main(){\n"
12976 " color = vec4(x);\n"
12977 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012978
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012981
12982 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012983 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012984 pipe.AddShader(&vs);
12985 pipe.AddShader(&fs);
12986
Chris Forbes59cb88d2015-05-25 11:13:13 +120012987 VkDescriptorSetObj descriptorSet(m_device);
12988 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012990
Tony Barbour5781e8f2015-08-04 16:23:11 -060012991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012992
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012993 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012994}
12995
Karl Schultz6addd812016-02-02 17:17:23 -070012996TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012997 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12998 "within an interace block, which is not present in the outputs "
12999 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013001
13002 ASSERT_NO_FATAL_FAILURE(InitState());
13003 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13004
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013005 char const *vsSource = "#version 450\n"
13006 "\n"
13007 "out gl_PerVertex {\n"
13008 " vec4 gl_Position;\n"
13009 "};\n"
13010 "void main(){\n"
13011 " gl_Position = vec4(1);\n"
13012 "}\n";
13013 char const *fsSource = "#version 450\n"
13014 "\n"
13015 "in block { layout(location=0) float x; } ins;\n"
13016 "layout(location=0) out vec4 color;\n"
13017 "void main(){\n"
13018 " color = vec4(ins.x);\n"
13019 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013020
13021 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13022 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13023
13024 VkPipelineObj pipe(m_device);
13025 pipe.AddColorAttachment();
13026 pipe.AddShader(&vs);
13027 pipe.AddShader(&fs);
13028
13029 VkDescriptorSetObj descriptorSet(m_device);
13030 descriptorSet.AppendDummy();
13031 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13032
13033 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13034
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013035 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013036}
13037
Karl Schultz6addd812016-02-02 17:17:23 -070013038TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013039 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013040 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13042 "output arr[2] of float32' vs 'ptr to "
Rene Lindsay479c2fa2017-01-10 11:43:26 -070013043 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013044
13045 ASSERT_NO_FATAL_FAILURE(InitState());
13046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13047
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 char const *vsSource = "#version 450\n"
13049 "\n"
13050 "layout(location=0) out float x[2];\n"
13051 "out gl_PerVertex {\n"
13052 " vec4 gl_Position;\n"
13053 "};\n"
13054 "void main(){\n"
13055 " x[0] = 0; x[1] = 0;\n"
13056 " gl_Position = vec4(1);\n"
13057 "}\n";
13058 char const *fsSource = "#version 450\n"
13059 "\n"
Rene Lindsay479c2fa2017-01-10 11:43:26 -070013060 "layout(location=0) in float x[1];\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013061 "layout(location=0) out vec4 color;\n"
13062 "void main(){\n"
Rene Lindsay479c2fa2017-01-10 11:43:26 -070013063 " color = vec4(x[0]);\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013064 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013065
13066 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13067 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13068
13069 VkPipelineObj pipe(m_device);
13070 pipe.AddColorAttachment();
13071 pipe.AddShader(&vs);
13072 pipe.AddShader(&fs);
13073
13074 VkDescriptorSetObj descriptorSet(m_device);
13075 descriptorSet.AppendDummy();
13076 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13077
13078 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13079
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013080 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013081}
13082
Karl Schultz6addd812016-02-02 17:17:23 -070013083TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013084 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013085 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013087
Chris Forbesb56af562015-05-25 11:13:17 +120013088 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013091 char const *vsSource = "#version 450\n"
13092 "\n"
13093 "layout(location=0) out int x;\n"
13094 "out gl_PerVertex {\n"
13095 " vec4 gl_Position;\n"
13096 "};\n"
13097 "void main(){\n"
13098 " x = 0;\n"
13099 " gl_Position = vec4(1);\n"
13100 "}\n";
13101 char const *fsSource = "#version 450\n"
13102 "\n"
13103 "layout(location=0) in float x;\n" /* VS writes int */
13104 "layout(location=0) out vec4 color;\n"
13105 "void main(){\n"
13106 " color = vec4(x);\n"
13107 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013108
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013109 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13110 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013111
13112 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013113 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013114 pipe.AddShader(&vs);
13115 pipe.AddShader(&fs);
13116
Chris Forbesb56af562015-05-25 11:13:17 +120013117 VkDescriptorSetObj descriptorSet(m_device);
13118 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013119 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013120
Tony Barbour5781e8f2015-08-04 16:23:11 -060013121 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013122
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013123 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013124}
13125
Karl Schultz6addd812016-02-02 17:17:23 -070013126TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013127 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013128 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120013129 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013131
13132 ASSERT_NO_FATAL_FAILURE(InitState());
13133 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13134
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013135 char const *vsSource = "#version 450\n"
13136 "\n"
13137 "out block { layout(location=0) int x; } outs;\n"
13138 "out gl_PerVertex {\n"
13139 " vec4 gl_Position;\n"
13140 "};\n"
13141 "void main(){\n"
13142 " outs.x = 0;\n"
13143 " gl_Position = vec4(1);\n"
13144 "}\n";
13145 char const *fsSource = "#version 450\n"
13146 "\n"
13147 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13148 "layout(location=0) out vec4 color;\n"
13149 "void main(){\n"
13150 " color = vec4(ins.x);\n"
13151 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013152
13153 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13154 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13155
13156 VkPipelineObj pipe(m_device);
13157 pipe.AddColorAttachment();
13158 pipe.AddShader(&vs);
13159 pipe.AddShader(&fs);
13160
13161 VkDescriptorSetObj descriptorSet(m_device);
13162 descriptorSet.AppendDummy();
13163 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13164
13165 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13166
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013167 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013168}
13169
13170TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013171 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013172 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120013173 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013174 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 +130013175
13176 ASSERT_NO_FATAL_FAILURE(InitState());
13177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13178
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013179 char const *vsSource = "#version 450\n"
13180 "\n"
13181 "out block { layout(location=1) float x; } outs;\n"
13182 "out gl_PerVertex {\n"
13183 " vec4 gl_Position;\n"
13184 "};\n"
13185 "void main(){\n"
13186 " outs.x = 0;\n"
13187 " gl_Position = vec4(1);\n"
13188 "}\n";
13189 char const *fsSource = "#version 450\n"
13190 "\n"
13191 "in block { layout(location=0) float x; } ins;\n"
13192 "layout(location=0) out vec4 color;\n"
13193 "void main(){\n"
13194 " color = vec4(ins.x);\n"
13195 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013196
13197 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13198 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13199
13200 VkPipelineObj pipe(m_device);
13201 pipe.AddColorAttachment();
13202 pipe.AddShader(&vs);
13203 pipe.AddShader(&fs);
13204
13205 VkDescriptorSetObj descriptorSet(m_device);
13206 descriptorSet.AppendDummy();
13207 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13208
13209 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13210
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013211 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013212}
13213
13214TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013215 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013216 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120013217 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013218 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 +130013219
13220 ASSERT_NO_FATAL_FAILURE(InitState());
13221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013223 char const *vsSource = "#version 450\n"
13224 "\n"
13225 "out block { layout(location=0, component=0) float x; } outs;\n"
13226 "out gl_PerVertex {\n"
13227 " vec4 gl_Position;\n"
13228 "};\n"
13229 "void main(){\n"
13230 " outs.x = 0;\n"
13231 " gl_Position = vec4(1);\n"
13232 "}\n";
13233 char const *fsSource = "#version 450\n"
13234 "\n"
13235 "in block { layout(location=0, component=1) float x; } ins;\n"
13236 "layout(location=0) out vec4 color;\n"
13237 "void main(){\n"
13238 " color = vec4(ins.x);\n"
13239 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013240
13241 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13242 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13243
13244 VkPipelineObj pipe(m_device);
13245 pipe.AddColorAttachment();
13246 pipe.AddShader(&vs);
13247 pipe.AddShader(&fs);
13248
13249 VkDescriptorSetObj descriptorSet(m_device);
13250 descriptorSet.AppendDummy();
13251 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13252
13253 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13254
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013255 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013256}
13257
Chris Forbes1f3b0152016-11-30 12:48:40 +130013258TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13259 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13260
13261 ASSERT_NO_FATAL_FAILURE(InitState());
13262 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13263
13264 char const *vsSource = "#version 450\n"
13265 "layout(location=0) out mediump float x;\n"
13266 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13267 char const *fsSource = "#version 450\n"
13268 "layout(location=0) in highp float x;\n"
13269 "layout(location=0) out vec4 color;\n"
13270 "void main() { color = vec4(x); }\n";
13271
13272 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13273 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13274
13275 VkPipelineObj pipe(m_device);
13276 pipe.AddColorAttachment();
13277 pipe.AddShader(&vs);
13278 pipe.AddShader(&fs);
13279
13280 VkDescriptorSetObj descriptorSet(m_device);
13281 descriptorSet.AppendDummy();
13282 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13283
13284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13285
13286 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13287
13288 m_errorMonitor->VerifyFound();
13289}
13290
Chris Forbes870a39e2016-11-30 12:55:56 +130013291TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13292 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13293
13294 ASSERT_NO_FATAL_FAILURE(InitState());
13295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13296
13297 char const *vsSource = "#version 450\n"
13298 "out block { layout(location=0) mediump float x; };\n"
13299 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13300 char const *fsSource = "#version 450\n"
13301 "in block { layout(location=0) highp float x; };\n"
13302 "layout(location=0) out vec4 color;\n"
13303 "void main() { color = vec4(x); }\n";
13304
13305 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13306 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13307
13308 VkPipelineObj pipe(m_device);
13309 pipe.AddColorAttachment();
13310 pipe.AddShader(&vs);
13311 pipe.AddShader(&fs);
13312
13313 VkDescriptorSetObj descriptorSet(m_device);
13314 descriptorSet.AppendDummy();
13315 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13316
13317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13318
13319 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13320
13321 m_errorMonitor->VerifyFound();
13322}
13323
Karl Schultz6addd812016-02-02 17:17:23 -070013324TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013325 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13326 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013328
Chris Forbesde136e02015-05-25 11:13:28 +120013329 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013331
13332 VkVertexInputBindingDescription input_binding;
13333 memset(&input_binding, 0, sizeof(input_binding));
13334
13335 VkVertexInputAttributeDescription input_attrib;
13336 memset(&input_attrib, 0, sizeof(input_attrib));
13337 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13338
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013339 char const *vsSource = "#version 450\n"
13340 "\n"
13341 "out gl_PerVertex {\n"
13342 " vec4 gl_Position;\n"
13343 "};\n"
13344 "void main(){\n"
13345 " gl_Position = vec4(1);\n"
13346 "}\n";
13347 char const *fsSource = "#version 450\n"
13348 "\n"
13349 "layout(location=0) out vec4 color;\n"
13350 "void main(){\n"
13351 " color = vec4(1);\n"
13352 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013353
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013354 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13355 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013356
13357 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013358 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013359 pipe.AddShader(&vs);
13360 pipe.AddShader(&fs);
13361
13362 pipe.AddVertexInputBindings(&input_binding, 1);
13363 pipe.AddVertexInputAttribs(&input_attrib, 1);
13364
Chris Forbesde136e02015-05-25 11:13:28 +120013365 VkDescriptorSetObj descriptorSet(m_device);
13366 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013367 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013368
Tony Barbour5781e8f2015-08-04 16:23:11 -060013369 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013370
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013371 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013372}
13373
Karl Schultz6addd812016-02-02 17:17:23 -070013374TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013375 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13376 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013378
13379 ASSERT_NO_FATAL_FAILURE(InitState());
13380 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13381
13382 VkVertexInputBindingDescription input_binding;
13383 memset(&input_binding, 0, sizeof(input_binding));
13384
13385 VkVertexInputAttributeDescription input_attrib;
13386 memset(&input_attrib, 0, sizeof(input_attrib));
13387 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013389 char const *vsSource = "#version 450\n"
13390 "\n"
13391 "layout(location=1) in float x;\n"
13392 "out gl_PerVertex {\n"
13393 " vec4 gl_Position;\n"
13394 "};\n"
13395 "void main(){\n"
13396 " gl_Position = vec4(x);\n"
13397 "}\n";
13398 char const *fsSource = "#version 450\n"
13399 "\n"
13400 "layout(location=0) out vec4 color;\n"
13401 "void main(){\n"
13402 " color = vec4(1);\n"
13403 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013404
13405 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13406 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13407
13408 VkPipelineObj pipe(m_device);
13409 pipe.AddColorAttachment();
13410 pipe.AddShader(&vs);
13411 pipe.AddShader(&fs);
13412
13413 pipe.AddVertexInputBindings(&input_binding, 1);
13414 pipe.AddVertexInputAttribs(&input_attrib, 1);
13415
13416 VkDescriptorSetObj descriptorSet(m_device);
13417 descriptorSet.AppendDummy();
13418 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13419
13420 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13421
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013422 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013423}
13424
Karl Schultz6addd812016-02-02 17:17:23 -070013425TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013426 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013427 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013429
Chris Forbes62e8e502015-05-25 11:13:29 +120013430 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013431 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013432
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013433 char const *vsSource = "#version 450\n"
13434 "\n"
13435 "layout(location=0) in vec4 x;\n" /* not provided */
13436 "out gl_PerVertex {\n"
13437 " vec4 gl_Position;\n"
13438 "};\n"
13439 "void main(){\n"
13440 " gl_Position = x;\n"
13441 "}\n";
13442 char const *fsSource = "#version 450\n"
13443 "\n"
13444 "layout(location=0) out vec4 color;\n"
13445 "void main(){\n"
13446 " color = vec4(1);\n"
13447 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013448
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013449 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13450 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013451
13452 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013453 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013454 pipe.AddShader(&vs);
13455 pipe.AddShader(&fs);
13456
Chris Forbes62e8e502015-05-25 11:13:29 +120013457 VkDescriptorSetObj descriptorSet(m_device);
13458 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013459 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013460
Tony Barbour5781e8f2015-08-04 16:23:11 -060013461 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013462
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013463 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013464}
13465
Karl Schultz6addd812016-02-02 17:17:23 -070013466TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013467 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13468 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013469 "vertex shader input that consumes it");
13470 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 -060013471
Chris Forbesc97d98e2015-05-25 11:13:31 +120013472 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013473 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013474
13475 VkVertexInputBindingDescription input_binding;
13476 memset(&input_binding, 0, sizeof(input_binding));
13477
13478 VkVertexInputAttributeDescription input_attrib;
13479 memset(&input_attrib, 0, sizeof(input_attrib));
13480 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13481
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013482 char const *vsSource = "#version 450\n"
13483 "\n"
13484 "layout(location=0) in int x;\n" /* attrib provided float */
13485 "out gl_PerVertex {\n"
13486 " vec4 gl_Position;\n"
13487 "};\n"
13488 "void main(){\n"
13489 " gl_Position = vec4(x);\n"
13490 "}\n";
13491 char const *fsSource = "#version 450\n"
13492 "\n"
13493 "layout(location=0) out vec4 color;\n"
13494 "void main(){\n"
13495 " color = vec4(1);\n"
13496 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013497
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013498 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13499 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013500
13501 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013502 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013503 pipe.AddShader(&vs);
13504 pipe.AddShader(&fs);
13505
13506 pipe.AddVertexInputBindings(&input_binding, 1);
13507 pipe.AddVertexInputAttribs(&input_attrib, 1);
13508
Chris Forbesc97d98e2015-05-25 11:13:31 +120013509 VkDescriptorSetObj descriptorSet(m_device);
13510 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013511 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013512
Tony Barbour5781e8f2015-08-04 16:23:11 -060013513 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013514
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013515 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013516}
13517
Chris Forbesc68b43c2016-04-06 11:18:47 +120013518TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013519 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13520 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13522 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013523
13524 ASSERT_NO_FATAL_FAILURE(InitState());
13525 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13526
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013527 char const *vsSource = "#version 450\n"
13528 "\n"
13529 "out gl_PerVertex {\n"
13530 " vec4 gl_Position;\n"
13531 "};\n"
13532 "void main(){\n"
13533 " gl_Position = vec4(1);\n"
13534 "}\n";
13535 char const *fsSource = "#version 450\n"
13536 "\n"
13537 "layout(location=0) out vec4 color;\n"
13538 "void main(){\n"
13539 " color = vec4(1);\n"
13540 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013541
13542 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13543 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13544
13545 VkPipelineObj pipe(m_device);
13546 pipe.AddColorAttachment();
13547 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013548 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013549 pipe.AddShader(&fs);
13550
13551 VkDescriptorSetObj descriptorSet(m_device);
13552 descriptorSet.AppendDummy();
13553 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13554
13555 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13556
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013557 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013558}
13559
Chris Forbes82ff92a2016-09-09 10:50:24 +120013560TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13562 "No entrypoint found named `foo`");
13563
13564 ASSERT_NO_FATAL_FAILURE(InitState());
13565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13566
13567 char const *vsSource = "#version 450\n"
13568 "out gl_PerVertex {\n"
13569 " vec4 gl_Position;\n"
13570 "};\n"
13571 "void main(){\n"
13572 " gl_Position = vec4(0);\n"
13573 "}\n";
13574 char const *fsSource = "#version 450\n"
13575 "\n"
13576 "layout(location=0) out vec4 color;\n"
13577 "void main(){\n"
13578 " color = vec4(1);\n"
13579 "}\n";
13580
13581 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13582 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13583
13584 VkPipelineObj pipe(m_device);
13585 pipe.AddColorAttachment();
13586 pipe.AddShader(&vs);
13587 pipe.AddShader(&fs);
13588
13589 VkDescriptorSetObj descriptorSet(m_device);
13590 descriptorSet.AppendDummy();
13591 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13592
13593 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13594
13595 m_errorMonitor->VerifyFound();
13596}
13597
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013598TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13599 m_errorMonitor->SetDesiredFailureMsg(
13600 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13601 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13602 "uses a depth/stencil attachment");
13603
13604 ASSERT_NO_FATAL_FAILURE(InitState());
13605 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13606
13607 char const *vsSource = "#version 450\n"
13608 "void main(){ gl_Position = vec4(0); }\n";
13609 char const *fsSource = "#version 450\n"
13610 "\n"
13611 "layout(location=0) out vec4 color;\n"
13612 "void main(){\n"
13613 " color = vec4(1);\n"
13614 "}\n";
13615
13616 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13617 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13618
13619 VkPipelineObj pipe(m_device);
13620 pipe.AddColorAttachment();
13621 pipe.AddShader(&vs);
13622 pipe.AddShader(&fs);
13623
13624 VkDescriptorSetObj descriptorSet(m_device);
13625 descriptorSet.AppendDummy();
13626 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13627
13628 VkAttachmentDescription attachments[] = {
13629 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13630 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13631 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13632 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13633 },
13634 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13635 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13636 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13637 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13638 },
13639 };
13640 VkAttachmentReference refs[] = {
13641 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13642 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13643 };
13644 VkSubpassDescription subpass = {
13645 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13646 1, &refs[0], nullptr, &refs[1],
13647 0, nullptr
13648 };
13649 VkRenderPassCreateInfo rpci = {
13650 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13651 0, 2, attachments, 1, &subpass, 0, nullptr
13652 };
13653 VkRenderPass rp;
13654 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13655 ASSERT_VK_SUCCESS(err);
13656
13657 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13658
13659 m_errorMonitor->VerifyFound();
13660
13661 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13662}
13663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013664TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013665 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13666 "the TCS without the patch decoration, but consumed in the TES "
13667 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13669 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013670
13671 ASSERT_NO_FATAL_FAILURE(InitState());
13672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13673
Chris Forbesc1e852d2016-04-04 19:26:42 +120013674 if (!m_device->phy().features().tessellationShader) {
13675 printf("Device does not support tessellation shaders; skipped.\n");
13676 return;
13677 }
13678
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013679 char const *vsSource = "#version 450\n"
13680 "void main(){}\n";
13681 char const *tcsSource = "#version 450\n"
13682 "layout(location=0) out int x[];\n"
13683 "layout(vertices=3) out;\n"
13684 "void main(){\n"
13685 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13686 " gl_TessLevelInner[0] = 1;\n"
13687 " x[gl_InvocationID] = gl_InvocationID;\n"
13688 "}\n";
13689 char const *tesSource = "#version 450\n"
13690 "layout(triangles, equal_spacing, cw) in;\n"
13691 "layout(location=0) patch in int x;\n"
13692 "out gl_PerVertex { vec4 gl_Position; };\n"
13693 "void main(){\n"
13694 " gl_Position.xyz = gl_TessCoord;\n"
13695 " gl_Position.w = x;\n"
13696 "}\n";
13697 char const *fsSource = "#version 450\n"
13698 "layout(location=0) out vec4 color;\n"
13699 "void main(){\n"
13700 " color = vec4(1);\n"
13701 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013702
13703 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13704 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13705 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13706 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13707
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013708 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13709 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013710
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013711 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013712
13713 VkPipelineObj pipe(m_device);
13714 pipe.SetInputAssembly(&iasci);
13715 pipe.SetTessellation(&tsci);
13716 pipe.AddColorAttachment();
13717 pipe.AddShader(&vs);
13718 pipe.AddShader(&tcs);
13719 pipe.AddShader(&tes);
13720 pipe.AddShader(&fs);
13721
13722 VkDescriptorSetObj descriptorSet(m_device);
13723 descriptorSet.AppendDummy();
13724 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13725
13726 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13727
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013728 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013729}
13730
Karl Schultz6addd812016-02-02 17:17:23 -070013731TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013732 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13733 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13735 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013736
Chris Forbes280ba2c2015-06-12 11:16:41 +120013737 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013739
13740 /* Two binding descriptions for binding 0 */
13741 VkVertexInputBindingDescription input_bindings[2];
13742 memset(input_bindings, 0, sizeof(input_bindings));
13743
13744 VkVertexInputAttributeDescription input_attrib;
13745 memset(&input_attrib, 0, sizeof(input_attrib));
13746 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13747
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013748 char const *vsSource = "#version 450\n"
13749 "\n"
13750 "layout(location=0) in float x;\n" /* attrib provided float */
13751 "out gl_PerVertex {\n"
13752 " vec4 gl_Position;\n"
13753 "};\n"
13754 "void main(){\n"
13755 " gl_Position = vec4(x);\n"
13756 "}\n";
13757 char const *fsSource = "#version 450\n"
13758 "\n"
13759 "layout(location=0) out vec4 color;\n"
13760 "void main(){\n"
13761 " color = vec4(1);\n"
13762 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013763
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013764 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13765 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013766
13767 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013768 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013769 pipe.AddShader(&vs);
13770 pipe.AddShader(&fs);
13771
13772 pipe.AddVertexInputBindings(input_bindings, 2);
13773 pipe.AddVertexInputAttribs(&input_attrib, 1);
13774
Chris Forbes280ba2c2015-06-12 11:16:41 +120013775 VkDescriptorSetObj descriptorSet(m_device);
13776 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013777 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013778
Tony Barbour5781e8f2015-08-04 16:23:11 -060013779 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013780
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013781 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013782}
Chris Forbes8f68b562015-05-25 11:13:32 +120013783
Karl Schultz6addd812016-02-02 17:17:23 -070013784TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013785 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013786 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013788
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013789 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013791 char const *vsSource = "#version 450\n"
13792 "\n"
13793 "out gl_PerVertex {\n"
13794 " vec4 gl_Position;\n"
13795 "};\n"
13796 "void main(){\n"
13797 " gl_Position = vec4(1);\n"
13798 "}\n";
13799 char const *fsSource = "#version 450\n"
13800 "\n"
13801 "void main(){\n"
13802 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013803
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013804 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13805 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013806
13807 VkPipelineObj pipe(m_device);
13808 pipe.AddShader(&vs);
13809 pipe.AddShader(&fs);
13810
Chia-I Wu08accc62015-07-07 11:50:03 +080013811 /* set up CB 0, not written */
13812 pipe.AddColorAttachment();
13813 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013814
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013815 VkDescriptorSetObj descriptorSet(m_device);
13816 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013817 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013818
Tony Barbour5781e8f2015-08-04 16:23:11 -060013819 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013820
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013821 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013822}
13823
Karl Schultz6addd812016-02-02 17:17:23 -070013824TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013825 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013826 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013828 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013829
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013830 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013831
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013832 char const *vsSource = "#version 450\n"
13833 "\n"
13834 "out gl_PerVertex {\n"
13835 " vec4 gl_Position;\n"
13836 "};\n"
13837 "void main(){\n"
13838 " gl_Position = vec4(1);\n"
13839 "}\n";
13840 char const *fsSource = "#version 450\n"
13841 "\n"
13842 "layout(location=0) out vec4 x;\n"
13843 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13844 "void main(){\n"
13845 " x = vec4(1);\n"
13846 " y = vec4(1);\n"
13847 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013848
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013849 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13850 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013851
13852 VkPipelineObj pipe(m_device);
13853 pipe.AddShader(&vs);
13854 pipe.AddShader(&fs);
13855
Chia-I Wu08accc62015-07-07 11:50:03 +080013856 /* set up CB 0, not written */
13857 pipe.AddColorAttachment();
13858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013859 /* FS writes CB 1, but we don't configure it */
13860
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013861 VkDescriptorSetObj descriptorSet(m_device);
13862 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013863 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013864
Tony Barbour5781e8f2015-08-04 16:23:11 -060013865 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013866
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013867 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013868}
13869
Karl Schultz6addd812016-02-02 17:17:23 -070013870TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013871 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013872 "type of an fragment shader output variable, and the format of the corresponding attachment");
13873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013874
Chris Forbesa36d69e2015-05-25 11:13:44 +120013875 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013877 char const *vsSource = "#version 450\n"
13878 "\n"
13879 "out gl_PerVertex {\n"
13880 " vec4 gl_Position;\n"
13881 "};\n"
13882 "void main(){\n"
13883 " gl_Position = vec4(1);\n"
13884 "}\n";
13885 char const *fsSource = "#version 450\n"
13886 "\n"
13887 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13888 "void main(){\n"
13889 " x = ivec4(1);\n"
13890 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013891
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013892 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13893 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013894
13895 VkPipelineObj pipe(m_device);
13896 pipe.AddShader(&vs);
13897 pipe.AddShader(&fs);
13898
Chia-I Wu08accc62015-07-07 11:50:03 +080013899 /* set up CB 0; type is UNORM by default */
13900 pipe.AddColorAttachment();
13901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013902
Chris Forbesa36d69e2015-05-25 11:13:44 +120013903 VkDescriptorSetObj descriptorSet(m_device);
13904 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013905 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013906
Tony Barbour5781e8f2015-08-04 16:23:11 -060013907 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013908
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013909 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013910}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013911
Karl Schultz6addd812016-02-02 17:17:23 -070013912TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013913 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13914 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013916
Chris Forbes556c76c2015-08-14 12:04:59 +120013917 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013919 char const *vsSource = "#version 450\n"
13920 "\n"
13921 "out gl_PerVertex {\n"
13922 " vec4 gl_Position;\n"
13923 "};\n"
13924 "void main(){\n"
13925 " gl_Position = vec4(1);\n"
13926 "}\n";
13927 char const *fsSource = "#version 450\n"
13928 "\n"
13929 "layout(location=0) out vec4 x;\n"
13930 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13931 "void main(){\n"
13932 " x = vec4(bar.y);\n"
13933 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013934
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013937
Chris Forbes556c76c2015-08-14 12:04:59 +120013938 VkPipelineObj pipe(m_device);
13939 pipe.AddShader(&vs);
13940 pipe.AddShader(&fs);
13941
13942 /* set up CB 0; type is UNORM by default */
13943 pipe.AddColorAttachment();
13944 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13945
13946 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013947 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013948
13949 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13950
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013951 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013952}
13953
Chris Forbes5c59e902016-02-26 16:56:09 +130013954TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013955 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13956 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013958
13959 ASSERT_NO_FATAL_FAILURE(InitState());
13960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013961 char const *vsSource = "#version 450\n"
13962 "\n"
13963 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13964 "out gl_PerVertex {\n"
13965 " vec4 gl_Position;\n"
13966 "};\n"
13967 "void main(){\n"
13968 " gl_Position = vec4(consts.x);\n"
13969 "}\n";
13970 char const *fsSource = "#version 450\n"
13971 "\n"
13972 "layout(location=0) out vec4 x;\n"
13973 "void main(){\n"
13974 " x = vec4(1);\n"
13975 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013976
13977 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13978 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13979
13980 VkPipelineObj pipe(m_device);
13981 pipe.AddShader(&vs);
13982 pipe.AddShader(&fs);
13983
13984 /* set up CB 0; type is UNORM by default */
13985 pipe.AddColorAttachment();
13986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13987
13988 VkDescriptorSetObj descriptorSet(m_device);
13989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13990
13991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13992
13993 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013994 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013995}
13996
Chris Forbes3fb17902016-08-22 14:57:55 +120013997TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13998 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
13999 "which is not included in the subpass description");
14000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14001 "consumes input attachment index 0 but not provided in subpass");
14002
14003 ASSERT_NO_FATAL_FAILURE(InitState());
14004
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014005 char const *vsSource = "#version 450\n"
14006 "\n"
14007 "out gl_PerVertex {\n"
14008 " vec4 gl_Position;\n"
14009 "};\n"
14010 "void main(){\n"
14011 " gl_Position = vec4(1);\n"
14012 "}\n";
14013 char const *fsSource = "#version 450\n"
14014 "\n"
14015 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14016 "layout(location=0) out vec4 color;\n"
14017 "void main() {\n"
14018 " color = subpassLoad(x);\n"
14019 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014020
14021 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14022 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14023
14024 VkPipelineObj pipe(m_device);
14025 pipe.AddShader(&vs);
14026 pipe.AddShader(&fs);
14027 pipe.AddColorAttachment();
14028 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14029
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014030 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14031 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014032 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014033 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014034 ASSERT_VK_SUCCESS(err);
14035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014036 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014037 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014038 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014039 ASSERT_VK_SUCCESS(err);
14040
14041 // error here.
14042 pipe.CreateVKPipeline(pl, renderPass());
14043
14044 m_errorMonitor->VerifyFound();
14045
14046 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14047 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14048}
14049
Chris Forbes5a9a0472016-08-22 16:02:09 +120014050TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
14051 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14052 "with a format having a different fundamental type");
14053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14054 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14055
14056 ASSERT_NO_FATAL_FAILURE(InitState());
14057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014058 char const *vsSource = "#version 450\n"
14059 "\n"
14060 "out gl_PerVertex {\n"
14061 " vec4 gl_Position;\n"
14062 "};\n"
14063 "void main(){\n"
14064 " gl_Position = vec4(1);\n"
14065 "}\n";
14066 char const *fsSource = "#version 450\n"
14067 "\n"
14068 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14069 "layout(location=0) out vec4 color;\n"
14070 "void main() {\n"
14071 " color = subpassLoad(x);\n"
14072 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014073
14074 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14075 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14076
14077 VkPipelineObj pipe(m_device);
14078 pipe.AddShader(&vs);
14079 pipe.AddShader(&fs);
14080 pipe.AddColorAttachment();
14081 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14082
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014083 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14084 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014085 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014086 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014087 ASSERT_VK_SUCCESS(err);
14088
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014089 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014090 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014091 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014092 ASSERT_VK_SUCCESS(err);
14093
14094 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014095 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14096 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14097 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14098 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14099 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 +120014100 };
14101 VkAttachmentReference color = {
14102 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14103 };
14104 VkAttachmentReference input = {
14105 1, VK_IMAGE_LAYOUT_GENERAL,
14106 };
14107
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014108 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014109
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014110 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014111 VkRenderPass rp;
14112 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14113 ASSERT_VK_SUCCESS(err);
14114
14115 // error here.
14116 pipe.CreateVKPipeline(pl, rp);
14117
14118 m_errorMonitor->VerifyFound();
14119
14120 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14121 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14122 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14123}
14124
Chris Forbes541f7b02016-08-22 15:30:27 +120014125TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14126 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14127 "which is not included in the subpass description -- array case");
14128 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014129 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014130
14131 ASSERT_NO_FATAL_FAILURE(InitState());
14132
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014133 char const *vsSource = "#version 450\n"
14134 "\n"
14135 "out gl_PerVertex {\n"
14136 " vec4 gl_Position;\n"
14137 "};\n"
14138 "void main(){\n"
14139 " gl_Position = vec4(1);\n"
14140 "}\n";
14141 char const *fsSource = "#version 450\n"
14142 "\n"
Rene Lindsay07b60af2017-01-10 15:57:55 -070014143 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014144 "layout(location=0) out vec4 color;\n"
14145 "void main() {\n"
Rene Lindsay07b60af2017-01-10 15:57:55 -070014146 " color = subpassLoad(xs[0]);\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014147 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014148
14149 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14150 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14151
14152 VkPipelineObj pipe(m_device);
14153 pipe.AddShader(&vs);
14154 pipe.AddShader(&fs);
14155 pipe.AddColorAttachment();
14156 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14157
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014158 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14159 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014160 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014161 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014162 ASSERT_VK_SUCCESS(err);
14163
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014164 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014165 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014166 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014167 ASSERT_VK_SUCCESS(err);
14168
14169 // error here.
14170 pipe.CreateVKPipeline(pl, renderPass());
14171
14172 m_errorMonitor->VerifyFound();
14173
14174 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14175 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14176}
14177
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014178TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014179 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
14180 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014182
14183 ASSERT_NO_FATAL_FAILURE(InitState());
14184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014185 char const *csSource = "#version 450\n"
14186 "\n"
14187 "layout(local_size_x=1) in;\n"
14188 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14189 "void main(){\n"
14190 " x = vec4(1);\n"
14191 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014192
14193 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14194
14195 VkDescriptorSetObj descriptorSet(m_device);
14196 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14197
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014198 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14199 nullptr,
14200 0,
14201 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14202 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14203 descriptorSet.GetPipelineLayout(),
14204 VK_NULL_HANDLE,
14205 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014206
14207 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014208 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014209
14210 m_errorMonitor->VerifyFound();
14211
14212 if (err == VK_SUCCESS) {
14213 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14214 }
14215}
14216
Chris Forbes22a9b092016-07-19 14:34:05 +120014217TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014218 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
14219 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14221 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014222
14223 ASSERT_NO_FATAL_FAILURE(InitState());
14224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014225 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14226 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014227 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014228 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014229 ASSERT_VK_SUCCESS(err);
14230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014231 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014232 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014233 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014234 ASSERT_VK_SUCCESS(err);
14235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014236 char const *csSource = "#version 450\n"
14237 "\n"
14238 "layout(local_size_x=1) in;\n"
14239 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14240 "void main() {\n"
14241 " x.x = 1.0f;\n"
14242 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014243 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014245 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14246 nullptr,
14247 0,
14248 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14249 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14250 pl,
14251 VK_NULL_HANDLE,
14252 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014253
14254 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014255 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014256
14257 m_errorMonitor->VerifyFound();
14258
14259 if (err == VK_SUCCESS) {
14260 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14261 }
14262
14263 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14264 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14265}
14266
Chris Forbes50020592016-07-27 13:52:41 +120014267TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14268 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14269 "does not match the dimensionality declared in the shader");
14270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014271 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 +120014272
14273 ASSERT_NO_FATAL_FAILURE(InitState());
14274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014276 char const *vsSource = "#version 450\n"
14277 "\n"
14278 "out gl_PerVertex { vec4 gl_Position; };\n"
14279 "void main() { gl_Position = vec4(0); }\n";
14280 char const *fsSource = "#version 450\n"
14281 "\n"
14282 "layout(set=0, binding=0) uniform sampler3D s;\n"
14283 "layout(location=0) out vec4 color;\n"
14284 "void main() {\n"
14285 " color = texture(s, vec3(0));\n"
14286 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014287 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14288 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14289
14290 VkPipelineObj pipe(m_device);
14291 pipe.AddShader(&vs);
14292 pipe.AddShader(&fs);
14293 pipe.AddColorAttachment();
14294
14295 VkTextureObj texture(m_device, nullptr);
14296 VkSamplerObj sampler(m_device);
14297
14298 VkDescriptorSetObj descriptorSet(m_device);
14299 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14300 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14301
14302 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14303 ASSERT_VK_SUCCESS(err);
14304
Tony Barbour552f6c02016-12-21 14:34:07 -070014305 m_commandBuffer->BeginCommandBuffer();
14306 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014307
14308 m_commandBuffer->BindPipeline(pipe);
14309 m_commandBuffer->BindDescriptorSet(descriptorSet);
14310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014311 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014312 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014313 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014314 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14315
14316 // error produced here.
14317 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14318
14319 m_errorMonitor->VerifyFound();
14320
Tony Barbour552f6c02016-12-21 14:34:07 -070014321 m_commandBuffer->EndRenderPass();
14322 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014323}
14324
Chris Forbes5533bfc2016-07-27 14:12:34 +120014325TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14326 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14327 "are consumed via singlesample images types in the shader, or vice versa.");
14328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014330
14331 ASSERT_NO_FATAL_FAILURE(InitState());
14332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014334 char const *vsSource = "#version 450\n"
14335 "\n"
14336 "out gl_PerVertex { vec4 gl_Position; };\n"
14337 "void main() { gl_Position = vec4(0); }\n";
14338 char const *fsSource = "#version 450\n"
14339 "\n"
14340 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14341 "layout(location=0) out vec4 color;\n"
14342 "void main() {\n"
14343 " color = texelFetch(s, ivec2(0), 0);\n"
14344 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014345 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
14353 VkTextureObj texture(m_device, nullptr);
14354 VkSamplerObj sampler(m_device);
14355
14356 VkDescriptorSetObj descriptorSet(m_device);
14357 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14358 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14359
14360 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14361 ASSERT_VK_SUCCESS(err);
14362
Tony Barbour552f6c02016-12-21 14:34:07 -070014363 m_commandBuffer->BeginCommandBuffer();
14364 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014365
14366 m_commandBuffer->BindPipeline(pipe);
14367 m_commandBuffer->BindDescriptorSet(descriptorSet);
14368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014369 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014370 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014371 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014372 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14373
14374 // error produced here.
14375 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14376
14377 m_errorMonitor->VerifyFound();
14378
Tony Barbour552f6c02016-12-21 14:34:07 -070014379 m_commandBuffer->EndRenderPass();
14380 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014381}
14382
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014383#endif // SHADER_CHECKER_TESTS
14384
14385#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014386TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014388
14389 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014390
14391 // Create an image
14392 VkImage image;
14393
Karl Schultz6addd812016-02-02 17:17:23 -070014394 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14395 const int32_t tex_width = 32;
14396 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014397
14398 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014399 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14400 image_create_info.pNext = NULL;
14401 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14402 image_create_info.format = tex_format;
14403 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014404 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014405 image_create_info.extent.depth = 1;
14406 image_create_info.mipLevels = 1;
14407 image_create_info.arrayLayers = 1;
14408 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14409 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14410 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14411 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014412
14413 // Introduce error by sending down a bogus width extent
14414 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014415 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014416
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014417 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014418}
14419
Mark Youngc48c4c12016-04-11 14:26:49 -060014420TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14422 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014423
14424 ASSERT_NO_FATAL_FAILURE(InitState());
14425
14426 // Create an image
14427 VkImage image;
14428
14429 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14430 const int32_t tex_width = 32;
14431 const int32_t tex_height = 32;
14432
14433 VkImageCreateInfo image_create_info = {};
14434 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14435 image_create_info.pNext = NULL;
14436 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14437 image_create_info.format = tex_format;
14438 image_create_info.extent.width = tex_width;
14439 image_create_info.extent.height = tex_height;
14440 image_create_info.extent.depth = 1;
14441 image_create_info.mipLevels = 1;
14442 image_create_info.arrayLayers = 1;
14443 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14444 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14445 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14446 image_create_info.flags = 0;
14447
14448 // Introduce error by sending down a bogus width extent
14449 image_create_info.extent.width = 0;
14450 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14451
14452 m_errorMonitor->VerifyFound();
14453}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014454#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014455
Tobin Ehliscde08892015-09-22 10:11:37 -060014456#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014457
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014458TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14459 TEST_DESCRIPTION("Create a render pass with an attachment description "
14460 "format set to VK_FORMAT_UNDEFINED");
14461
14462 ASSERT_NO_FATAL_FAILURE(InitState());
14463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14464
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014466
14467 VkAttachmentReference color_attach = {};
14468 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14469 color_attach.attachment = 0;
14470 VkSubpassDescription subpass = {};
14471 subpass.colorAttachmentCount = 1;
14472 subpass.pColorAttachments = &color_attach;
14473
14474 VkRenderPassCreateInfo rpci = {};
14475 rpci.subpassCount = 1;
14476 rpci.pSubpasses = &subpass;
14477 rpci.attachmentCount = 1;
14478 VkAttachmentDescription attach_desc = {};
14479 attach_desc.format = VK_FORMAT_UNDEFINED;
14480 rpci.pAttachments = &attach_desc;
14481 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14482 VkRenderPass rp;
14483 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14484
14485 m_errorMonitor->VerifyFound();
14486
14487 if (result == VK_SUCCESS) {
14488 vkDestroyRenderPass(m_device->device(), rp, NULL);
14489 }
14490}
14491
Karl Schultz6addd812016-02-02 17:17:23 -070014492TEST_F(VkLayerTest, InvalidImageView) {
14493 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014494
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014496
Tobin Ehliscde08892015-09-22 10:11:37 -060014497 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014498
Mike Stroyana3082432015-09-25 13:39:21 -060014499 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014500 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014501
Karl Schultz6addd812016-02-02 17:17:23 -070014502 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14503 const int32_t tex_width = 32;
14504 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014505
14506 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014507 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14508 image_create_info.pNext = NULL;
14509 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14510 image_create_info.format = tex_format;
14511 image_create_info.extent.width = tex_width;
14512 image_create_info.extent.height = tex_height;
14513 image_create_info.extent.depth = 1;
14514 image_create_info.mipLevels = 1;
14515 image_create_info.arrayLayers = 1;
14516 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14517 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14518 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14519 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014520
Chia-I Wuf7458c52015-10-26 21:10:41 +080014521 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014522 ASSERT_VK_SUCCESS(err);
14523
14524 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014525 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014526 image_view_create_info.image = image;
14527 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14528 image_view_create_info.format = tex_format;
14529 image_view_create_info.subresourceRange.layerCount = 1;
14530 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14531 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014532 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014533
14534 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014535 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014536
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014537 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014538 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014539}
Mike Stroyana3082432015-09-25 13:39:21 -060014540
Mark Youngd339ba32016-05-30 13:28:35 -060014541TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14542 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014544 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014545
14546 ASSERT_NO_FATAL_FAILURE(InitState());
14547
14548 // Create an image and try to create a view with no memory backing the image
14549 VkImage image;
14550
14551 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14552 const int32_t tex_width = 32;
14553 const int32_t tex_height = 32;
14554
14555 VkImageCreateInfo image_create_info = {};
14556 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14557 image_create_info.pNext = NULL;
14558 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14559 image_create_info.format = tex_format;
14560 image_create_info.extent.width = tex_width;
14561 image_create_info.extent.height = tex_height;
14562 image_create_info.extent.depth = 1;
14563 image_create_info.mipLevels = 1;
14564 image_create_info.arrayLayers = 1;
14565 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14566 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14567 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14568 image_create_info.flags = 0;
14569
14570 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14571 ASSERT_VK_SUCCESS(err);
14572
14573 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014574 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014575 image_view_create_info.image = image;
14576 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14577 image_view_create_info.format = tex_format;
14578 image_view_create_info.subresourceRange.layerCount = 1;
14579 image_view_create_info.subresourceRange.baseMipLevel = 0;
14580 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014581 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014582
14583 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014584 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014585
14586 m_errorMonitor->VerifyFound();
14587 vkDestroyImage(m_device->device(), image, NULL);
14588 // If last error is success, it still created the view, so delete it.
14589 if (err == VK_SUCCESS) {
14590 vkDestroyImageView(m_device->device(), view, NULL);
14591 }
Mark Youngd339ba32016-05-30 13:28:35 -060014592}
14593
Karl Schultz6addd812016-02-02 17:17:23 -070014594TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014595 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014597
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014598 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014599
Karl Schultz6addd812016-02-02 17:17:23 -070014600 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014601 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014602 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014603 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014604
14605 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014606 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014607 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014608 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14609 image_view_create_info.format = tex_format;
14610 image_view_create_info.subresourceRange.baseMipLevel = 0;
14611 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014612 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014613 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014614 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014615
14616 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014617 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014618
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014619 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014620}
14621
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014622TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014623 VkResult err;
14624 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014625
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014627
Mike Stroyana3082432015-09-25 13:39:21 -060014628 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014629
14630 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014631 VkImage srcImage;
14632 VkImage dstImage;
14633 VkDeviceMemory srcMem;
14634 VkDeviceMemory destMem;
14635 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014636
14637 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014638 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14639 image_create_info.pNext = NULL;
14640 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14641 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14642 image_create_info.extent.width = 32;
14643 image_create_info.extent.height = 32;
14644 image_create_info.extent.depth = 1;
14645 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014646 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014647 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14648 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14649 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14650 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014651
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014652 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014653 ASSERT_VK_SUCCESS(err);
14654
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014655 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014656 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014657 ASSERT_VK_SUCCESS(err);
14658
14659 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014660 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014661 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14662 memAlloc.pNext = NULL;
14663 memAlloc.allocationSize = 0;
14664 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014665
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014666 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014667 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014668 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014669 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014670 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014671 ASSERT_VK_SUCCESS(err);
14672
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014673 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014674 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014675 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014676 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014677 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014678 ASSERT_VK_SUCCESS(err);
14679
14680 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14681 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014682 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014683 ASSERT_VK_SUCCESS(err);
14684
Tony Barbour552f6c02016-12-21 14:34:07 -070014685 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014686 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014687 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014688 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014689 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014690 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014691 copyRegion.srcOffset.x = 0;
14692 copyRegion.srcOffset.y = 0;
14693 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014694 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014695 copyRegion.dstSubresource.mipLevel = 0;
14696 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014697 // Introduce failure by forcing the dst layerCount to differ from src
14698 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014699 copyRegion.dstOffset.x = 0;
14700 copyRegion.dstOffset.y = 0;
14701 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014702 copyRegion.extent.width = 1;
14703 copyRegion.extent.height = 1;
14704 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014705 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070014706 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014707
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014708 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014709
Chia-I Wuf7458c52015-10-26 21:10:41 +080014710 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014711 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014712 vkFreeMemory(m_device->device(), srcMem, NULL);
14713 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014714}
14715
Tony Barbourd6673642016-05-05 14:46:39 -060014716TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14717
14718 TEST_DESCRIPTION("Creating images with unsuported formats ");
14719
14720 ASSERT_NO_FATAL_FAILURE(InitState());
14721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14722 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014723 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 -060014724 VK_IMAGE_TILING_OPTIMAL, 0);
14725 ASSERT_TRUE(image.initialized());
14726
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014727 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014728 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014729 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014730 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14731 image_create_info.format = VK_FORMAT_UNDEFINED;
14732 image_create_info.extent.width = 32;
14733 image_create_info.extent.height = 32;
14734 image_create_info.extent.depth = 1;
14735 image_create_info.mipLevels = 1;
14736 image_create_info.arrayLayers = 1;
14737 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14738 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14739 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14742 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014743
14744 VkImage localImage;
14745 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14746 m_errorMonitor->VerifyFound();
14747
Tony Barbourd6673642016-05-05 14:46:39 -060014748 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014749 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014750 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14751 VkFormat format = static_cast<VkFormat>(f);
14752 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014753 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014754 unsupported = format;
14755 break;
14756 }
14757 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014758
Tony Barbourd6673642016-05-05 14:46:39 -060014759 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014760 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014762
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014763 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014764 m_errorMonitor->VerifyFound();
14765 }
14766}
14767
14768TEST_F(VkLayerTest, ImageLayerViewTests) {
14769 VkResult ret;
14770 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14771
14772 ASSERT_NO_FATAL_FAILURE(InitState());
14773
14774 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014775 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 -060014776 VK_IMAGE_TILING_OPTIMAL, 0);
14777 ASSERT_TRUE(image.initialized());
14778
14779 VkImageView imgView;
14780 VkImageViewCreateInfo imgViewInfo = {};
14781 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14782 imgViewInfo.image = image.handle();
14783 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14784 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14785 imgViewInfo.subresourceRange.layerCount = 1;
14786 imgViewInfo.subresourceRange.baseMipLevel = 0;
14787 imgViewInfo.subresourceRange.levelCount = 1;
14788 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14789
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014791 // View can't have baseMipLevel >= image's mipLevels - Expect
14792 // VIEW_CREATE_ERROR
14793 imgViewInfo.subresourceRange.baseMipLevel = 1;
14794 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14795 m_errorMonitor->VerifyFound();
14796 imgViewInfo.subresourceRange.baseMipLevel = 0;
14797
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060014799 // View can't have baseArrayLayer >= image's arraySize - Expect
14800 // VIEW_CREATE_ERROR
14801 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14802 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14803 m_errorMonitor->VerifyFound();
14804 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14805
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14807 "pCreateInfo->subresourceRange."
14808 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014809 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14810 imgViewInfo.subresourceRange.levelCount = 0;
14811 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14812 m_errorMonitor->VerifyFound();
14813 imgViewInfo.subresourceRange.levelCount = 1;
14814
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014815 m_errorMonitor->SetDesiredFailureMsg(
14816 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14817 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014818 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14819 imgViewInfo.subresourceRange.layerCount = 0;
14820 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14821 m_errorMonitor->VerifyFound();
14822 imgViewInfo.subresourceRange.layerCount = 1;
14823
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14825 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14826 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014827 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14828 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14829 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14830 m_errorMonitor->VerifyFound();
14831 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14832
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060014834 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14835 // VIEW_CREATE_ERROR
14836 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14837 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14838 m_errorMonitor->VerifyFound();
14839 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14840
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014842 // TODO: Update framework to easily passing mutable flag into ImageObj init
14843 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070014844 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
14845 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14846 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014847 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14848 // VIEW_CREATE_ERROR
14849 VkImageCreateInfo mutImgInfo = image.create_info();
14850 VkImage mutImage;
14851 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014852 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014853 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14854 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14855 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14856 ASSERT_VK_SUCCESS(ret);
14857 imgViewInfo.image = mutImage;
14858 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14859 m_errorMonitor->VerifyFound();
14860 imgViewInfo.image = image.handle();
14861 vkDestroyImage(m_device->handle(), mutImage, NULL);
14862}
14863
14864TEST_F(VkLayerTest, MiscImageLayerTests) {
14865
14866 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14867
14868 ASSERT_NO_FATAL_FAILURE(InitState());
14869
Rene Lindsay135204f2016-12-22 17:11:09 -070014870 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060014871 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070014872 image.init(128, 128, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14873 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060014874 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060014875 vk_testing::Buffer buffer;
14876 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070014877 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060014878 VkBufferImageCopy region = {};
14879 region.bufferRowLength = 128;
14880 region.bufferImageHeight = 128;
14881 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14882 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014883 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014884 region.imageExtent.height = 4;
14885 region.imageExtent.width = 4;
14886 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070014887
14888 VkImageObj image2(m_device);
14889 image2.init(128, 128, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14890 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
14891 ASSERT_TRUE(image2.initialized());
14892 vk_testing::Buffer buffer2;
14893 VkMemoryPropertyFlags reqs2 = 0;
14894 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
14895 VkBufferImageCopy region2 = {};
14896 region2.bufferRowLength = 128;
14897 region2.bufferImageHeight = 128;
14898 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14899 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14900 region2.imageSubresource.layerCount = 1;
14901 region2.imageExtent.height = 4;
14902 region2.imageExtent.width = 4;
14903 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014904 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014905
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014906 // Image must have offset.z of 0 and extent.depth of 1
14907 // Introduce failure by setting imageExtent.depth to 0
14908 region.imageExtent.depth = 0;
14909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14910 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14911 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14912 m_errorMonitor->VerifyFound();
14913
14914 region.imageExtent.depth = 1;
14915
14916 // Image must have offset.z of 0 and extent.depth of 1
14917 // Introduce failure by setting imageOffset.z to 4
14918 region.imageOffset.z = 4;
14919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14920 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14921 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14922 m_errorMonitor->VerifyFound();
14923
14924 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014925 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14926 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070014927 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014929 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14930 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014931 m_errorMonitor->VerifyFound();
14932
14933 // BufferOffset must be a multiple of 4
14934 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070014935 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070014937 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
14938 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014939 m_errorMonitor->VerifyFound();
14940
14941 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14942 region.bufferOffset = 0;
14943 region.imageExtent.height = 128;
14944 region.imageExtent.width = 128;
14945 // Introduce failure by setting bufferRowLength > 0 but less than width
14946 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014948 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14949 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014950 m_errorMonitor->VerifyFound();
14951
14952 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14953 region.bufferRowLength = 128;
14954 // Introduce failure by setting bufferRowHeight > 0 but less than height
14955 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014957 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14958 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014959 m_errorMonitor->VerifyFound();
14960
14961 region.bufferImageHeight = 128;
Dave Houlton34df4cb2016-12-01 16:43:06 -070014962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014963 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014964 // Expect INVALID_FILTER
14965 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014966 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
14967 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014968 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014969 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14970 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014971 VkImageBlit blitRegion = {};
14972 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14973 blitRegion.srcSubresource.baseArrayLayer = 0;
14974 blitRegion.srcSubresource.layerCount = 1;
14975 blitRegion.srcSubresource.mipLevel = 0;
14976 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14977 blitRegion.dstSubresource.baseArrayLayer = 0;
14978 blitRegion.dstSubresource.layerCount = 1;
14979 blitRegion.dstSubresource.mipLevel = 0;
14980
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014981 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014982 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014983 m_errorMonitor->VerifyFound();
14984
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014985 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14987 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14988 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014989 m_errorMonitor->VerifyFound();
14990
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014991 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014992 VkImageMemoryBarrier img_barrier;
14993 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14994 img_barrier.pNext = NULL;
14995 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14996 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14997 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14998 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14999 img_barrier.image = image.handle();
15000 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15001 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15002 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15003 img_barrier.subresourceRange.baseArrayLayer = 0;
15004 img_barrier.subresourceRange.baseMipLevel = 0;
15005 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15006 img_barrier.subresourceRange.layerCount = 0;
15007 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015008 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15009 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015010 m_errorMonitor->VerifyFound();
15011 img_barrier.subresourceRange.layerCount = 1;
15012}
15013
15014TEST_F(VkLayerTest, ImageFormatLimits) {
15015
15016 TEST_DESCRIPTION("Exceed the limits of image format ");
15017
Cody Northropc31a84f2016-08-22 10:41:47 -060015018 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015020 VkImageCreateInfo image_create_info = {};
15021 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15022 image_create_info.pNext = NULL;
15023 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15024 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15025 image_create_info.extent.width = 32;
15026 image_create_info.extent.height = 32;
15027 image_create_info.extent.depth = 1;
15028 image_create_info.mipLevels = 1;
15029 image_create_info.arrayLayers = 1;
15030 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15031 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15032 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15033 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15034 image_create_info.flags = 0;
15035
15036 VkImage nullImg;
15037 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015038 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15039 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015040 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015041 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15042 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15043 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015044 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015047 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15048 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15049 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15050 m_errorMonitor->VerifyFound();
15051 image_create_info.mipLevels = 1;
15052
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015054 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15055 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15056 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15057 m_errorMonitor->VerifyFound();
15058 image_create_info.arrayLayers = 1;
15059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015061 int samples = imgFmtProps.sampleCounts >> 1;
15062 image_create_info.samples = (VkSampleCountFlagBits)samples;
15063 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15064 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15065 m_errorMonitor->VerifyFound();
15066 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15067
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
15069 "VK_IMAGE_LAYOUT_UNDEFINED or "
15070 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015071 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15072 // Expect INVALID_LAYOUT
15073 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15074 m_errorMonitor->VerifyFound();
15075 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15076}
15077
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015078TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
15079
15080 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015081 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015082
15083 ASSERT_NO_FATAL_FAILURE(InitState());
15084
15085 VkImageObj src_image(m_device);
15086 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15087 VkImageObj dst_image(m_device);
15088 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15089
Tony Barbour552f6c02016-12-21 14:34:07 -070015090 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015091 VkImageCopy copy_region;
15092 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15093 copy_region.srcSubresource.mipLevel = 0;
15094 copy_region.srcSubresource.baseArrayLayer = 0;
15095 copy_region.srcSubresource.layerCount = 0;
15096 copy_region.srcOffset.x = 0;
15097 copy_region.srcOffset.y = 0;
15098 copy_region.srcOffset.z = 0;
15099 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15100 copy_region.dstSubresource.mipLevel = 0;
15101 copy_region.dstSubresource.baseArrayLayer = 0;
15102 copy_region.dstSubresource.layerCount = 0;
15103 copy_region.dstOffset.x = 0;
15104 copy_region.dstOffset.y = 0;
15105 copy_region.dstOffset.z = 0;
15106 copy_region.extent.width = 64;
15107 copy_region.extent.height = 64;
15108 copy_region.extent.depth = 1;
15109 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15110 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015111 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015112
15113 m_errorMonitor->VerifyFound();
15114}
15115
15116TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
15117
15118 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015120
15121 ASSERT_NO_FATAL_FAILURE(InitState());
15122
15123 VkImageObj src_image(m_device);
15124 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15125 VkImageObj dst_image(m_device);
15126 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15127
Tony Barbour552f6c02016-12-21 14:34:07 -070015128 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015129 VkImageCopy copy_region;
15130 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15131 copy_region.srcSubresource.mipLevel = 0;
15132 copy_region.srcSubresource.baseArrayLayer = 0;
15133 copy_region.srcSubresource.layerCount = 0;
15134 copy_region.srcOffset.x = 0;
15135 copy_region.srcOffset.y = 0;
15136 copy_region.srcOffset.z = 0;
15137 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15138 copy_region.dstSubresource.mipLevel = 0;
15139 copy_region.dstSubresource.baseArrayLayer = 0;
15140 copy_region.dstSubresource.layerCount = 0;
15141 copy_region.dstOffset.x = 0;
15142 copy_region.dstOffset.y = 0;
15143 copy_region.dstOffset.z = 0;
15144 copy_region.extent.width = 64;
15145 copy_region.extent.height = 64;
15146 copy_region.extent.depth = 1;
15147 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15148 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015149 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015150
15151 m_errorMonitor->VerifyFound();
15152}
15153
Karl Schultz6addd812016-02-02 17:17:23 -070015154TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015155 VkResult err;
15156 bool pass;
15157
15158 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015159 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015160
15161 ASSERT_NO_FATAL_FAILURE(InitState());
15162
15163 // Create two images of different types and try to copy between them
15164 VkImage srcImage;
15165 VkImage dstImage;
15166 VkDeviceMemory srcMem;
15167 VkDeviceMemory destMem;
15168 VkMemoryRequirements memReqs;
15169
15170 VkImageCreateInfo image_create_info = {};
15171 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15172 image_create_info.pNext = NULL;
15173 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15174 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15175 image_create_info.extent.width = 32;
15176 image_create_info.extent.height = 32;
15177 image_create_info.extent.depth = 1;
15178 image_create_info.mipLevels = 1;
15179 image_create_info.arrayLayers = 1;
15180 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15181 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15182 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15183 image_create_info.flags = 0;
15184
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015185 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015186 ASSERT_VK_SUCCESS(err);
15187
15188 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15189 // Introduce failure by creating second image with a different-sized format.
15190 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015192 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015193 ASSERT_VK_SUCCESS(err);
15194
15195 // Allocate memory
15196 VkMemoryAllocateInfo memAlloc = {};
15197 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15198 memAlloc.pNext = NULL;
15199 memAlloc.allocationSize = 0;
15200 memAlloc.memoryTypeIndex = 0;
15201
15202 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15203 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015204 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015205 ASSERT_TRUE(pass);
15206 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15207 ASSERT_VK_SUCCESS(err);
15208
15209 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15210 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015211 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015212 ASSERT_TRUE(pass);
15213 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15214 ASSERT_VK_SUCCESS(err);
15215
15216 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15217 ASSERT_VK_SUCCESS(err);
15218 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15219 ASSERT_VK_SUCCESS(err);
15220
Tony Barbour552f6c02016-12-21 14:34:07 -070015221 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015222 VkImageCopy copyRegion;
15223 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15224 copyRegion.srcSubresource.mipLevel = 0;
15225 copyRegion.srcSubresource.baseArrayLayer = 0;
15226 copyRegion.srcSubresource.layerCount = 0;
15227 copyRegion.srcOffset.x = 0;
15228 copyRegion.srcOffset.y = 0;
15229 copyRegion.srcOffset.z = 0;
15230 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15231 copyRegion.dstSubresource.mipLevel = 0;
15232 copyRegion.dstSubresource.baseArrayLayer = 0;
15233 copyRegion.dstSubresource.layerCount = 0;
15234 copyRegion.dstOffset.x = 0;
15235 copyRegion.dstOffset.y = 0;
15236 copyRegion.dstOffset.z = 0;
15237 copyRegion.extent.width = 1;
15238 copyRegion.extent.height = 1;
15239 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015240 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015241 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015242
15243 m_errorMonitor->VerifyFound();
15244
15245 vkDestroyImage(m_device->device(), srcImage, NULL);
15246 vkDestroyImage(m_device->device(), dstImage, NULL);
15247 vkFreeMemory(m_device->device(), srcMem, NULL);
15248 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015249}
15250
Karl Schultz6addd812016-02-02 17:17:23 -070015251TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15252 VkResult err;
15253 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015254
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015255 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15257 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015258
Mike Stroyana3082432015-09-25 13:39:21 -060015259 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015260
15261 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015262 VkImage srcImage;
15263 VkImage dstImage;
15264 VkDeviceMemory srcMem;
15265 VkDeviceMemory destMem;
15266 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015267
15268 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015269 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15270 image_create_info.pNext = NULL;
15271 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15272 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15273 image_create_info.extent.width = 32;
15274 image_create_info.extent.height = 32;
15275 image_create_info.extent.depth = 1;
15276 image_create_info.mipLevels = 1;
15277 image_create_info.arrayLayers = 1;
15278 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15279 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15280 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15281 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015282
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015283 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015284 ASSERT_VK_SUCCESS(err);
15285
Karl Schultzbdb75952016-04-19 11:36:49 -060015286 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15287
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015288 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015289 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015290 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015291 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015292
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015293 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015294 ASSERT_VK_SUCCESS(err);
15295
15296 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015297 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015298 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15299 memAlloc.pNext = NULL;
15300 memAlloc.allocationSize = 0;
15301 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015302
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015303 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015304 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015305 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015306 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015307 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015308 ASSERT_VK_SUCCESS(err);
15309
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015310 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015311 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015312 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015313 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015314 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015315 ASSERT_VK_SUCCESS(err);
15316
15317 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15318 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015319 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015320 ASSERT_VK_SUCCESS(err);
15321
Tony Barbour552f6c02016-12-21 14:34:07 -070015322 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015323 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015324 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015325 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015326 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015327 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015328 copyRegion.srcOffset.x = 0;
15329 copyRegion.srcOffset.y = 0;
15330 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015331 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015332 copyRegion.dstSubresource.mipLevel = 0;
15333 copyRegion.dstSubresource.baseArrayLayer = 0;
15334 copyRegion.dstSubresource.layerCount = 0;
15335 copyRegion.dstOffset.x = 0;
15336 copyRegion.dstOffset.y = 0;
15337 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015338 copyRegion.extent.width = 1;
15339 copyRegion.extent.height = 1;
15340 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015341 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015342 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015343
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015344 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015345
Chia-I Wuf7458c52015-10-26 21:10:41 +080015346 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015347 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015348 vkFreeMemory(m_device->device(), srcMem, NULL);
15349 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015350}
15351
Karl Schultz6addd812016-02-02 17:17:23 -070015352TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15353 VkResult err;
15354 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015356 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15357 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015358
Mike Stroyana3082432015-09-25 13:39:21 -060015359 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015360
15361 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015362 VkImage srcImage;
15363 VkImage dstImage;
15364 VkDeviceMemory srcMem;
15365 VkDeviceMemory destMem;
15366 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015367
15368 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015369 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15370 image_create_info.pNext = NULL;
15371 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15372 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15373 image_create_info.extent.width = 32;
15374 image_create_info.extent.height = 1;
15375 image_create_info.extent.depth = 1;
15376 image_create_info.mipLevels = 1;
15377 image_create_info.arrayLayers = 1;
15378 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15379 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15380 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15381 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015383 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015384 ASSERT_VK_SUCCESS(err);
15385
Karl Schultz6addd812016-02-02 17:17:23 -070015386 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015388 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015389 ASSERT_VK_SUCCESS(err);
15390
15391 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015392 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015393 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15394 memAlloc.pNext = NULL;
15395 memAlloc.allocationSize = 0;
15396 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015397
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015398 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015399 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015400 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015401 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015402 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015403 ASSERT_VK_SUCCESS(err);
15404
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015405 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015406 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015407 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015408 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015409 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015410 ASSERT_VK_SUCCESS(err);
15411
15412 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15413 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015414 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015415 ASSERT_VK_SUCCESS(err);
15416
Tony Barbour552f6c02016-12-21 14:34:07 -070015417 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015418 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015419 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15420 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015421 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015422 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015423 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015424 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015425 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015426 resolveRegion.srcOffset.x = 0;
15427 resolveRegion.srcOffset.y = 0;
15428 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015429 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015430 resolveRegion.dstSubresource.mipLevel = 0;
15431 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015432 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015433 resolveRegion.dstOffset.x = 0;
15434 resolveRegion.dstOffset.y = 0;
15435 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015436 resolveRegion.extent.width = 1;
15437 resolveRegion.extent.height = 1;
15438 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015439 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015440 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015441
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015442 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015443
Chia-I Wuf7458c52015-10-26 21:10:41 +080015444 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015445 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015446 vkFreeMemory(m_device->device(), srcMem, NULL);
15447 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015448}
15449
Karl Schultz6addd812016-02-02 17:17:23 -070015450TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15451 VkResult err;
15452 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015453
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015454 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15455 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015456
Mike Stroyana3082432015-09-25 13:39:21 -060015457 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015458
Chris Forbesa7530692016-05-08 12:35:39 +120015459 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015460 VkImage srcImage;
15461 VkImage dstImage;
15462 VkDeviceMemory srcMem;
15463 VkDeviceMemory destMem;
15464 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015465
15466 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015467 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15468 image_create_info.pNext = NULL;
15469 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15470 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15471 image_create_info.extent.width = 32;
15472 image_create_info.extent.height = 1;
15473 image_create_info.extent.depth = 1;
15474 image_create_info.mipLevels = 1;
15475 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015476 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015477 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15478 // Note: Some implementations expect color attachment usage for any
15479 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015480 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015481 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015482
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015483 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015484 ASSERT_VK_SUCCESS(err);
15485
Karl Schultz6addd812016-02-02 17:17:23 -070015486 // Note: Some implementations expect color attachment usage for any
15487 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015488 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015490 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015491 ASSERT_VK_SUCCESS(err);
15492
15493 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015494 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015495 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15496 memAlloc.pNext = NULL;
15497 memAlloc.allocationSize = 0;
15498 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015499
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015500 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015501 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015502 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015503 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015504 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015505 ASSERT_VK_SUCCESS(err);
15506
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015507 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015508 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015509 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015510 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015511 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015512 ASSERT_VK_SUCCESS(err);
15513
15514 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15515 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015516 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015517 ASSERT_VK_SUCCESS(err);
15518
Tony Barbour552f6c02016-12-21 14:34:07 -070015519 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015520 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015521 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15522 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015523 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015524 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015525 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015526 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015527 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015528 resolveRegion.srcOffset.x = 0;
15529 resolveRegion.srcOffset.y = 0;
15530 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015531 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015532 resolveRegion.dstSubresource.mipLevel = 0;
15533 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015534 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015535 resolveRegion.dstOffset.x = 0;
15536 resolveRegion.dstOffset.y = 0;
15537 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015538 resolveRegion.extent.width = 1;
15539 resolveRegion.extent.height = 1;
15540 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015541 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015542 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015543
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015544 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015545
Chia-I Wuf7458c52015-10-26 21:10:41 +080015546 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015547 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015548 vkFreeMemory(m_device->device(), srcMem, NULL);
15549 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015550}
15551
Karl Schultz6addd812016-02-02 17:17:23 -070015552TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15553 VkResult err;
15554 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15557 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015558
Mike Stroyana3082432015-09-25 13:39:21 -060015559 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015560
15561 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015562 VkImage srcImage;
15563 VkImage dstImage;
15564 VkDeviceMemory srcMem;
15565 VkDeviceMemory destMem;
15566 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015567
15568 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015569 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15570 image_create_info.pNext = NULL;
15571 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15572 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15573 image_create_info.extent.width = 32;
15574 image_create_info.extent.height = 1;
15575 image_create_info.extent.depth = 1;
15576 image_create_info.mipLevels = 1;
15577 image_create_info.arrayLayers = 1;
15578 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15579 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15580 // Note: Some implementations expect color attachment usage for any
15581 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015582 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015583 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015584
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015585 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015586 ASSERT_VK_SUCCESS(err);
15587
Karl Schultz6addd812016-02-02 17:17:23 -070015588 // Set format to something other than source image
15589 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15590 // Note: Some implementations expect color attachment usage for any
15591 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015592 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015593 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015595 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015596 ASSERT_VK_SUCCESS(err);
15597
15598 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015599 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015600 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15601 memAlloc.pNext = NULL;
15602 memAlloc.allocationSize = 0;
15603 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015604
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015605 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015606 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015607 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015608 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015609 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015610 ASSERT_VK_SUCCESS(err);
15611
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015612 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015613 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015614 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015615 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015616 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015617 ASSERT_VK_SUCCESS(err);
15618
15619 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15620 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015621 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015622 ASSERT_VK_SUCCESS(err);
15623
Tony Barbour552f6c02016-12-21 14:34:07 -070015624 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015625 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015626 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15627 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015628 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015629 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015630 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015631 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015632 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015633 resolveRegion.srcOffset.x = 0;
15634 resolveRegion.srcOffset.y = 0;
15635 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015636 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015637 resolveRegion.dstSubresource.mipLevel = 0;
15638 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015639 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015640 resolveRegion.dstOffset.x = 0;
15641 resolveRegion.dstOffset.y = 0;
15642 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015643 resolveRegion.extent.width = 1;
15644 resolveRegion.extent.height = 1;
15645 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015646 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015647 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015648
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015649 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015650
Chia-I Wuf7458c52015-10-26 21:10:41 +080015651 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015652 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015653 vkFreeMemory(m_device->device(), srcMem, NULL);
15654 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015655}
15656
Karl Schultz6addd812016-02-02 17:17:23 -070015657TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15658 VkResult err;
15659 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015660
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15662 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015663
Mike Stroyana3082432015-09-25 13:39:21 -060015664 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015665
15666 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015667 VkImage srcImage;
15668 VkImage dstImage;
15669 VkDeviceMemory srcMem;
15670 VkDeviceMemory destMem;
15671 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015672
15673 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015674 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15675 image_create_info.pNext = NULL;
15676 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15677 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15678 image_create_info.extent.width = 32;
15679 image_create_info.extent.height = 1;
15680 image_create_info.extent.depth = 1;
15681 image_create_info.mipLevels = 1;
15682 image_create_info.arrayLayers = 1;
15683 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15684 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15685 // Note: Some implementations expect color attachment usage for any
15686 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015687 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015688 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015689
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015690 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015691 ASSERT_VK_SUCCESS(err);
15692
Karl Schultz6addd812016-02-02 17:17:23 -070015693 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15694 // Note: Some implementations expect color attachment usage for any
15695 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015696 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015697 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015698
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015699 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015700 ASSERT_VK_SUCCESS(err);
15701
15702 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015703 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015704 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15705 memAlloc.pNext = NULL;
15706 memAlloc.allocationSize = 0;
15707 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015708
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015709 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015710 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015711 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015712 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015713 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015714 ASSERT_VK_SUCCESS(err);
15715
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015716 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015717 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015718 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015719 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015720 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015721 ASSERT_VK_SUCCESS(err);
15722
15723 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15724 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015725 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015726 ASSERT_VK_SUCCESS(err);
15727
Tony Barbour552f6c02016-12-21 14:34:07 -070015728 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015729 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015730 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15731 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015732 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015733 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015734 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015735 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015736 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015737 resolveRegion.srcOffset.x = 0;
15738 resolveRegion.srcOffset.y = 0;
15739 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015740 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015741 resolveRegion.dstSubresource.mipLevel = 0;
15742 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015743 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015744 resolveRegion.dstOffset.x = 0;
15745 resolveRegion.dstOffset.y = 0;
15746 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015747 resolveRegion.extent.width = 1;
15748 resolveRegion.extent.height = 1;
15749 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015750 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015751 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015752
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015753 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015754
Chia-I Wuf7458c52015-10-26 21:10:41 +080015755 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015756 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015757 vkFreeMemory(m_device->device(), srcMem, NULL);
15758 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015759}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015760
Karl Schultz6addd812016-02-02 17:17:23 -070015761TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015762 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015763 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15764 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015765 // The image format check comes 2nd in validation so we trigger it first,
15766 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015767 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015768
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15770 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015771
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015772 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015773
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015774 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015775 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15776 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015777
15778 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015779 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15780 ds_pool_ci.pNext = NULL;
15781 ds_pool_ci.maxSets = 1;
15782 ds_pool_ci.poolSizeCount = 1;
15783 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015784
15785 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015786 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015787 ASSERT_VK_SUCCESS(err);
15788
15789 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015790 dsl_binding.binding = 0;
15791 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15792 dsl_binding.descriptorCount = 1;
15793 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15794 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015795
15796 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015797 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15798 ds_layout_ci.pNext = NULL;
15799 ds_layout_ci.bindingCount = 1;
15800 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015801 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015802 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015803 ASSERT_VK_SUCCESS(err);
15804
15805 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015806 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015807 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015808 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015809 alloc_info.descriptorPool = ds_pool;
15810 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015811 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015812 ASSERT_VK_SUCCESS(err);
15813
Karl Schultz6addd812016-02-02 17:17:23 -070015814 VkImage image_bad;
15815 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015816 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015817 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015818 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015819 const int32_t tex_width = 32;
15820 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015821
15822 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015823 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15824 image_create_info.pNext = NULL;
15825 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15826 image_create_info.format = tex_format_bad;
15827 image_create_info.extent.width = tex_width;
15828 image_create_info.extent.height = tex_height;
15829 image_create_info.extent.depth = 1;
15830 image_create_info.mipLevels = 1;
15831 image_create_info.arrayLayers = 1;
15832 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15833 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015834 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015835 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015837 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015838 ASSERT_VK_SUCCESS(err);
15839 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015840 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15841 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015842 ASSERT_VK_SUCCESS(err);
15843
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015844 // ---Bind image memory---
15845 VkMemoryRequirements img_mem_reqs;
15846 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15847 VkMemoryAllocateInfo image_alloc_info = {};
15848 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15849 image_alloc_info.pNext = NULL;
15850 image_alloc_info.memoryTypeIndex = 0;
15851 image_alloc_info.allocationSize = img_mem_reqs.size;
15852 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &image_alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15853 ASSERT_TRUE(pass);
15854 VkDeviceMemory mem;
15855 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15856 ASSERT_VK_SUCCESS(err);
15857 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15858 ASSERT_VK_SUCCESS(err);
15859 // -----------------------
15860
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015861 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015862 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015863 image_view_create_info.image = image_bad;
15864 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15865 image_view_create_info.format = tex_format_bad;
15866 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15867 image_view_create_info.subresourceRange.baseMipLevel = 0;
15868 image_view_create_info.subresourceRange.layerCount = 1;
15869 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015870 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015871
15872 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015873 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015874
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015875 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015876
Chia-I Wuf7458c52015-10-26 21:10:41 +080015877 vkDestroyImage(m_device->device(), image_bad, NULL);
15878 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015879 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15880 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015881
15882 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015883}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015884
15885TEST_F(VkLayerTest, ClearImageErrors) {
15886 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15887 "ClearDepthStencilImage with a color image.");
15888
15889 ASSERT_NO_FATAL_FAILURE(InitState());
15890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15891
Tony Barbour552f6c02016-12-21 14:34:07 -070015892 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015893
15894 // Color image
15895 VkClearColorValue clear_color;
15896 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15897 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15898 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15899 const int32_t img_width = 32;
15900 const int32_t img_height = 32;
15901 VkImageCreateInfo image_create_info = {};
15902 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15903 image_create_info.pNext = NULL;
15904 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15905 image_create_info.format = color_format;
15906 image_create_info.extent.width = img_width;
15907 image_create_info.extent.height = img_height;
15908 image_create_info.extent.depth = 1;
15909 image_create_info.mipLevels = 1;
15910 image_create_info.arrayLayers = 1;
15911 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15912 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15913 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15914
15915 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015916 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015917
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015918 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015919
15920 // Depth/Stencil image
15921 VkClearDepthStencilValue clear_value = {0};
15922 reqs = 0; // don't need HOST_VISIBLE DS image
15923 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15924 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15925 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15926 ds_image_create_info.extent.width = 64;
15927 ds_image_create_info.extent.height = 64;
15928 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015929 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 -060015930
15931 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015932 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015934 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 -060015935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015937
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015938 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015939 &color_range);
15940
15941 m_errorMonitor->VerifyFound();
15942
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15944 "image created without "
15945 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015946
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015947 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015948 &color_range);
15949
15950 m_errorMonitor->VerifyFound();
15951
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015952 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15954 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015955
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015956 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015957 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015958
15959 m_errorMonitor->VerifyFound();
15960}
Tobin Ehliscde08892015-09-22 10:11:37 -060015961#endif // IMAGE_TESTS
15962
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015963
15964// WSI Enabled Tests
15965//
Chris Forbes09368e42016-10-13 11:59:22 +130015966#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015967TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15968
15969#if defined(VK_USE_PLATFORM_XCB_KHR)
15970 VkSurfaceKHR surface = VK_NULL_HANDLE;
15971
15972 VkResult err;
15973 bool pass;
15974 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15975 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15976 // uint32_t swapchain_image_count = 0;
15977 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15978 // uint32_t image_index = 0;
15979 // VkPresentInfoKHR present_info = {};
15980
15981 ASSERT_NO_FATAL_FAILURE(InitState());
15982
15983 // Use the create function from one of the VK_KHR_*_surface extension in
15984 // order to create a surface, testing all known errors in the process,
15985 // before successfully creating a surface:
15986 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15988 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15989 pass = (err != VK_SUCCESS);
15990 ASSERT_TRUE(pass);
15991 m_errorMonitor->VerifyFound();
15992
15993 // Next, try to create a surface with the wrong
15994 // VkXcbSurfaceCreateInfoKHR::sType:
15995 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15996 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15998 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
15999 pass = (err != VK_SUCCESS);
16000 ASSERT_TRUE(pass);
16001 m_errorMonitor->VerifyFound();
16002
16003 // Create a native window, and then correctly create a surface:
16004 xcb_connection_t *connection;
16005 xcb_screen_t *screen;
16006 xcb_window_t xcb_window;
16007 xcb_intern_atom_reply_t *atom_wm_delete_window;
16008
16009 const xcb_setup_t *setup;
16010 xcb_screen_iterator_t iter;
16011 int scr;
16012 uint32_t value_mask, value_list[32];
16013 int width = 1;
16014 int height = 1;
16015
16016 connection = xcb_connect(NULL, &scr);
16017 ASSERT_TRUE(connection != NULL);
16018 setup = xcb_get_setup(connection);
16019 iter = xcb_setup_roots_iterator(setup);
16020 while (scr-- > 0)
16021 xcb_screen_next(&iter);
16022 screen = iter.data;
16023
16024 xcb_window = xcb_generate_id(connection);
16025
16026 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16027 value_list[0] = screen->black_pixel;
16028 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16029
16030 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16031 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16032
16033 /* Magic code that will send notification when window is destroyed */
16034 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16035 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16036
16037 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16038 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16039 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16040 free(reply);
16041
16042 xcb_map_window(connection, xcb_window);
16043
16044 // Force the x/y coordinates to 100,100 results are identical in consecutive
16045 // runs
16046 const uint32_t coords[] = { 100, 100 };
16047 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16048
16049 // Finally, try to correctly create a surface:
16050 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16051 xcb_create_info.pNext = NULL;
16052 xcb_create_info.flags = 0;
16053 xcb_create_info.connection = connection;
16054 xcb_create_info.window = xcb_window;
16055 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16056 pass = (err == VK_SUCCESS);
16057 ASSERT_TRUE(pass);
16058
16059 // Check if surface supports presentation:
16060
16061 // 1st, do so without having queried the queue families:
16062 VkBool32 supported = false;
16063 // TODO: Get the following error to come out:
16064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16065 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16066 "function");
16067 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16068 pass = (err != VK_SUCCESS);
16069 // ASSERT_TRUE(pass);
16070 // m_errorMonitor->VerifyFound();
16071
16072 // Next, query a queue family index that's too large:
16073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16074 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16075 pass = (err != VK_SUCCESS);
16076 ASSERT_TRUE(pass);
16077 m_errorMonitor->VerifyFound();
16078
16079 // Finally, do so correctly:
16080 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16081 // SUPPORTED
16082 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16083 pass = (err == VK_SUCCESS);
16084 ASSERT_TRUE(pass);
16085
16086 // Before proceeding, try to create a swapchain without having called
16087 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16088 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16089 swapchain_create_info.pNext = NULL;
16090 swapchain_create_info.flags = 0;
16091 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16092 swapchain_create_info.surface = surface;
16093 swapchain_create_info.imageArrayLayers = 1;
16094 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16095 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16097 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16098 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16099 pass = (err != VK_SUCCESS);
16100 ASSERT_TRUE(pass);
16101 m_errorMonitor->VerifyFound();
16102
16103 // Get the surface capabilities:
16104 VkSurfaceCapabilitiesKHR surface_capabilities;
16105
16106 // Do so correctly (only error logged by this entrypoint is if the
16107 // extension isn't enabled):
16108 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16109 pass = (err == VK_SUCCESS);
16110 ASSERT_TRUE(pass);
16111
16112 // Get the surface formats:
16113 uint32_t surface_format_count;
16114
16115 // First, try without a pointer to surface_format_count:
16116 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16117 "specified as NULL");
16118 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16119 pass = (err == VK_SUCCESS);
16120 ASSERT_TRUE(pass);
16121 m_errorMonitor->VerifyFound();
16122
16123 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16124 // correctly done a 1st try (to get the count):
16125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16126 surface_format_count = 0;
16127 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16128 pass = (err == VK_SUCCESS);
16129 ASSERT_TRUE(pass);
16130 m_errorMonitor->VerifyFound();
16131
16132 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16133 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16134 pass = (err == VK_SUCCESS);
16135 ASSERT_TRUE(pass);
16136
16137 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16138 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16139
16140 // Next, do a 2nd try with surface_format_count being set too high:
16141 surface_format_count += 5;
16142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16143 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16144 pass = (err == VK_SUCCESS);
16145 ASSERT_TRUE(pass);
16146 m_errorMonitor->VerifyFound();
16147
16148 // Finally, do a correct 1st and 2nd try:
16149 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16150 pass = (err == VK_SUCCESS);
16151 ASSERT_TRUE(pass);
16152 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16153 pass = (err == VK_SUCCESS);
16154 ASSERT_TRUE(pass);
16155
16156 // Get the surface present modes:
16157 uint32_t surface_present_mode_count;
16158
16159 // First, try without a pointer to surface_format_count:
16160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16161 "specified as NULL");
16162
16163 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16164 pass = (err == VK_SUCCESS);
16165 ASSERT_TRUE(pass);
16166 m_errorMonitor->VerifyFound();
16167
16168 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16169 // correctly done a 1st try (to get the count):
16170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16171 surface_present_mode_count = 0;
16172 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16173 (VkPresentModeKHR *)&surface_present_mode_count);
16174 pass = (err == VK_SUCCESS);
16175 ASSERT_TRUE(pass);
16176 m_errorMonitor->VerifyFound();
16177
16178 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16179 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16180 pass = (err == VK_SUCCESS);
16181 ASSERT_TRUE(pass);
16182
16183 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16184 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16185
16186 // Next, do a 2nd try with surface_format_count being set too high:
16187 surface_present_mode_count += 5;
16188 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16189 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16190 pass = (err == VK_SUCCESS);
16191 ASSERT_TRUE(pass);
16192 m_errorMonitor->VerifyFound();
16193
16194 // Finally, do a correct 1st and 2nd try:
16195 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16196 pass = (err == VK_SUCCESS);
16197 ASSERT_TRUE(pass);
16198 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16199 pass = (err == VK_SUCCESS);
16200 ASSERT_TRUE(pass);
16201
16202 // Create a swapchain:
16203
16204 // First, try without a pointer to swapchain_create_info:
16205 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16206 "specified as NULL");
16207
16208 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16209 pass = (err != VK_SUCCESS);
16210 ASSERT_TRUE(pass);
16211 m_errorMonitor->VerifyFound();
16212
16213 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16214 // sType:
16215 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16217
16218 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16219 pass = (err != VK_SUCCESS);
16220 ASSERT_TRUE(pass);
16221 m_errorMonitor->VerifyFound();
16222
16223 // Next, call with a NULL swapchain pointer:
16224 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16225 swapchain_create_info.pNext = NULL;
16226 swapchain_create_info.flags = 0;
16227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16228 "specified as NULL");
16229
16230 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16231 pass = (err != VK_SUCCESS);
16232 ASSERT_TRUE(pass);
16233 m_errorMonitor->VerifyFound();
16234
16235 // TODO: Enhance swapchain layer so that
16236 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16237
16238 // Next, call with a queue family index that's too large:
16239 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16240 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16241 swapchain_create_info.queueFamilyIndexCount = 2;
16242 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16244 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16245 pass = (err != VK_SUCCESS);
16246 ASSERT_TRUE(pass);
16247 m_errorMonitor->VerifyFound();
16248
16249 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16250 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16251 swapchain_create_info.queueFamilyIndexCount = 1;
16252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16253 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16254 "pCreateInfo->pQueueFamilyIndices).");
16255 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16256 pass = (err != VK_SUCCESS);
16257 ASSERT_TRUE(pass);
16258 m_errorMonitor->VerifyFound();
16259
16260 // Next, call with an invalid imageSharingMode:
16261 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16262 swapchain_create_info.queueFamilyIndexCount = 1;
16263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16264 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16265 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16266 pass = (err != VK_SUCCESS);
16267 ASSERT_TRUE(pass);
16268 m_errorMonitor->VerifyFound();
16269 // Fix for the future:
16270 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16271 // SUPPORTED
16272 swapchain_create_info.queueFamilyIndexCount = 0;
16273 queueFamilyIndex[0] = 0;
16274 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16275
16276 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16277 // Get the images from a swapchain:
16278 // Acquire an image from a swapchain:
16279 // Present an image to a swapchain:
16280 // Destroy the swapchain:
16281
16282 // TODOs:
16283 //
16284 // - Try destroying the device without first destroying the swapchain
16285 //
16286 // - Try destroying the device without first destroying the surface
16287 //
16288 // - Try destroying the surface without first destroying the swapchain
16289
16290 // Destroy the surface:
16291 vkDestroySurfaceKHR(instance(), surface, NULL);
16292
16293 // Tear down the window:
16294 xcb_destroy_window(connection, xcb_window);
16295 xcb_disconnect(connection);
16296
16297#else // VK_USE_PLATFORM_XCB_KHR
16298 return;
16299#endif // VK_USE_PLATFORM_XCB_KHR
16300}
Chris Forbes09368e42016-10-13 11:59:22 +130016301#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016302
16303//
16304// POSITIVE VALIDATION TESTS
16305//
16306// These tests do not expect to encounter ANY validation errors pass only if this is true
16307
Tobin Ehlise0006882016-11-03 10:14:28 -060016308TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16309 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16310 "by a transition in the primary.");
16311 VkResult err;
16312 m_errorMonitor->ExpectSuccess();
16313 ASSERT_NO_FATAL_FAILURE(InitState());
16314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16315 // Allocate a secondary and primary cmd buffer
16316 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16317 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16318 command_buffer_allocate_info.commandPool = m_commandPool;
16319 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16320 command_buffer_allocate_info.commandBufferCount = 1;
16321
16322 VkCommandBuffer secondary_command_buffer;
16323 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16324 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16325 VkCommandBuffer primary_command_buffer;
16326 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16327 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16328 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16329 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16330 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16331 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16332 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16333
16334 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16335 ASSERT_VK_SUCCESS(err);
16336 VkImageObj image(m_device);
16337 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16338 ASSERT_TRUE(image.initialized());
16339 VkImageMemoryBarrier img_barrier = {};
16340 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16341 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16342 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16343 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16344 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16345 img_barrier.image = image.handle();
16346 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16347 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16348 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16349 img_barrier.subresourceRange.baseArrayLayer = 0;
16350 img_barrier.subresourceRange.baseMipLevel = 0;
16351 img_barrier.subresourceRange.layerCount = 1;
16352 img_barrier.subresourceRange.levelCount = 1;
16353 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16354 0, nullptr, 1, &img_barrier);
16355 err = vkEndCommandBuffer(secondary_command_buffer);
16356 ASSERT_VK_SUCCESS(err);
16357
16358 // Now update primary cmd buffer to execute secondary and transitions image
16359 command_buffer_begin_info.pInheritanceInfo = nullptr;
16360 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16361 ASSERT_VK_SUCCESS(err);
16362 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16363 VkImageMemoryBarrier img_barrier2 = {};
16364 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16365 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16366 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16367 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16368 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16369 img_barrier2.image = image.handle();
16370 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16371 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16372 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16373 img_barrier2.subresourceRange.baseArrayLayer = 0;
16374 img_barrier2.subresourceRange.baseMipLevel = 0;
16375 img_barrier2.subresourceRange.layerCount = 1;
16376 img_barrier2.subresourceRange.levelCount = 1;
16377 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16378 nullptr, 1, &img_barrier2);
16379 err = vkEndCommandBuffer(primary_command_buffer);
16380 ASSERT_VK_SUCCESS(err);
16381 VkSubmitInfo submit_info = {};
16382 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16383 submit_info.commandBufferCount = 1;
16384 submit_info.pCommandBuffers = &primary_command_buffer;
16385 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16386 ASSERT_VK_SUCCESS(err);
16387 m_errorMonitor->VerifyNotFound();
16388 err = vkDeviceWaitIdle(m_device->device());
16389 ASSERT_VK_SUCCESS(err);
16390 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16391 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16392}
16393
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016394// This is a positive test. No failures are expected.
16395TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16396 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16397 "is ignoring VkWriteDescriptorSet members that are not "
16398 "related to the descriptor type specified by "
16399 "VkWriteDescriptorSet::descriptorType. Correct "
16400 "validation behavior will result in the test running to "
16401 "completion without validation errors.");
16402
16403 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16404
16405 ASSERT_NO_FATAL_FAILURE(InitState());
16406
16407 // Image Case
16408 {
16409 m_errorMonitor->ExpectSuccess();
16410
16411 VkImage image;
16412 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16413 const int32_t tex_width = 32;
16414 const int32_t tex_height = 32;
16415 VkImageCreateInfo image_create_info = {};
16416 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16417 image_create_info.pNext = NULL;
16418 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16419 image_create_info.format = tex_format;
16420 image_create_info.extent.width = tex_width;
16421 image_create_info.extent.height = tex_height;
16422 image_create_info.extent.depth = 1;
16423 image_create_info.mipLevels = 1;
16424 image_create_info.arrayLayers = 1;
16425 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16426 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16427 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16428 image_create_info.flags = 0;
16429 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16430 ASSERT_VK_SUCCESS(err);
16431
16432 VkMemoryRequirements memory_reqs;
16433 VkDeviceMemory image_memory;
16434 bool pass;
16435 VkMemoryAllocateInfo memory_info = {};
16436 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16437 memory_info.pNext = NULL;
16438 memory_info.allocationSize = 0;
16439 memory_info.memoryTypeIndex = 0;
16440 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16441 memory_info.allocationSize = memory_reqs.size;
16442 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16443 ASSERT_TRUE(pass);
16444 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16445 ASSERT_VK_SUCCESS(err);
16446 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16447 ASSERT_VK_SUCCESS(err);
16448
16449 VkImageViewCreateInfo image_view_create_info = {};
16450 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16451 image_view_create_info.image = image;
16452 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16453 image_view_create_info.format = tex_format;
16454 image_view_create_info.subresourceRange.layerCount = 1;
16455 image_view_create_info.subresourceRange.baseMipLevel = 0;
16456 image_view_create_info.subresourceRange.levelCount = 1;
16457 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16458
16459 VkImageView view;
16460 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16461 ASSERT_VK_SUCCESS(err);
16462
16463 VkDescriptorPoolSize ds_type_count = {};
16464 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16465 ds_type_count.descriptorCount = 1;
16466
16467 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16468 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16469 ds_pool_ci.pNext = NULL;
16470 ds_pool_ci.maxSets = 1;
16471 ds_pool_ci.poolSizeCount = 1;
16472 ds_pool_ci.pPoolSizes = &ds_type_count;
16473
16474 VkDescriptorPool ds_pool;
16475 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16476 ASSERT_VK_SUCCESS(err);
16477
16478 VkDescriptorSetLayoutBinding dsl_binding = {};
16479 dsl_binding.binding = 0;
16480 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16481 dsl_binding.descriptorCount = 1;
16482 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16483 dsl_binding.pImmutableSamplers = NULL;
16484
16485 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16486 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16487 ds_layout_ci.pNext = NULL;
16488 ds_layout_ci.bindingCount = 1;
16489 ds_layout_ci.pBindings = &dsl_binding;
16490 VkDescriptorSetLayout ds_layout;
16491 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16492 ASSERT_VK_SUCCESS(err);
16493
16494 VkDescriptorSet descriptor_set;
16495 VkDescriptorSetAllocateInfo alloc_info = {};
16496 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16497 alloc_info.descriptorSetCount = 1;
16498 alloc_info.descriptorPool = ds_pool;
16499 alloc_info.pSetLayouts = &ds_layout;
16500 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16501 ASSERT_VK_SUCCESS(err);
16502
16503 VkDescriptorImageInfo image_info = {};
16504 image_info.imageView = view;
16505 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16506
16507 VkWriteDescriptorSet descriptor_write;
16508 memset(&descriptor_write, 0, sizeof(descriptor_write));
16509 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16510 descriptor_write.dstSet = descriptor_set;
16511 descriptor_write.dstBinding = 0;
16512 descriptor_write.descriptorCount = 1;
16513 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16514 descriptor_write.pImageInfo = &image_info;
16515
16516 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16517 // be
16518 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16519 // This will most likely produce a crash if the parameter_validation
16520 // layer
16521 // does not correctly ignore pBufferInfo.
16522 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16523 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16524
16525 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16526
16527 m_errorMonitor->VerifyNotFound();
16528
16529 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16530 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16531 vkDestroyImageView(m_device->device(), view, NULL);
16532 vkDestroyImage(m_device->device(), image, NULL);
16533 vkFreeMemory(m_device->device(), image_memory, NULL);
16534 }
16535
16536 // Buffer Case
16537 {
16538 m_errorMonitor->ExpectSuccess();
16539
16540 VkBuffer buffer;
16541 uint32_t queue_family_index = 0;
16542 VkBufferCreateInfo buffer_create_info = {};
16543 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16544 buffer_create_info.size = 1024;
16545 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16546 buffer_create_info.queueFamilyIndexCount = 1;
16547 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16548
16549 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16550 ASSERT_VK_SUCCESS(err);
16551
16552 VkMemoryRequirements memory_reqs;
16553 VkDeviceMemory buffer_memory;
16554 bool pass;
16555 VkMemoryAllocateInfo memory_info = {};
16556 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16557 memory_info.pNext = NULL;
16558 memory_info.allocationSize = 0;
16559 memory_info.memoryTypeIndex = 0;
16560
16561 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16562 memory_info.allocationSize = memory_reqs.size;
16563 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16564 ASSERT_TRUE(pass);
16565
16566 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16567 ASSERT_VK_SUCCESS(err);
16568 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16569 ASSERT_VK_SUCCESS(err);
16570
16571 VkDescriptorPoolSize ds_type_count = {};
16572 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16573 ds_type_count.descriptorCount = 1;
16574
16575 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16576 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16577 ds_pool_ci.pNext = NULL;
16578 ds_pool_ci.maxSets = 1;
16579 ds_pool_ci.poolSizeCount = 1;
16580 ds_pool_ci.pPoolSizes = &ds_type_count;
16581
16582 VkDescriptorPool ds_pool;
16583 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16584 ASSERT_VK_SUCCESS(err);
16585
16586 VkDescriptorSetLayoutBinding dsl_binding = {};
16587 dsl_binding.binding = 0;
16588 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16589 dsl_binding.descriptorCount = 1;
16590 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16591 dsl_binding.pImmutableSamplers = NULL;
16592
16593 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16594 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16595 ds_layout_ci.pNext = NULL;
16596 ds_layout_ci.bindingCount = 1;
16597 ds_layout_ci.pBindings = &dsl_binding;
16598 VkDescriptorSetLayout ds_layout;
16599 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16600 ASSERT_VK_SUCCESS(err);
16601
16602 VkDescriptorSet descriptor_set;
16603 VkDescriptorSetAllocateInfo alloc_info = {};
16604 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16605 alloc_info.descriptorSetCount = 1;
16606 alloc_info.descriptorPool = ds_pool;
16607 alloc_info.pSetLayouts = &ds_layout;
16608 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16609 ASSERT_VK_SUCCESS(err);
16610
16611 VkDescriptorBufferInfo buffer_info = {};
16612 buffer_info.buffer = buffer;
16613 buffer_info.offset = 0;
16614 buffer_info.range = 1024;
16615
16616 VkWriteDescriptorSet descriptor_write;
16617 memset(&descriptor_write, 0, sizeof(descriptor_write));
16618 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16619 descriptor_write.dstSet = descriptor_set;
16620 descriptor_write.dstBinding = 0;
16621 descriptor_write.descriptorCount = 1;
16622 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16623 descriptor_write.pBufferInfo = &buffer_info;
16624
16625 // Set pImageInfo and pTexelBufferView to invalid values, which should
16626 // be
16627 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16628 // This will most likely produce a crash if the parameter_validation
16629 // layer
16630 // does not correctly ignore pImageInfo.
16631 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16632 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16633
16634 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16635
16636 m_errorMonitor->VerifyNotFound();
16637
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016638 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16639 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16640 vkDestroyBuffer(m_device->device(), buffer, NULL);
16641 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16642 }
16643
16644 // Texel Buffer Case
16645 {
16646 m_errorMonitor->ExpectSuccess();
16647
16648 VkBuffer buffer;
16649 uint32_t queue_family_index = 0;
16650 VkBufferCreateInfo buffer_create_info = {};
16651 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16652 buffer_create_info.size = 1024;
16653 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16654 buffer_create_info.queueFamilyIndexCount = 1;
16655 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16656
16657 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16658 ASSERT_VK_SUCCESS(err);
16659
16660 VkMemoryRequirements memory_reqs;
16661 VkDeviceMemory buffer_memory;
16662 bool pass;
16663 VkMemoryAllocateInfo memory_info = {};
16664 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16665 memory_info.pNext = NULL;
16666 memory_info.allocationSize = 0;
16667 memory_info.memoryTypeIndex = 0;
16668
16669 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16670 memory_info.allocationSize = memory_reqs.size;
16671 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16672 ASSERT_TRUE(pass);
16673
16674 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16675 ASSERT_VK_SUCCESS(err);
16676 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16677 ASSERT_VK_SUCCESS(err);
16678
16679 VkBufferViewCreateInfo buff_view_ci = {};
16680 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16681 buff_view_ci.buffer = buffer;
16682 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16683 buff_view_ci.range = VK_WHOLE_SIZE;
16684 VkBufferView buffer_view;
16685 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16686
16687 VkDescriptorPoolSize ds_type_count = {};
16688 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16689 ds_type_count.descriptorCount = 1;
16690
16691 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16692 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16693 ds_pool_ci.pNext = NULL;
16694 ds_pool_ci.maxSets = 1;
16695 ds_pool_ci.poolSizeCount = 1;
16696 ds_pool_ci.pPoolSizes = &ds_type_count;
16697
16698 VkDescriptorPool ds_pool;
16699 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16700 ASSERT_VK_SUCCESS(err);
16701
16702 VkDescriptorSetLayoutBinding dsl_binding = {};
16703 dsl_binding.binding = 0;
16704 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16705 dsl_binding.descriptorCount = 1;
16706 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16707 dsl_binding.pImmutableSamplers = NULL;
16708
16709 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16710 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16711 ds_layout_ci.pNext = NULL;
16712 ds_layout_ci.bindingCount = 1;
16713 ds_layout_ci.pBindings = &dsl_binding;
16714 VkDescriptorSetLayout ds_layout;
16715 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16716 ASSERT_VK_SUCCESS(err);
16717
16718 VkDescriptorSet descriptor_set;
16719 VkDescriptorSetAllocateInfo alloc_info = {};
16720 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16721 alloc_info.descriptorSetCount = 1;
16722 alloc_info.descriptorPool = ds_pool;
16723 alloc_info.pSetLayouts = &ds_layout;
16724 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16725 ASSERT_VK_SUCCESS(err);
16726
16727 VkWriteDescriptorSet descriptor_write;
16728 memset(&descriptor_write, 0, sizeof(descriptor_write));
16729 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16730 descriptor_write.dstSet = descriptor_set;
16731 descriptor_write.dstBinding = 0;
16732 descriptor_write.descriptorCount = 1;
16733 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16734 descriptor_write.pTexelBufferView = &buffer_view;
16735
16736 // Set pImageInfo and pBufferInfo to invalid values, which should be
16737 // ignored for descriptorType ==
16738 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16739 // This will most likely produce a crash if the parameter_validation
16740 // layer
16741 // does not correctly ignore pImageInfo and pBufferInfo.
16742 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16743 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16744
16745 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16746
16747 m_errorMonitor->VerifyNotFound();
16748
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016749 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16750 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16751 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16752 vkDestroyBuffer(m_device->device(), buffer, NULL);
16753 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16754 }
16755}
16756
Tobin Ehlisf7428442016-10-25 07:58:24 -060016757TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16758 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16759
16760 ASSERT_NO_FATAL_FAILURE(InitState());
16761 // Create layout where two binding #s are "1"
16762 static const uint32_t NUM_BINDINGS = 3;
16763 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16764 dsl_binding[0].binding = 1;
16765 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16766 dsl_binding[0].descriptorCount = 1;
16767 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16768 dsl_binding[0].pImmutableSamplers = NULL;
16769 dsl_binding[1].binding = 0;
16770 dsl_binding[1].descriptorCount = 1;
16771 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16772 dsl_binding[1].descriptorCount = 1;
16773 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16774 dsl_binding[1].pImmutableSamplers = NULL;
16775 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16776 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16777 dsl_binding[2].descriptorCount = 1;
16778 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16779 dsl_binding[2].pImmutableSamplers = NULL;
16780
16781 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16782 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16783 ds_layout_ci.pNext = NULL;
16784 ds_layout_ci.bindingCount = NUM_BINDINGS;
16785 ds_layout_ci.pBindings = dsl_binding;
16786 VkDescriptorSetLayout ds_layout;
16787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16788 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16789 m_errorMonitor->VerifyFound();
16790}
16791
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016792TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016793 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16794
16795 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016796
Tony Barbour552f6c02016-12-21 14:34:07 -070016797 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016798
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016799 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16800
16801 {
16802 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16803 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16804 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16805 m_errorMonitor->VerifyFound();
16806 }
16807
16808 {
16809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16810 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16811 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16812 m_errorMonitor->VerifyFound();
16813 }
16814
16815 {
16816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16817 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16818 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16819 m_errorMonitor->VerifyFound();
16820 }
16821
16822 {
16823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16824 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16825 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16826 m_errorMonitor->VerifyFound();
16827 }
16828
16829 {
16830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16831 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16832 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16833 m_errorMonitor->VerifyFound();
16834 }
16835
16836 {
16837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16838 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16839 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16840 m_errorMonitor->VerifyFound();
16841 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016842
16843 {
16844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16845 VkRect2D scissor = {{-1, 0}, {16, 16}};
16846 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16847 m_errorMonitor->VerifyFound();
16848 }
16849
16850 {
16851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16852 VkRect2D scissor = {{0, -2}, {16, 16}};
16853 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16854 m_errorMonitor->VerifyFound();
16855 }
16856
16857 {
16858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16859 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16860 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16861 m_errorMonitor->VerifyFound();
16862 }
16863
16864 {
16865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16866 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16867 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16868 m_errorMonitor->VerifyFound();
16869 }
16870
Tony Barbour552f6c02016-12-21 14:34:07 -070016871 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016872}
16873
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016874// This is a positive test. No failures are expected.
16875TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16876 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16877 VkResult err;
16878
16879 ASSERT_NO_FATAL_FAILURE(InitState());
16880 m_errorMonitor->ExpectSuccess();
16881 VkDescriptorPoolSize ds_type_count = {};
16882 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16883 ds_type_count.descriptorCount = 2;
16884
16885 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16886 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16887 ds_pool_ci.pNext = NULL;
16888 ds_pool_ci.maxSets = 1;
16889 ds_pool_ci.poolSizeCount = 1;
16890 ds_pool_ci.pPoolSizes = &ds_type_count;
16891
16892 VkDescriptorPool ds_pool;
16893 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16894 ASSERT_VK_SUCCESS(err);
16895
16896 // Create layout with two uniform buffer descriptors w/ empty binding between them
16897 static const uint32_t NUM_BINDINGS = 3;
16898 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16899 dsl_binding[0].binding = 0;
16900 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16901 dsl_binding[0].descriptorCount = 1;
16902 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16903 dsl_binding[0].pImmutableSamplers = NULL;
16904 dsl_binding[1].binding = 1;
16905 dsl_binding[1].descriptorCount = 0; // empty binding
16906 dsl_binding[2].binding = 2;
16907 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16908 dsl_binding[2].descriptorCount = 1;
16909 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16910 dsl_binding[2].pImmutableSamplers = NULL;
16911
16912 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16913 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16914 ds_layout_ci.pNext = NULL;
16915 ds_layout_ci.bindingCount = NUM_BINDINGS;
16916 ds_layout_ci.pBindings = dsl_binding;
16917 VkDescriptorSetLayout ds_layout;
16918 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16919 ASSERT_VK_SUCCESS(err);
16920
16921 VkDescriptorSet descriptor_set = {};
16922 VkDescriptorSetAllocateInfo alloc_info = {};
16923 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16924 alloc_info.descriptorSetCount = 1;
16925 alloc_info.descriptorPool = ds_pool;
16926 alloc_info.pSetLayouts = &ds_layout;
16927 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16928 ASSERT_VK_SUCCESS(err);
16929
16930 // Create a buffer to be used for update
16931 VkBufferCreateInfo buff_ci = {};
16932 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16933 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16934 buff_ci.size = 256;
16935 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16936 VkBuffer buffer;
16937 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16938 ASSERT_VK_SUCCESS(err);
16939 // Have to bind memory to buffer before descriptor update
16940 VkMemoryAllocateInfo mem_alloc = {};
16941 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16942 mem_alloc.pNext = NULL;
16943 mem_alloc.allocationSize = 512; // one allocation for both buffers
16944 mem_alloc.memoryTypeIndex = 0;
16945
16946 VkMemoryRequirements mem_reqs;
16947 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16948 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16949 if (!pass) {
16950 vkDestroyBuffer(m_device->device(), buffer, NULL);
16951 return;
16952 }
16953
16954 VkDeviceMemory mem;
16955 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16956 ASSERT_VK_SUCCESS(err);
16957 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16958 ASSERT_VK_SUCCESS(err);
16959
16960 // Only update the descriptor at binding 2
16961 VkDescriptorBufferInfo buff_info = {};
16962 buff_info.buffer = buffer;
16963 buff_info.offset = 0;
16964 buff_info.range = VK_WHOLE_SIZE;
16965 VkWriteDescriptorSet descriptor_write = {};
16966 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16967 descriptor_write.dstBinding = 2;
16968 descriptor_write.descriptorCount = 1;
16969 descriptor_write.pTexelBufferView = nullptr;
16970 descriptor_write.pBufferInfo = &buff_info;
16971 descriptor_write.pImageInfo = nullptr;
16972 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16973 descriptor_write.dstSet = descriptor_set;
16974
16975 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16976
16977 m_errorMonitor->VerifyNotFound();
16978 // Cleanup
16979 vkFreeMemory(m_device->device(), mem, NULL);
16980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16981 vkDestroyBuffer(m_device->device(), buffer, NULL);
16982 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16983}
16984
16985// This is a positive test. No failures are expected.
16986TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16987 VkResult err;
16988 bool pass;
16989
16990 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16991 "the buffer, create an image, and bind the same memory to "
16992 "it");
16993
16994 m_errorMonitor->ExpectSuccess();
16995
16996 ASSERT_NO_FATAL_FAILURE(InitState());
16997
16998 VkBuffer buffer;
16999 VkImage image;
17000 VkDeviceMemory mem;
17001 VkMemoryRequirements mem_reqs;
17002
17003 VkBufferCreateInfo buf_info = {};
17004 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17005 buf_info.pNext = NULL;
17006 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17007 buf_info.size = 256;
17008 buf_info.queueFamilyIndexCount = 0;
17009 buf_info.pQueueFamilyIndices = NULL;
17010 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17011 buf_info.flags = 0;
17012 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17013 ASSERT_VK_SUCCESS(err);
17014
17015 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17016
17017 VkMemoryAllocateInfo alloc_info = {};
17018 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17019 alloc_info.pNext = NULL;
17020 alloc_info.memoryTypeIndex = 0;
17021
17022 // Ensure memory is big enough for both bindings
17023 alloc_info.allocationSize = 0x10000;
17024
17025 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17026 if (!pass) {
17027 vkDestroyBuffer(m_device->device(), buffer, NULL);
17028 return;
17029 }
17030
17031 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17032 ASSERT_VK_SUCCESS(err);
17033
17034 uint8_t *pData;
17035 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17036 ASSERT_VK_SUCCESS(err);
17037
17038 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17039
17040 vkUnmapMemory(m_device->device(), mem);
17041
17042 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17043 ASSERT_VK_SUCCESS(err);
17044
17045 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17046 // memory. In fact, it was never used by the GPU.
17047 // Just be be sure, wait for idle.
17048 vkDestroyBuffer(m_device->device(), buffer, NULL);
17049 vkDeviceWaitIdle(m_device->device());
17050
Tobin Ehlis6a005702016-12-28 15:25:56 -070017051 // Use optimal as some platforms report linear support but then fail image creation
17052 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17053 VkImageFormatProperties image_format_properties;
17054 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17055 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17056 if (image_format_properties.maxExtent.width == 0) {
17057 printf("Image format not supported; skipped.\n");
17058 vkFreeMemory(m_device->device(), mem, NULL);
17059 return;
17060 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017061 VkImageCreateInfo image_create_info = {};
17062 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17063 image_create_info.pNext = NULL;
17064 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17065 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17066 image_create_info.extent.width = 64;
17067 image_create_info.extent.height = 64;
17068 image_create_info.extent.depth = 1;
17069 image_create_info.mipLevels = 1;
17070 image_create_info.arrayLayers = 1;
17071 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017072 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017073 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17074 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17075 image_create_info.queueFamilyIndexCount = 0;
17076 image_create_info.pQueueFamilyIndices = NULL;
17077 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17078 image_create_info.flags = 0;
17079
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017080 /* Create a mappable image. It will be the texture if linear images are ok
17081 * to be textures or it will be the staging image if they are not.
17082 */
17083 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17084 ASSERT_VK_SUCCESS(err);
17085
17086 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17087
Tobin Ehlis6a005702016-12-28 15:25:56 -070017088 VkMemoryAllocateInfo mem_alloc = {};
17089 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17090 mem_alloc.pNext = NULL;
17091 mem_alloc.allocationSize = 0;
17092 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017093 mem_alloc.allocationSize = mem_reqs.size;
17094
17095 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17096 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017097 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017098 vkDestroyImage(m_device->device(), image, NULL);
17099 return;
17100 }
17101
17102 // VALIDATION FAILURE:
17103 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17104 ASSERT_VK_SUCCESS(err);
17105
17106 m_errorMonitor->VerifyNotFound();
17107
17108 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017109 vkDestroyImage(m_device->device(), image, NULL);
17110}
17111
Tobin Ehlis953e8392016-11-17 10:54:13 -070017112TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17113 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17114 // We previously had a bug where dynamic offset of inactive bindings was still being used
17115 VkResult err;
17116 m_errorMonitor->ExpectSuccess();
17117
17118 ASSERT_NO_FATAL_FAILURE(InitState());
17119 ASSERT_NO_FATAL_FAILURE(InitViewport());
17120 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17121
17122 VkDescriptorPoolSize ds_type_count = {};
17123 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17124 ds_type_count.descriptorCount = 3;
17125
17126 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17127 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17128 ds_pool_ci.pNext = NULL;
17129 ds_pool_ci.maxSets = 1;
17130 ds_pool_ci.poolSizeCount = 1;
17131 ds_pool_ci.pPoolSizes = &ds_type_count;
17132
17133 VkDescriptorPool ds_pool;
17134 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17135 ASSERT_VK_SUCCESS(err);
17136
17137 const uint32_t BINDING_COUNT = 3;
17138 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017139 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017140 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17141 dsl_binding[0].descriptorCount = 1;
17142 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17143 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017144 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017145 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17146 dsl_binding[1].descriptorCount = 1;
17147 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17148 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017149 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017150 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17151 dsl_binding[2].descriptorCount = 1;
17152 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17153 dsl_binding[2].pImmutableSamplers = NULL;
17154
17155 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17156 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17157 ds_layout_ci.pNext = NULL;
17158 ds_layout_ci.bindingCount = BINDING_COUNT;
17159 ds_layout_ci.pBindings = dsl_binding;
17160 VkDescriptorSetLayout ds_layout;
17161 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17162 ASSERT_VK_SUCCESS(err);
17163
17164 VkDescriptorSet descriptor_set;
17165 VkDescriptorSetAllocateInfo alloc_info = {};
17166 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17167 alloc_info.descriptorSetCount = 1;
17168 alloc_info.descriptorPool = ds_pool;
17169 alloc_info.pSetLayouts = &ds_layout;
17170 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17171 ASSERT_VK_SUCCESS(err);
17172
17173 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17174 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17175 pipeline_layout_ci.pNext = NULL;
17176 pipeline_layout_ci.setLayoutCount = 1;
17177 pipeline_layout_ci.pSetLayouts = &ds_layout;
17178
17179 VkPipelineLayout pipeline_layout;
17180 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17181 ASSERT_VK_SUCCESS(err);
17182
17183 // Create two buffers to update the descriptors with
17184 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17185 uint32_t qfi = 0;
17186 VkBufferCreateInfo buffCI = {};
17187 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17188 buffCI.size = 2048;
17189 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17190 buffCI.queueFamilyIndexCount = 1;
17191 buffCI.pQueueFamilyIndices = &qfi;
17192
17193 VkBuffer dyub1;
17194 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17195 ASSERT_VK_SUCCESS(err);
17196 // buffer2
17197 buffCI.size = 1024;
17198 VkBuffer dyub2;
17199 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17200 ASSERT_VK_SUCCESS(err);
17201 // Allocate memory and bind to buffers
17202 VkMemoryAllocateInfo mem_alloc[2] = {};
17203 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17204 mem_alloc[0].pNext = NULL;
17205 mem_alloc[0].memoryTypeIndex = 0;
17206 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17207 mem_alloc[1].pNext = NULL;
17208 mem_alloc[1].memoryTypeIndex = 0;
17209
17210 VkMemoryRequirements mem_reqs1;
17211 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17212 VkMemoryRequirements mem_reqs2;
17213 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17214 mem_alloc[0].allocationSize = mem_reqs1.size;
17215 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17216 mem_alloc[1].allocationSize = mem_reqs2.size;
17217 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17218 if (!pass) {
17219 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17220 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17221 return;
17222 }
17223
17224 VkDeviceMemory mem1;
17225 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17226 ASSERT_VK_SUCCESS(err);
17227 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17228 ASSERT_VK_SUCCESS(err);
17229 VkDeviceMemory mem2;
17230 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17231 ASSERT_VK_SUCCESS(err);
17232 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17233 ASSERT_VK_SUCCESS(err);
17234 // Update descriptors
17235 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17236 buff_info[0].buffer = dyub1;
17237 buff_info[0].offset = 0;
17238 buff_info[0].range = 256;
17239 buff_info[1].buffer = dyub1;
17240 buff_info[1].offset = 256;
17241 buff_info[1].range = 512;
17242 buff_info[2].buffer = dyub2;
17243 buff_info[2].offset = 0;
17244 buff_info[2].range = 512;
17245
17246 VkWriteDescriptorSet descriptor_write;
17247 memset(&descriptor_write, 0, sizeof(descriptor_write));
17248 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17249 descriptor_write.dstSet = descriptor_set;
17250 descriptor_write.dstBinding = 0;
17251 descriptor_write.descriptorCount = BINDING_COUNT;
17252 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17253 descriptor_write.pBufferInfo = buff_info;
17254
17255 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17256
Tony Barbour552f6c02016-12-21 14:34:07 -070017257 m_commandBuffer->BeginCommandBuffer();
17258 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017259
17260 // Create PSO to be used for draw-time errors below
17261 char const *vsSource = "#version 450\n"
17262 "\n"
17263 "out gl_PerVertex { \n"
17264 " vec4 gl_Position;\n"
17265 "};\n"
17266 "void main(){\n"
17267 " gl_Position = vec4(1);\n"
17268 "}\n";
17269 char const *fsSource = "#version 450\n"
17270 "\n"
17271 "layout(location=0) out vec4 x;\n"
17272 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17273 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17274 "void main(){\n"
17275 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17276 "}\n";
17277 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17278 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17279 VkPipelineObj pipe(m_device);
17280 pipe.SetViewport(m_viewports);
17281 pipe.SetScissor(m_scissors);
17282 pipe.AddShader(&vs);
17283 pipe.AddShader(&fs);
17284 pipe.AddColorAttachment();
17285 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17286
17287 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17288 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17289 // we used to have a bug in this case.
17290 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17291 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17292 &descriptor_set, BINDING_COUNT, dyn_off);
17293 Draw(1, 0, 0, 0);
17294 m_errorMonitor->VerifyNotFound();
17295
17296 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17297 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17298 vkFreeMemory(m_device->device(), mem1, NULL);
17299 vkFreeMemory(m_device->device(), mem2, NULL);
17300
17301 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17302 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17303 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17304}
17305
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017306TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17307
17308 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17309 "mapping while using VK_WHOLE_SIZE does not cause access "
17310 "violations");
17311 VkResult err;
17312 uint8_t *pData;
17313 ASSERT_NO_FATAL_FAILURE(InitState());
17314
17315 VkDeviceMemory mem;
17316 VkMemoryRequirements mem_reqs;
17317 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017318 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017319 VkMemoryAllocateInfo alloc_info = {};
17320 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17321 alloc_info.pNext = NULL;
17322 alloc_info.memoryTypeIndex = 0;
17323
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017324 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017325 alloc_info.allocationSize = allocation_size;
17326
17327 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17328 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17329 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17330 if (!pass) {
17331 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17332 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17333 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17334 if (!pass) {
17335 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17336 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17337 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17338 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17339 if (!pass) {
17340 return;
17341 }
17342 }
17343 }
17344
17345 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17346 ASSERT_VK_SUCCESS(err);
17347
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017348 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017349 m_errorMonitor->ExpectSuccess();
17350 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17351 ASSERT_VK_SUCCESS(err);
17352 VkMappedMemoryRange mmr = {};
17353 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17354 mmr.memory = mem;
17355 mmr.offset = 0;
17356 mmr.size = VK_WHOLE_SIZE;
17357 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17358 ASSERT_VK_SUCCESS(err);
17359 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17360 ASSERT_VK_SUCCESS(err);
17361 m_errorMonitor->VerifyNotFound();
17362 vkUnmapMemory(m_device->device(), mem);
17363
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017364 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017365 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017366 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017367 ASSERT_VK_SUCCESS(err);
17368 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17369 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017370 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017371 mmr.size = VK_WHOLE_SIZE;
17372 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17373 ASSERT_VK_SUCCESS(err);
17374 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17375 ASSERT_VK_SUCCESS(err);
17376 m_errorMonitor->VerifyNotFound();
17377 vkUnmapMemory(m_device->device(), mem);
17378
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017379 // Map with offset and size
17380 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017381 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017382 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017383 ASSERT_VK_SUCCESS(err);
17384 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17385 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017386 mmr.offset = 4 * atom_size;
17387 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017388 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17389 ASSERT_VK_SUCCESS(err);
17390 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17391 ASSERT_VK_SUCCESS(err);
17392 m_errorMonitor->VerifyNotFound();
17393 vkUnmapMemory(m_device->device(), mem);
17394
17395 // Map without offset and flush WHOLE_SIZE with two separate offsets
17396 m_errorMonitor->ExpectSuccess();
17397 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17398 ASSERT_VK_SUCCESS(err);
17399 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17400 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017401 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017402 mmr.size = VK_WHOLE_SIZE;
17403 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17404 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017405 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017406 mmr.size = VK_WHOLE_SIZE;
17407 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17408 ASSERT_VK_SUCCESS(err);
17409 m_errorMonitor->VerifyNotFound();
17410 vkUnmapMemory(m_device->device(), mem);
17411
17412 vkFreeMemory(m_device->device(), mem, NULL);
17413}
17414
17415// This is a positive test. We used to expect error in this case but spec now allows it
17416TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17417 m_errorMonitor->ExpectSuccess();
17418 vk_testing::Fence testFence;
17419 VkFenceCreateInfo fenceInfo = {};
17420 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17421 fenceInfo.pNext = NULL;
17422
17423 ASSERT_NO_FATAL_FAILURE(InitState());
17424 testFence.init(*m_device, fenceInfo);
17425 VkFence fences[1] = { testFence.handle() };
17426 VkResult result = vkResetFences(m_device->device(), 1, fences);
17427 ASSERT_VK_SUCCESS(result);
17428
17429 m_errorMonitor->VerifyNotFound();
17430}
17431
17432TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17433 m_errorMonitor->ExpectSuccess();
17434
17435 ASSERT_NO_FATAL_FAILURE(InitState());
17436 VkResult err;
17437
17438 // Record (empty!) command buffer that can be submitted multiple times
17439 // simultaneously.
17440 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17441 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17442 m_commandBuffer->BeginCommandBuffer(&cbbi);
17443 m_commandBuffer->EndCommandBuffer();
17444
17445 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17446 VkFence fence;
17447 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17448 ASSERT_VK_SUCCESS(err);
17449
17450 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17451 VkSemaphore s1, s2;
17452 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17453 ASSERT_VK_SUCCESS(err);
17454 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17455 ASSERT_VK_SUCCESS(err);
17456
17457 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17458 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17459 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17460 ASSERT_VK_SUCCESS(err);
17461
17462 // Submit CB again, signaling s2.
17463 si.pSignalSemaphores = &s2;
17464 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17465 ASSERT_VK_SUCCESS(err);
17466
17467 // Wait for fence.
17468 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17469 ASSERT_VK_SUCCESS(err);
17470
17471 // CB is still in flight from second submission, but semaphore s1 is no
17472 // longer in flight. delete it.
17473 vkDestroySemaphore(m_device->device(), s1, nullptr);
17474
17475 m_errorMonitor->VerifyNotFound();
17476
17477 // Force device idle and clean up remaining objects
17478 vkDeviceWaitIdle(m_device->device());
17479 vkDestroySemaphore(m_device->device(), s2, nullptr);
17480 vkDestroyFence(m_device->device(), fence, nullptr);
17481}
17482
17483TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17484 m_errorMonitor->ExpectSuccess();
17485
17486 ASSERT_NO_FATAL_FAILURE(InitState());
17487 VkResult err;
17488
17489 // A fence created signaled
17490 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17491 VkFence f1;
17492 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17493 ASSERT_VK_SUCCESS(err);
17494
17495 // A fence created not
17496 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17497 VkFence f2;
17498 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17499 ASSERT_VK_SUCCESS(err);
17500
17501 // Submit the unsignaled fence
17502 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17503 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17504
17505 // Wait on both fences, with signaled first.
17506 VkFence fences[] = { f1, f2 };
17507 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17508
17509 // Should have both retired!
17510 vkDestroyFence(m_device->device(), f1, nullptr);
17511 vkDestroyFence(m_device->device(), f2, nullptr);
17512
17513 m_errorMonitor->VerifyNotFound();
17514}
17515
17516TEST_F(VkPositiveLayerTest, ValidUsage) {
17517 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17518 "doesn't generate validation errors");
17519
17520 ASSERT_NO_FATAL_FAILURE(InitState());
17521
17522 m_errorMonitor->ExpectSuccess();
17523 // Verify that we can create a view with usage INPUT_ATTACHMENT
17524 VkImageObj image(m_device);
17525 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17526 ASSERT_TRUE(image.initialized());
17527 VkImageView imageView;
17528 VkImageViewCreateInfo ivci = {};
17529 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17530 ivci.image = image.handle();
17531 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17532 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17533 ivci.subresourceRange.layerCount = 1;
17534 ivci.subresourceRange.baseMipLevel = 0;
17535 ivci.subresourceRange.levelCount = 1;
17536 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17537
17538 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17539 m_errorMonitor->VerifyNotFound();
17540 vkDestroyImageView(m_device->device(), imageView, NULL);
17541}
17542
17543// This is a positive test. No failures are expected.
17544TEST_F(VkPositiveLayerTest, BindSparse) {
17545 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17546 "and then free the memory");
17547
17548 ASSERT_NO_FATAL_FAILURE(InitState());
17549
17550 auto index = m_device->graphics_queue_node_index_;
17551 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17552 return;
17553
17554 m_errorMonitor->ExpectSuccess();
17555
17556 VkImage image;
17557 VkImageCreateInfo image_create_info = {};
17558 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17559 image_create_info.pNext = NULL;
17560 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17561 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17562 image_create_info.extent.width = 64;
17563 image_create_info.extent.height = 64;
17564 image_create_info.extent.depth = 1;
17565 image_create_info.mipLevels = 1;
17566 image_create_info.arrayLayers = 1;
17567 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17568 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17569 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17570 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17571 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17572 ASSERT_VK_SUCCESS(err);
17573
17574 VkMemoryRequirements memory_reqs;
17575 VkDeviceMemory memory_one, memory_two;
17576 bool pass;
17577 VkMemoryAllocateInfo memory_info = {};
17578 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17579 memory_info.pNext = NULL;
17580 memory_info.allocationSize = 0;
17581 memory_info.memoryTypeIndex = 0;
17582 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17583 // Find an image big enough to allow sparse mapping of 2 memory regions
17584 // Increase the image size until it is at least twice the
17585 // size of the required alignment, to ensure we can bind both
17586 // allocated memory blocks to the image on aligned offsets.
17587 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17588 vkDestroyImage(m_device->device(), image, nullptr);
17589 image_create_info.extent.width *= 2;
17590 image_create_info.extent.height *= 2;
17591 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17592 ASSERT_VK_SUCCESS(err);
17593 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17594 }
17595 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17596 // at the end of the first
17597 memory_info.allocationSize = memory_reqs.alignment;
17598 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17599 ASSERT_TRUE(pass);
17600 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17601 ASSERT_VK_SUCCESS(err);
17602 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17603 ASSERT_VK_SUCCESS(err);
17604 VkSparseMemoryBind binds[2];
17605 binds[0].flags = 0;
17606 binds[0].memory = memory_one;
17607 binds[0].memoryOffset = 0;
17608 binds[0].resourceOffset = 0;
17609 binds[0].size = memory_info.allocationSize;
17610 binds[1].flags = 0;
17611 binds[1].memory = memory_two;
17612 binds[1].memoryOffset = 0;
17613 binds[1].resourceOffset = memory_info.allocationSize;
17614 binds[1].size = memory_info.allocationSize;
17615
17616 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17617 opaqueBindInfo.image = image;
17618 opaqueBindInfo.bindCount = 2;
17619 opaqueBindInfo.pBinds = binds;
17620
17621 VkFence fence = VK_NULL_HANDLE;
17622 VkBindSparseInfo bindSparseInfo = {};
17623 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17624 bindSparseInfo.imageOpaqueBindCount = 1;
17625 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17626
17627 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17628 vkQueueWaitIdle(m_device->m_queue);
17629 vkDestroyImage(m_device->device(), image, NULL);
17630 vkFreeMemory(m_device->device(), memory_one, NULL);
17631 vkFreeMemory(m_device->device(), memory_two, NULL);
17632 m_errorMonitor->VerifyNotFound();
17633}
17634
17635TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17636 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17637 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17638 "the command buffer has prior knowledge of that "
17639 "attachment's layout.");
17640
17641 m_errorMonitor->ExpectSuccess();
17642
17643 ASSERT_NO_FATAL_FAILURE(InitState());
17644
17645 // A renderpass with one color attachment.
17646 VkAttachmentDescription attachment = { 0,
17647 VK_FORMAT_R8G8B8A8_UNORM,
17648 VK_SAMPLE_COUNT_1_BIT,
17649 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17650 VK_ATTACHMENT_STORE_OP_STORE,
17651 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17652 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17653 VK_IMAGE_LAYOUT_UNDEFINED,
17654 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17655
17656 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17657
17658 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17659
17660 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17661
17662 VkRenderPass rp;
17663 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17664 ASSERT_VK_SUCCESS(err);
17665
17666 // A compatible framebuffer.
17667 VkImageObj image(m_device);
17668 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17669 ASSERT_TRUE(image.initialized());
17670
17671 VkImageViewCreateInfo ivci = {
17672 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17673 nullptr,
17674 0,
17675 image.handle(),
17676 VK_IMAGE_VIEW_TYPE_2D,
17677 VK_FORMAT_R8G8B8A8_UNORM,
17678 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17679 VK_COMPONENT_SWIZZLE_IDENTITY },
17680 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17681 };
17682 VkImageView view;
17683 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17684 ASSERT_VK_SUCCESS(err);
17685
17686 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17687 VkFramebuffer fb;
17688 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17689 ASSERT_VK_SUCCESS(err);
17690
17691 // Record a single command buffer which uses this renderpass twice. The
17692 // bug is triggered at the beginning of the second renderpass, when the
17693 // command buffer already has a layout recorded for the attachment.
17694 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 -070017695 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017696 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17697 vkCmdEndRenderPass(m_commandBuffer->handle());
17698 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17699
17700 m_errorMonitor->VerifyNotFound();
17701
17702 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017703 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017704
17705 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17706 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17707 vkDestroyImageView(m_device->device(), view, nullptr);
17708}
17709
17710TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17711 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17712 "command buffer, bind them together, then destroy "
17713 "command pool and framebuffer and verify there are no "
17714 "errors.");
17715
17716 m_errorMonitor->ExpectSuccess();
17717
17718 ASSERT_NO_FATAL_FAILURE(InitState());
17719
17720 // A renderpass with one color attachment.
17721 VkAttachmentDescription attachment = { 0,
17722 VK_FORMAT_R8G8B8A8_UNORM,
17723 VK_SAMPLE_COUNT_1_BIT,
17724 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17725 VK_ATTACHMENT_STORE_OP_STORE,
17726 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17727 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17728 VK_IMAGE_LAYOUT_UNDEFINED,
17729 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17730
17731 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17732
17733 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17734
17735 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17736
17737 VkRenderPass rp;
17738 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17739 ASSERT_VK_SUCCESS(err);
17740
17741 // A compatible framebuffer.
17742 VkImageObj image(m_device);
17743 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17744 ASSERT_TRUE(image.initialized());
17745
17746 VkImageViewCreateInfo ivci = {
17747 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17748 nullptr,
17749 0,
17750 image.handle(),
17751 VK_IMAGE_VIEW_TYPE_2D,
17752 VK_FORMAT_R8G8B8A8_UNORM,
17753 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17754 VK_COMPONENT_SWIZZLE_IDENTITY },
17755 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17756 };
17757 VkImageView view;
17758 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17759 ASSERT_VK_SUCCESS(err);
17760
17761 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17762 VkFramebuffer fb;
17763 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17764 ASSERT_VK_SUCCESS(err);
17765
17766 // Explicitly create a command buffer to bind the FB to so that we can then
17767 // destroy the command pool in order to implicitly free command buffer
17768 VkCommandPool command_pool;
17769 VkCommandPoolCreateInfo pool_create_info{};
17770 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17771 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17772 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17773 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17774
17775 VkCommandBuffer command_buffer;
17776 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17777 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17778 command_buffer_allocate_info.commandPool = command_pool;
17779 command_buffer_allocate_info.commandBufferCount = 1;
17780 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17781 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17782
17783 // Begin our cmd buffer with renderpass using our framebuffer
17784 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17785 VkCommandBufferBeginInfo begin_info{};
17786 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17787 vkBeginCommandBuffer(command_buffer, &begin_info);
17788
17789 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17790 vkCmdEndRenderPass(command_buffer);
17791 vkEndCommandBuffer(command_buffer);
17792 vkDestroyImageView(m_device->device(), view, nullptr);
17793 // Destroy command pool to implicitly free command buffer
17794 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17795 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17796 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17797 m_errorMonitor->VerifyNotFound();
17798}
17799
17800TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17801 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17802 "transitions for the first subpass");
17803
17804 m_errorMonitor->ExpectSuccess();
17805
17806 ASSERT_NO_FATAL_FAILURE(InitState());
17807
17808 // A renderpass with one color attachment.
17809 VkAttachmentDescription attachment = { 0,
17810 VK_FORMAT_R8G8B8A8_UNORM,
17811 VK_SAMPLE_COUNT_1_BIT,
17812 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17813 VK_ATTACHMENT_STORE_OP_STORE,
17814 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17815 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17816 VK_IMAGE_LAYOUT_UNDEFINED,
17817 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17818
17819 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17820
17821 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17822
17823 VkSubpassDependency dep = { 0,
17824 0,
17825 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17826 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17827 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17828 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17829 VK_DEPENDENCY_BY_REGION_BIT };
17830
17831 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17832
17833 VkResult err;
17834 VkRenderPass rp;
17835 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17836 ASSERT_VK_SUCCESS(err);
17837
17838 // A compatible framebuffer.
17839 VkImageObj image(m_device);
17840 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17841 ASSERT_TRUE(image.initialized());
17842
17843 VkImageViewCreateInfo ivci = {
17844 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17845 nullptr,
17846 0,
17847 image.handle(),
17848 VK_IMAGE_VIEW_TYPE_2D,
17849 VK_FORMAT_R8G8B8A8_UNORM,
17850 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17851 VK_COMPONENT_SWIZZLE_IDENTITY },
17852 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17853 };
17854 VkImageView view;
17855 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17856 ASSERT_VK_SUCCESS(err);
17857
17858 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17859 VkFramebuffer fb;
17860 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17861 ASSERT_VK_SUCCESS(err);
17862
17863 // Record a single command buffer which issues a pipeline barrier w/
17864 // image memory barrier for the attachment. This detects the previously
17865 // missing tracking of the subpass layout by throwing a validation error
17866 // if it doesn't occur.
17867 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 -070017868 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017869 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17870
17871 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17872 nullptr,
17873 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17874 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17875 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17876 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17877 VK_QUEUE_FAMILY_IGNORED,
17878 VK_QUEUE_FAMILY_IGNORED,
17879 image.handle(),
17880 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17881 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17882 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17883 &imb);
17884
17885 vkCmdEndRenderPass(m_commandBuffer->handle());
17886 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017887 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017888
17889 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17890 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17891 vkDestroyImageView(m_device->device(), view, nullptr);
17892}
17893
17894TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17895 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17896 "is used as a depth/stencil framebuffer attachment, the "
17897 "aspectMask is ignored and both depth and stencil image "
17898 "subresources are used.");
17899
17900 VkFormatProperties format_properties;
17901 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17902 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17903 return;
17904 }
17905
17906 m_errorMonitor->ExpectSuccess();
17907
17908 ASSERT_NO_FATAL_FAILURE(InitState());
17909
17910 VkAttachmentDescription attachment = { 0,
17911 VK_FORMAT_D32_SFLOAT_S8_UINT,
17912 VK_SAMPLE_COUNT_1_BIT,
17913 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17914 VK_ATTACHMENT_STORE_OP_STORE,
17915 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17916 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17917 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17918 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17919
17920 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17921
17922 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17923
17924 VkSubpassDependency dep = { 0,
17925 0,
17926 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17927 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17928 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17929 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17930 VK_DEPENDENCY_BY_REGION_BIT};
17931
17932 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17933
17934 VkResult err;
17935 VkRenderPass rp;
17936 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17937 ASSERT_VK_SUCCESS(err);
17938
17939 VkImageObj image(m_device);
17940 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17941 0x26, // usage
17942 VK_IMAGE_TILING_OPTIMAL, 0);
17943 ASSERT_TRUE(image.initialized());
17944 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17945
17946 VkImageViewCreateInfo ivci = {
17947 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17948 nullptr,
17949 0,
17950 image.handle(),
17951 VK_IMAGE_VIEW_TYPE_2D,
17952 VK_FORMAT_D32_SFLOAT_S8_UINT,
17953 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17954 { 0x2, 0, 1, 0, 1 },
17955 };
17956 VkImageView view;
17957 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17958 ASSERT_VK_SUCCESS(err);
17959
17960 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17961 VkFramebuffer fb;
17962 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17963 ASSERT_VK_SUCCESS(err);
17964
17965 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 -070017966 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017967 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17968
17969 VkImageMemoryBarrier imb = {};
17970 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17971 imb.pNext = nullptr;
17972 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17973 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17974 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17975 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17976 imb.srcQueueFamilyIndex = 0;
17977 imb.dstQueueFamilyIndex = 0;
17978 imb.image = image.handle();
17979 imb.subresourceRange.aspectMask = 0x6;
17980 imb.subresourceRange.baseMipLevel = 0;
17981 imb.subresourceRange.levelCount = 0x1;
17982 imb.subresourceRange.baseArrayLayer = 0;
17983 imb.subresourceRange.layerCount = 0x1;
17984
17985 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17986 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17987 &imb);
17988
17989 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017990 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017991 QueueCommandBuffer(false);
17992 m_errorMonitor->VerifyNotFound();
17993
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, RenderPassTransitionsAttachmentUnused) {
18000 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
18001 "errors, when an attachment reference is "
18002 "VK_ATTACHMENT_UNUSED");
18003
18004 m_errorMonitor->ExpectSuccess();
18005
18006 ASSERT_NO_FATAL_FAILURE(InitState());
18007
18008 // A renderpass with no attachments
18009 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
18010
18011 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
18012
18013 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
18014
18015 VkRenderPass rp;
18016 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18017 ASSERT_VK_SUCCESS(err);
18018
18019 // A compatible framebuffer.
18020 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
18021 VkFramebuffer fb;
18022 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18023 ASSERT_VK_SUCCESS(err);
18024
18025 // Record a command buffer which just begins and ends the renderpass. The
18026 // bug manifests in BeginRenderPass.
18027 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 -070018028 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018029 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18030 vkCmdEndRenderPass(m_commandBuffer->handle());
18031 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018032 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018033
18034 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18035 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18036}
18037
18038// This is a positive test. No errors are expected.
18039TEST_F(VkPositiveLayerTest, StencilLoadOp) {
18040 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
18041 "CLEAR. stencil[Load|Store]Op used to be ignored.");
18042 VkResult result = VK_SUCCESS;
18043 VkImageFormatProperties formatProps;
18044 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18045 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18046 &formatProps);
18047 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18048 return;
18049 }
18050
18051 ASSERT_NO_FATAL_FAILURE(InitState());
18052 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18053 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
18054 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
18055 VkAttachmentDescription att = {};
18056 VkAttachmentReference ref = {};
18057 att.format = depth_stencil_fmt;
18058 att.samples = VK_SAMPLE_COUNT_1_BIT;
18059 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18060 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18061 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18062 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18063 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18064 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18065
18066 VkClearValue clear;
18067 clear.depthStencil.depth = 1.0;
18068 clear.depthStencil.stencil = 0;
18069 ref.attachment = 0;
18070 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18071
18072 VkSubpassDescription subpass = {};
18073 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18074 subpass.flags = 0;
18075 subpass.inputAttachmentCount = 0;
18076 subpass.pInputAttachments = NULL;
18077 subpass.colorAttachmentCount = 0;
18078 subpass.pColorAttachments = NULL;
18079 subpass.pResolveAttachments = NULL;
18080 subpass.pDepthStencilAttachment = &ref;
18081 subpass.preserveAttachmentCount = 0;
18082 subpass.pPreserveAttachments = NULL;
18083
18084 VkRenderPass rp;
18085 VkRenderPassCreateInfo rp_info = {};
18086 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18087 rp_info.attachmentCount = 1;
18088 rp_info.pAttachments = &att;
18089 rp_info.subpassCount = 1;
18090 rp_info.pSubpasses = &subpass;
18091 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18092 ASSERT_VK_SUCCESS(result);
18093
18094 VkImageView *depthView = m_depthStencil->BindInfo();
18095 VkFramebufferCreateInfo fb_info = {};
18096 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18097 fb_info.pNext = NULL;
18098 fb_info.renderPass = rp;
18099 fb_info.attachmentCount = 1;
18100 fb_info.pAttachments = depthView;
18101 fb_info.width = 100;
18102 fb_info.height = 100;
18103 fb_info.layers = 1;
18104 VkFramebuffer fb;
18105 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18106 ASSERT_VK_SUCCESS(result);
18107
18108 VkRenderPassBeginInfo rpbinfo = {};
18109 rpbinfo.clearValueCount = 1;
18110 rpbinfo.pClearValues = &clear;
18111 rpbinfo.pNext = NULL;
18112 rpbinfo.renderPass = rp;
18113 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18114 rpbinfo.renderArea.extent.width = 100;
18115 rpbinfo.renderArea.extent.height = 100;
18116 rpbinfo.renderArea.offset.x = 0;
18117 rpbinfo.renderArea.offset.y = 0;
18118 rpbinfo.framebuffer = fb;
18119
18120 VkFence fence = {};
18121 VkFenceCreateInfo fence_ci = {};
18122 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18123 fence_ci.pNext = nullptr;
18124 fence_ci.flags = 0;
18125 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18126 ASSERT_VK_SUCCESS(result);
18127
18128 m_commandBuffer->BeginCommandBuffer();
18129 m_commandBuffer->BeginRenderPass(rpbinfo);
18130 m_commandBuffer->EndRenderPass();
18131 m_commandBuffer->EndCommandBuffer();
18132 m_commandBuffer->QueueCommandBuffer(fence);
18133
18134 VkImageObj destImage(m_device);
18135 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18136 VK_IMAGE_TILING_OPTIMAL, 0);
18137 VkImageMemoryBarrier barrier = {};
18138 VkImageSubresourceRange range;
18139 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18140 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18141 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18142 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18143 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18144 barrier.image = m_depthStencil->handle();
18145 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18146 range.baseMipLevel = 0;
18147 range.levelCount = 1;
18148 range.baseArrayLayer = 0;
18149 range.layerCount = 1;
18150 barrier.subresourceRange = range;
18151 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18152 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18153 cmdbuf.BeginCommandBuffer();
18154 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18155 &barrier);
18156 barrier.srcAccessMask = 0;
18157 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18158 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18159 barrier.image = destImage.handle();
18160 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18161 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18162 &barrier);
18163 VkImageCopy cregion;
18164 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18165 cregion.srcSubresource.mipLevel = 0;
18166 cregion.srcSubresource.baseArrayLayer = 0;
18167 cregion.srcSubresource.layerCount = 1;
18168 cregion.srcOffset.x = 0;
18169 cregion.srcOffset.y = 0;
18170 cregion.srcOffset.z = 0;
18171 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18172 cregion.dstSubresource.mipLevel = 0;
18173 cregion.dstSubresource.baseArrayLayer = 0;
18174 cregion.dstSubresource.layerCount = 1;
18175 cregion.dstOffset.x = 0;
18176 cregion.dstOffset.y = 0;
18177 cregion.dstOffset.z = 0;
18178 cregion.extent.width = 100;
18179 cregion.extent.height = 100;
18180 cregion.extent.depth = 1;
18181 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
18182 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
18183 cmdbuf.EndCommandBuffer();
18184
18185 VkSubmitInfo submit_info;
18186 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18187 submit_info.pNext = NULL;
18188 submit_info.waitSemaphoreCount = 0;
18189 submit_info.pWaitSemaphores = NULL;
18190 submit_info.pWaitDstStageMask = NULL;
18191 submit_info.commandBufferCount = 1;
18192 submit_info.pCommandBuffers = &cmdbuf.handle();
18193 submit_info.signalSemaphoreCount = 0;
18194 submit_info.pSignalSemaphores = NULL;
18195
18196 m_errorMonitor->ExpectSuccess();
18197 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18198 m_errorMonitor->VerifyNotFound();
18199
18200 vkQueueWaitIdle(m_device->m_queue);
18201 vkDestroyFence(m_device->device(), fence, nullptr);
18202 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18203 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18204}
18205
18206// This is a positive test. No errors should be generated.
18207TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18208 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18209
18210 m_errorMonitor->ExpectSuccess();
18211 ASSERT_NO_FATAL_FAILURE(InitState());
18212
18213 VkEvent event;
18214 VkEventCreateInfo event_create_info{};
18215 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18216 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18217
18218 VkCommandPool command_pool;
18219 VkCommandPoolCreateInfo pool_create_info{};
18220 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18221 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18222 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18223 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18224
18225 VkCommandBuffer command_buffer;
18226 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18227 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18228 command_buffer_allocate_info.commandPool = command_pool;
18229 command_buffer_allocate_info.commandBufferCount = 1;
18230 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18231 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18232
18233 VkQueue queue = VK_NULL_HANDLE;
18234 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18235
18236 {
18237 VkCommandBufferBeginInfo begin_info{};
18238 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18239 vkBeginCommandBuffer(command_buffer, &begin_info);
18240
18241 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
18242 nullptr, 0, nullptr);
18243 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18244 vkEndCommandBuffer(command_buffer);
18245 }
18246 {
18247 VkSubmitInfo submit_info{};
18248 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18249 submit_info.commandBufferCount = 1;
18250 submit_info.pCommandBuffers = &command_buffer;
18251 submit_info.signalSemaphoreCount = 0;
18252 submit_info.pSignalSemaphores = nullptr;
18253 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18254 }
18255 { vkSetEvent(m_device->device(), event); }
18256
18257 vkQueueWaitIdle(queue);
18258
18259 vkDestroyEvent(m_device->device(), event, nullptr);
18260 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18261 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18262
18263 m_errorMonitor->VerifyNotFound();
18264}
18265// This is a positive test. No errors should be generated.
18266TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18267 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18268
18269 ASSERT_NO_FATAL_FAILURE(InitState());
18270 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18271 return;
18272
18273 m_errorMonitor->ExpectSuccess();
18274
18275 VkQueryPool query_pool;
18276 VkQueryPoolCreateInfo query_pool_create_info{};
18277 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18278 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18279 query_pool_create_info.queryCount = 1;
18280 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18281
18282 VkCommandPool command_pool;
18283 VkCommandPoolCreateInfo pool_create_info{};
18284 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18285 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18286 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18288
18289 VkCommandBuffer command_buffer;
18290 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18291 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18292 command_buffer_allocate_info.commandPool = command_pool;
18293 command_buffer_allocate_info.commandBufferCount = 1;
18294 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18295 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18296
18297 VkCommandBuffer secondary_command_buffer;
18298 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18299 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18300
18301 VkQueue queue = VK_NULL_HANDLE;
18302 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18303
18304 uint32_t qfi = 0;
18305 VkBufferCreateInfo buff_create_info = {};
18306 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18307 buff_create_info.size = 1024;
18308 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18309 buff_create_info.queueFamilyIndexCount = 1;
18310 buff_create_info.pQueueFamilyIndices = &qfi;
18311
18312 VkResult err;
18313 VkBuffer buffer;
18314 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18315 ASSERT_VK_SUCCESS(err);
18316 VkMemoryAllocateInfo mem_alloc = {};
18317 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18318 mem_alloc.pNext = NULL;
18319 mem_alloc.allocationSize = 1024;
18320 mem_alloc.memoryTypeIndex = 0;
18321
18322 VkMemoryRequirements memReqs;
18323 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18324 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18325 if (!pass) {
18326 vkDestroyBuffer(m_device->device(), buffer, NULL);
18327 return;
18328 }
18329
18330 VkDeviceMemory mem;
18331 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18332 ASSERT_VK_SUCCESS(err);
18333 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18334 ASSERT_VK_SUCCESS(err);
18335
18336 VkCommandBufferInheritanceInfo hinfo = {};
18337 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18338 hinfo.renderPass = VK_NULL_HANDLE;
18339 hinfo.subpass = 0;
18340 hinfo.framebuffer = VK_NULL_HANDLE;
18341 hinfo.occlusionQueryEnable = VK_FALSE;
18342 hinfo.queryFlags = 0;
18343 hinfo.pipelineStatistics = 0;
18344
18345 {
18346 VkCommandBufferBeginInfo begin_info{};
18347 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18348 begin_info.pInheritanceInfo = &hinfo;
18349 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18350
18351 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18352 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18353
18354 vkEndCommandBuffer(secondary_command_buffer);
18355
18356 begin_info.pInheritanceInfo = nullptr;
18357 vkBeginCommandBuffer(command_buffer, &begin_info);
18358
18359 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18360 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18361
18362 vkEndCommandBuffer(command_buffer);
18363 }
18364 {
18365 VkSubmitInfo submit_info{};
18366 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18367 submit_info.commandBufferCount = 1;
18368 submit_info.pCommandBuffers = &command_buffer;
18369 submit_info.signalSemaphoreCount = 0;
18370 submit_info.pSignalSemaphores = nullptr;
18371 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18372 }
18373
18374 vkQueueWaitIdle(queue);
18375
18376 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18377 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18378 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18379 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18380 vkDestroyBuffer(m_device->device(), buffer, NULL);
18381 vkFreeMemory(m_device->device(), mem, NULL);
18382
18383 m_errorMonitor->VerifyNotFound();
18384}
18385
18386// This is a positive test. No errors should be generated.
18387TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18388 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18389
18390 ASSERT_NO_FATAL_FAILURE(InitState());
18391 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18392 return;
18393
18394 m_errorMonitor->ExpectSuccess();
18395
18396 VkQueryPool query_pool;
18397 VkQueryPoolCreateInfo query_pool_create_info{};
18398 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18399 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18400 query_pool_create_info.queryCount = 1;
18401 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18402
18403 VkCommandPool command_pool;
18404 VkCommandPoolCreateInfo pool_create_info{};
18405 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18406 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18407 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18408 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18409
18410 VkCommandBuffer command_buffer[2];
18411 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18412 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18413 command_buffer_allocate_info.commandPool = command_pool;
18414 command_buffer_allocate_info.commandBufferCount = 2;
18415 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18416 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18417
18418 VkQueue queue = VK_NULL_HANDLE;
18419 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18420
18421 uint32_t qfi = 0;
18422 VkBufferCreateInfo buff_create_info = {};
18423 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18424 buff_create_info.size = 1024;
18425 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18426 buff_create_info.queueFamilyIndexCount = 1;
18427 buff_create_info.pQueueFamilyIndices = &qfi;
18428
18429 VkResult err;
18430 VkBuffer buffer;
18431 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18432 ASSERT_VK_SUCCESS(err);
18433 VkMemoryAllocateInfo mem_alloc = {};
18434 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18435 mem_alloc.pNext = NULL;
18436 mem_alloc.allocationSize = 1024;
18437 mem_alloc.memoryTypeIndex = 0;
18438
18439 VkMemoryRequirements memReqs;
18440 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18441 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18442 if (!pass) {
18443 vkDestroyBuffer(m_device->device(), buffer, NULL);
18444 return;
18445 }
18446
18447 VkDeviceMemory mem;
18448 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18449 ASSERT_VK_SUCCESS(err);
18450 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18451 ASSERT_VK_SUCCESS(err);
18452
18453 {
18454 VkCommandBufferBeginInfo begin_info{};
18455 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18456 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18457
18458 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18459 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18460
18461 vkEndCommandBuffer(command_buffer[0]);
18462
18463 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18464
18465 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18466
18467 vkEndCommandBuffer(command_buffer[1]);
18468 }
18469 {
18470 VkSubmitInfo submit_info{};
18471 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18472 submit_info.commandBufferCount = 2;
18473 submit_info.pCommandBuffers = command_buffer;
18474 submit_info.signalSemaphoreCount = 0;
18475 submit_info.pSignalSemaphores = nullptr;
18476 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18477 }
18478
18479 vkQueueWaitIdle(queue);
18480
18481 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18482 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18483 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18484 vkDestroyBuffer(m_device->device(), buffer, NULL);
18485 vkFreeMemory(m_device->device(), mem, NULL);
18486
18487 m_errorMonitor->VerifyNotFound();
18488}
18489
Tony Barbourc46924f2016-11-04 11:49:52 -060018490TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018491 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18492
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018493 ASSERT_NO_FATAL_FAILURE(InitState());
18494 VkEvent event;
18495 VkEventCreateInfo event_create_info{};
18496 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18497 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18498
18499 VkCommandPool command_pool;
18500 VkCommandPoolCreateInfo pool_create_info{};
18501 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18502 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18503 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18504 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18505
18506 VkCommandBuffer command_buffer;
18507 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18508 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18509 command_buffer_allocate_info.commandPool = command_pool;
18510 command_buffer_allocate_info.commandBufferCount = 1;
18511 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18512 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18513
18514 VkQueue queue = VK_NULL_HANDLE;
18515 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18516
18517 {
18518 VkCommandBufferBeginInfo begin_info{};
18519 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18520 vkBeginCommandBuffer(command_buffer, &begin_info);
18521
18522 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018523 vkEndCommandBuffer(command_buffer);
18524 }
18525 {
18526 VkSubmitInfo submit_info{};
18527 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18528 submit_info.commandBufferCount = 1;
18529 submit_info.pCommandBuffers = &command_buffer;
18530 submit_info.signalSemaphoreCount = 0;
18531 submit_info.pSignalSemaphores = nullptr;
18532 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18533 }
18534 {
18535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18536 "command buffer.");
18537 vkSetEvent(m_device->device(), event);
18538 m_errorMonitor->VerifyFound();
18539 }
18540
18541 vkQueueWaitIdle(queue);
18542
18543 vkDestroyEvent(m_device->device(), event, nullptr);
18544 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18545 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18546}
18547
18548// This is a positive test. No errors should be generated.
18549TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18550 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18551 "run through a Submit & WaitForFences cycle 3 times. This "
18552 "previously revealed a bug so running this positive test "
18553 "to prevent a regression.");
18554 m_errorMonitor->ExpectSuccess();
18555
18556 ASSERT_NO_FATAL_FAILURE(InitState());
18557 VkQueue queue = VK_NULL_HANDLE;
18558 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18559
18560 static const uint32_t NUM_OBJECTS = 2;
18561 static const uint32_t NUM_FRAMES = 3;
18562 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18563 VkFence fences[NUM_OBJECTS] = {};
18564
18565 VkCommandPool cmd_pool;
18566 VkCommandPoolCreateInfo cmd_pool_ci = {};
18567 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18568 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18569 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18570 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18571 ASSERT_VK_SUCCESS(err);
18572
18573 VkCommandBufferAllocateInfo cmd_buf_info = {};
18574 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18575 cmd_buf_info.commandPool = cmd_pool;
18576 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18577 cmd_buf_info.commandBufferCount = 1;
18578
18579 VkFenceCreateInfo fence_ci = {};
18580 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18581 fence_ci.pNext = nullptr;
18582 fence_ci.flags = 0;
18583
18584 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18585 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18586 ASSERT_VK_SUCCESS(err);
18587 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18588 ASSERT_VK_SUCCESS(err);
18589 }
18590
18591 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18592 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18593 // Create empty cmd buffer
18594 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18595 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18596
18597 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18598 ASSERT_VK_SUCCESS(err);
18599 err = vkEndCommandBuffer(cmd_buffers[obj]);
18600 ASSERT_VK_SUCCESS(err);
18601
18602 VkSubmitInfo submit_info = {};
18603 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18604 submit_info.commandBufferCount = 1;
18605 submit_info.pCommandBuffers = &cmd_buffers[obj];
18606 // Submit cmd buffer and wait for fence
18607 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18608 ASSERT_VK_SUCCESS(err);
18609 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18610 ASSERT_VK_SUCCESS(err);
18611 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18612 ASSERT_VK_SUCCESS(err);
18613 }
18614 }
18615 m_errorMonitor->VerifyNotFound();
18616 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18617 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18618 vkDestroyFence(m_device->device(), fences[i], nullptr);
18619 }
18620}
18621// This is a positive test. No errors should be generated.
18622TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18623
18624 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18625 "submitted on separate queues followed by a QueueWaitIdle.");
18626
18627 ASSERT_NO_FATAL_FAILURE(InitState());
18628 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18629 return;
18630
18631 m_errorMonitor->ExpectSuccess();
18632
18633 VkSemaphore semaphore;
18634 VkSemaphoreCreateInfo semaphore_create_info{};
18635 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18636 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18637
18638 VkCommandPool command_pool;
18639 VkCommandPoolCreateInfo pool_create_info{};
18640 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18641 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18642 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18643 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18644
18645 VkCommandBuffer command_buffer[2];
18646 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18647 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18648 command_buffer_allocate_info.commandPool = command_pool;
18649 command_buffer_allocate_info.commandBufferCount = 2;
18650 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18651 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18652
18653 VkQueue queue = VK_NULL_HANDLE;
18654 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18655
18656 {
18657 VkCommandBufferBeginInfo begin_info{};
18658 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18659 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18660
18661 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18662 nullptr, 0, nullptr, 0, nullptr);
18663
18664 VkViewport viewport{};
18665 viewport.maxDepth = 1.0f;
18666 viewport.minDepth = 0.0f;
18667 viewport.width = 512;
18668 viewport.height = 512;
18669 viewport.x = 0;
18670 viewport.y = 0;
18671 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18672 vkEndCommandBuffer(command_buffer[0]);
18673 }
18674 {
18675 VkCommandBufferBeginInfo begin_info{};
18676 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18677 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18678
18679 VkViewport viewport{};
18680 viewport.maxDepth = 1.0f;
18681 viewport.minDepth = 0.0f;
18682 viewport.width = 512;
18683 viewport.height = 512;
18684 viewport.x = 0;
18685 viewport.y = 0;
18686 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18687 vkEndCommandBuffer(command_buffer[1]);
18688 }
18689 {
18690 VkSubmitInfo submit_info{};
18691 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18692 submit_info.commandBufferCount = 1;
18693 submit_info.pCommandBuffers = &command_buffer[0];
18694 submit_info.signalSemaphoreCount = 1;
18695 submit_info.pSignalSemaphores = &semaphore;
18696 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18697 }
18698 {
18699 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18700 VkSubmitInfo submit_info{};
18701 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18702 submit_info.commandBufferCount = 1;
18703 submit_info.pCommandBuffers = &command_buffer[1];
18704 submit_info.waitSemaphoreCount = 1;
18705 submit_info.pWaitSemaphores = &semaphore;
18706 submit_info.pWaitDstStageMask = flags;
18707 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18708 }
18709
18710 vkQueueWaitIdle(m_device->m_queue);
18711
18712 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18713 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18714 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18715
18716 m_errorMonitor->VerifyNotFound();
18717}
18718
18719// This is a positive test. No errors should be generated.
18720TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18721
18722 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18723 "submitted on separate queues, the second having a fence"
18724 "followed by a QueueWaitIdle.");
18725
18726 ASSERT_NO_FATAL_FAILURE(InitState());
18727 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18728 return;
18729
18730 m_errorMonitor->ExpectSuccess();
18731
18732 VkFence fence;
18733 VkFenceCreateInfo fence_create_info{};
18734 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18735 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18736
18737 VkSemaphore semaphore;
18738 VkSemaphoreCreateInfo semaphore_create_info{};
18739 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18740 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18741
18742 VkCommandPool command_pool;
18743 VkCommandPoolCreateInfo pool_create_info{};
18744 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18745 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18746 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18747 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18748
18749 VkCommandBuffer command_buffer[2];
18750 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18751 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18752 command_buffer_allocate_info.commandPool = command_pool;
18753 command_buffer_allocate_info.commandBufferCount = 2;
18754 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18755 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18756
18757 VkQueue queue = VK_NULL_HANDLE;
18758 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18759
18760 {
18761 VkCommandBufferBeginInfo begin_info{};
18762 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18763 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18764
18765 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18766 nullptr, 0, nullptr, 0, nullptr);
18767
18768 VkViewport viewport{};
18769 viewport.maxDepth = 1.0f;
18770 viewport.minDepth = 0.0f;
18771 viewport.width = 512;
18772 viewport.height = 512;
18773 viewport.x = 0;
18774 viewport.y = 0;
18775 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18776 vkEndCommandBuffer(command_buffer[0]);
18777 }
18778 {
18779 VkCommandBufferBeginInfo begin_info{};
18780 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18781 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18782
18783 VkViewport viewport{};
18784 viewport.maxDepth = 1.0f;
18785 viewport.minDepth = 0.0f;
18786 viewport.width = 512;
18787 viewport.height = 512;
18788 viewport.x = 0;
18789 viewport.y = 0;
18790 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18791 vkEndCommandBuffer(command_buffer[1]);
18792 }
18793 {
18794 VkSubmitInfo submit_info{};
18795 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18796 submit_info.commandBufferCount = 1;
18797 submit_info.pCommandBuffers = &command_buffer[0];
18798 submit_info.signalSemaphoreCount = 1;
18799 submit_info.pSignalSemaphores = &semaphore;
18800 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18801 }
18802 {
18803 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18804 VkSubmitInfo submit_info{};
18805 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18806 submit_info.commandBufferCount = 1;
18807 submit_info.pCommandBuffers = &command_buffer[1];
18808 submit_info.waitSemaphoreCount = 1;
18809 submit_info.pWaitSemaphores = &semaphore;
18810 submit_info.pWaitDstStageMask = flags;
18811 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18812 }
18813
18814 vkQueueWaitIdle(m_device->m_queue);
18815
18816 vkDestroyFence(m_device->device(), fence, nullptr);
18817 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18818 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18819 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18820
18821 m_errorMonitor->VerifyNotFound();
18822}
18823
18824// This is a positive test. No errors should be generated.
18825TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18826
18827 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18828 "submitted on separate queues, the second having a fence"
18829 "followed by two consecutive WaitForFences calls on the same fence.");
18830
18831 ASSERT_NO_FATAL_FAILURE(InitState());
18832 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18833 return;
18834
18835 m_errorMonitor->ExpectSuccess();
18836
18837 VkFence fence;
18838 VkFenceCreateInfo fence_create_info{};
18839 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18840 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18841
18842 VkSemaphore semaphore;
18843 VkSemaphoreCreateInfo semaphore_create_info{};
18844 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18845 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18846
18847 VkCommandPool command_pool;
18848 VkCommandPoolCreateInfo pool_create_info{};
18849 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18850 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18851 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18852 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18853
18854 VkCommandBuffer command_buffer[2];
18855 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18856 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18857 command_buffer_allocate_info.commandPool = command_pool;
18858 command_buffer_allocate_info.commandBufferCount = 2;
18859 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18860 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18861
18862 VkQueue queue = VK_NULL_HANDLE;
18863 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18864
18865 {
18866 VkCommandBufferBeginInfo begin_info{};
18867 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18868 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18869
18870 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18871 nullptr, 0, nullptr, 0, nullptr);
18872
18873 VkViewport viewport{};
18874 viewport.maxDepth = 1.0f;
18875 viewport.minDepth = 0.0f;
18876 viewport.width = 512;
18877 viewport.height = 512;
18878 viewport.x = 0;
18879 viewport.y = 0;
18880 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18881 vkEndCommandBuffer(command_buffer[0]);
18882 }
18883 {
18884 VkCommandBufferBeginInfo begin_info{};
18885 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18886 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18887
18888 VkViewport viewport{};
18889 viewport.maxDepth = 1.0f;
18890 viewport.minDepth = 0.0f;
18891 viewport.width = 512;
18892 viewport.height = 512;
18893 viewport.x = 0;
18894 viewport.y = 0;
18895 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18896 vkEndCommandBuffer(command_buffer[1]);
18897 }
18898 {
18899 VkSubmitInfo submit_info{};
18900 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18901 submit_info.commandBufferCount = 1;
18902 submit_info.pCommandBuffers = &command_buffer[0];
18903 submit_info.signalSemaphoreCount = 1;
18904 submit_info.pSignalSemaphores = &semaphore;
18905 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18906 }
18907 {
18908 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18909 VkSubmitInfo submit_info{};
18910 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18911 submit_info.commandBufferCount = 1;
18912 submit_info.pCommandBuffers = &command_buffer[1];
18913 submit_info.waitSemaphoreCount = 1;
18914 submit_info.pWaitSemaphores = &semaphore;
18915 submit_info.pWaitDstStageMask = flags;
18916 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18917 }
18918
18919 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18920 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18921
18922 vkDestroyFence(m_device->device(), fence, nullptr);
18923 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18924 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18925 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18926
18927 m_errorMonitor->VerifyNotFound();
18928}
18929
18930TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18931
18932 ASSERT_NO_FATAL_FAILURE(InitState());
18933 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18934 printf("Test requires two queues, skipping\n");
18935 return;
18936 }
18937
18938 VkResult err;
18939
18940 m_errorMonitor->ExpectSuccess();
18941
18942 VkQueue q0 = m_device->m_queue;
18943 VkQueue q1 = nullptr;
18944 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18945 ASSERT_NE(q1, nullptr);
18946
18947 // An (empty) command buffer. We must have work in the first submission --
18948 // the layer treats unfenced work differently from fenced work.
18949 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18950 VkCommandPool pool;
18951 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18952 ASSERT_VK_SUCCESS(err);
18953 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18954 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18955 VkCommandBuffer cb;
18956 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18957 ASSERT_VK_SUCCESS(err);
18958 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18959 err = vkBeginCommandBuffer(cb, &cbbi);
18960 ASSERT_VK_SUCCESS(err);
18961 err = vkEndCommandBuffer(cb);
18962 ASSERT_VK_SUCCESS(err);
18963
18964 // A semaphore
18965 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18966 VkSemaphore s;
18967 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18968 ASSERT_VK_SUCCESS(err);
18969
18970 // First submission, to q0
18971 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18972
18973 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18974 ASSERT_VK_SUCCESS(err);
18975
18976 // Second submission, to q1, waiting on s
18977 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18978 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18979
18980 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18981 ASSERT_VK_SUCCESS(err);
18982
18983 // Wait for q0 idle
18984 err = vkQueueWaitIdle(q0);
18985 ASSERT_VK_SUCCESS(err);
18986
18987 // Command buffer should have been completed (it was on q0); reset the pool.
18988 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18989
18990 m_errorMonitor->VerifyNotFound();
18991
18992 // Force device completely idle and clean up resources
18993 vkDeviceWaitIdle(m_device->device());
18994 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18995 vkDestroySemaphore(m_device->device(), s, nullptr);
18996}
18997
18998// This is a positive test. No errors should be generated.
18999TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
19000
19001 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19002 "submitted on separate queues, the second having a fence, "
19003 "followed by a WaitForFences call.");
19004
19005 ASSERT_NO_FATAL_FAILURE(InitState());
19006 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
19007 return;
19008
19009 m_errorMonitor->ExpectSuccess();
19010
19011 ASSERT_NO_FATAL_FAILURE(InitState());
19012 VkFence fence;
19013 VkFenceCreateInfo fence_create_info{};
19014 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19015 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19016
19017 VkSemaphore semaphore;
19018 VkSemaphoreCreateInfo semaphore_create_info{};
19019 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19020 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19021
19022 VkCommandPool command_pool;
19023 VkCommandPoolCreateInfo pool_create_info{};
19024 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19025 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19026 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19027 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19028
19029 VkCommandBuffer command_buffer[2];
19030 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19031 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19032 command_buffer_allocate_info.commandPool = command_pool;
19033 command_buffer_allocate_info.commandBufferCount = 2;
19034 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19035 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19036
19037 VkQueue queue = VK_NULL_HANDLE;
19038 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19039
19040 {
19041 VkCommandBufferBeginInfo begin_info{};
19042 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19043 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19044
19045 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19046 nullptr, 0, nullptr, 0, nullptr);
19047
19048 VkViewport viewport{};
19049 viewport.maxDepth = 1.0f;
19050 viewport.minDepth = 0.0f;
19051 viewport.width = 512;
19052 viewport.height = 512;
19053 viewport.x = 0;
19054 viewport.y = 0;
19055 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19056 vkEndCommandBuffer(command_buffer[0]);
19057 }
19058 {
19059 VkCommandBufferBeginInfo begin_info{};
19060 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19061 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19062
19063 VkViewport viewport{};
19064 viewport.maxDepth = 1.0f;
19065 viewport.minDepth = 0.0f;
19066 viewport.width = 512;
19067 viewport.height = 512;
19068 viewport.x = 0;
19069 viewport.y = 0;
19070 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19071 vkEndCommandBuffer(command_buffer[1]);
19072 }
19073 {
19074 VkSubmitInfo submit_info{};
19075 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19076 submit_info.commandBufferCount = 1;
19077 submit_info.pCommandBuffers = &command_buffer[0];
19078 submit_info.signalSemaphoreCount = 1;
19079 submit_info.pSignalSemaphores = &semaphore;
19080 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19081 }
19082 {
19083 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19084 VkSubmitInfo submit_info{};
19085 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19086 submit_info.commandBufferCount = 1;
19087 submit_info.pCommandBuffers = &command_buffer[1];
19088 submit_info.waitSemaphoreCount = 1;
19089 submit_info.pWaitSemaphores = &semaphore;
19090 submit_info.pWaitDstStageMask = flags;
19091 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19092 }
19093
19094 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19095
19096 vkDestroyFence(m_device->device(), fence, nullptr);
19097 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19098 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19099 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19100
19101 m_errorMonitor->VerifyNotFound();
19102}
19103
19104// This is a positive test. No errors should be generated.
19105TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
19106
19107 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19108 "on the same queue, sharing a signal/wait semaphore, the "
19109 "second having a fence, "
19110 "followed by a WaitForFences call.");
19111
19112 m_errorMonitor->ExpectSuccess();
19113
19114 ASSERT_NO_FATAL_FAILURE(InitState());
19115 VkFence fence;
19116 VkFenceCreateInfo fence_create_info{};
19117 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19118 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19119
19120 VkSemaphore semaphore;
19121 VkSemaphoreCreateInfo semaphore_create_info{};
19122 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19123 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19124
19125 VkCommandPool command_pool;
19126 VkCommandPoolCreateInfo pool_create_info{};
19127 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19128 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19129 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19130 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19131
19132 VkCommandBuffer command_buffer[2];
19133 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19134 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19135 command_buffer_allocate_info.commandPool = command_pool;
19136 command_buffer_allocate_info.commandBufferCount = 2;
19137 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19138 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19139
19140 {
19141 VkCommandBufferBeginInfo begin_info{};
19142 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19143 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19144
19145 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19146 nullptr, 0, nullptr, 0, nullptr);
19147
19148 VkViewport viewport{};
19149 viewport.maxDepth = 1.0f;
19150 viewport.minDepth = 0.0f;
19151 viewport.width = 512;
19152 viewport.height = 512;
19153 viewport.x = 0;
19154 viewport.y = 0;
19155 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19156 vkEndCommandBuffer(command_buffer[0]);
19157 }
19158 {
19159 VkCommandBufferBeginInfo begin_info{};
19160 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19161 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19162
19163 VkViewport viewport{};
19164 viewport.maxDepth = 1.0f;
19165 viewport.minDepth = 0.0f;
19166 viewport.width = 512;
19167 viewport.height = 512;
19168 viewport.x = 0;
19169 viewport.y = 0;
19170 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19171 vkEndCommandBuffer(command_buffer[1]);
19172 }
19173 {
19174 VkSubmitInfo submit_info{};
19175 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19176 submit_info.commandBufferCount = 1;
19177 submit_info.pCommandBuffers = &command_buffer[0];
19178 submit_info.signalSemaphoreCount = 1;
19179 submit_info.pSignalSemaphores = &semaphore;
19180 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19181 }
19182 {
19183 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19184 VkSubmitInfo submit_info{};
19185 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19186 submit_info.commandBufferCount = 1;
19187 submit_info.pCommandBuffers = &command_buffer[1];
19188 submit_info.waitSemaphoreCount = 1;
19189 submit_info.pWaitSemaphores = &semaphore;
19190 submit_info.pWaitDstStageMask = flags;
19191 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19192 }
19193
19194 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19195
19196 vkDestroyFence(m_device->device(), fence, nullptr);
19197 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19198 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19199 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19200
19201 m_errorMonitor->VerifyNotFound();
19202}
19203
19204// This is a positive test. No errors should be generated.
19205TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
19206
19207 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19208 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19209 "SubmitInfos but with a fence, followed by a WaitForFences call.");
19210
19211 m_errorMonitor->ExpectSuccess();
19212
19213 ASSERT_NO_FATAL_FAILURE(InitState());
19214 VkFence fence;
19215 VkFenceCreateInfo fence_create_info{};
19216 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19217 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19218
19219 VkCommandPool command_pool;
19220 VkCommandPoolCreateInfo pool_create_info{};
19221 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19222 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19223 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19224 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19225
19226 VkCommandBuffer command_buffer[2];
19227 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19228 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19229 command_buffer_allocate_info.commandPool = command_pool;
19230 command_buffer_allocate_info.commandBufferCount = 2;
19231 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19232 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19233
19234 {
19235 VkCommandBufferBeginInfo begin_info{};
19236 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19237 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19238
19239 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19240 nullptr, 0, nullptr, 0, nullptr);
19241
19242 VkViewport viewport{};
19243 viewport.maxDepth = 1.0f;
19244 viewport.minDepth = 0.0f;
19245 viewport.width = 512;
19246 viewport.height = 512;
19247 viewport.x = 0;
19248 viewport.y = 0;
19249 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19250 vkEndCommandBuffer(command_buffer[0]);
19251 }
19252 {
19253 VkCommandBufferBeginInfo begin_info{};
19254 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19255 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19256
19257 VkViewport viewport{};
19258 viewport.maxDepth = 1.0f;
19259 viewport.minDepth = 0.0f;
19260 viewport.width = 512;
19261 viewport.height = 512;
19262 viewport.x = 0;
19263 viewport.y = 0;
19264 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19265 vkEndCommandBuffer(command_buffer[1]);
19266 }
19267 {
19268 VkSubmitInfo submit_info{};
19269 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19270 submit_info.commandBufferCount = 1;
19271 submit_info.pCommandBuffers = &command_buffer[0];
19272 submit_info.signalSemaphoreCount = 0;
19273 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19274 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19275 }
19276 {
19277 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19278 VkSubmitInfo submit_info{};
19279 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19280 submit_info.commandBufferCount = 1;
19281 submit_info.pCommandBuffers = &command_buffer[1];
19282 submit_info.waitSemaphoreCount = 0;
19283 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19284 submit_info.pWaitDstStageMask = flags;
19285 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19286 }
19287
19288 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19289
19290 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19291 ASSERT_VK_SUCCESS(err);
19292
19293 vkDestroyFence(m_device->device(), fence, nullptr);
19294 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19295 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19296
19297 m_errorMonitor->VerifyNotFound();
19298}
19299
19300// This is a positive test. No errors should be generated.
19301TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19302
19303 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19304 "on the same queue, the second having a fence, followed "
19305 "by a WaitForFences call.");
19306
19307 m_errorMonitor->ExpectSuccess();
19308
19309 ASSERT_NO_FATAL_FAILURE(InitState());
19310 VkFence fence;
19311 VkFenceCreateInfo fence_create_info{};
19312 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19313 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19314
19315 VkCommandPool command_pool;
19316 VkCommandPoolCreateInfo pool_create_info{};
19317 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19318 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19319 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19320 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19321
19322 VkCommandBuffer command_buffer[2];
19323 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19324 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19325 command_buffer_allocate_info.commandPool = command_pool;
19326 command_buffer_allocate_info.commandBufferCount = 2;
19327 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19328 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19329
19330 {
19331 VkCommandBufferBeginInfo begin_info{};
19332 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19333 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19334
19335 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19336 nullptr, 0, nullptr, 0, nullptr);
19337
19338 VkViewport viewport{};
19339 viewport.maxDepth = 1.0f;
19340 viewport.minDepth = 0.0f;
19341 viewport.width = 512;
19342 viewport.height = 512;
19343 viewport.x = 0;
19344 viewport.y = 0;
19345 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19346 vkEndCommandBuffer(command_buffer[0]);
19347 }
19348 {
19349 VkCommandBufferBeginInfo begin_info{};
19350 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19351 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19352
19353 VkViewport viewport{};
19354 viewport.maxDepth = 1.0f;
19355 viewport.minDepth = 0.0f;
19356 viewport.width = 512;
19357 viewport.height = 512;
19358 viewport.x = 0;
19359 viewport.y = 0;
19360 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19361 vkEndCommandBuffer(command_buffer[1]);
19362 }
19363 {
19364 VkSubmitInfo submit_info{};
19365 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19366 submit_info.commandBufferCount = 1;
19367 submit_info.pCommandBuffers = &command_buffer[0];
19368 submit_info.signalSemaphoreCount = 0;
19369 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19370 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19371 }
19372 {
19373 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19374 VkSubmitInfo submit_info{};
19375 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19376 submit_info.commandBufferCount = 1;
19377 submit_info.pCommandBuffers = &command_buffer[1];
19378 submit_info.waitSemaphoreCount = 0;
19379 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19380 submit_info.pWaitDstStageMask = flags;
19381 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19382 }
19383
19384 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19385
19386 vkDestroyFence(m_device->device(), fence, 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, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19395
19396 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19397 "QueueSubmit call followed by a WaitForFences call.");
19398 ASSERT_NO_FATAL_FAILURE(InitState());
19399
19400 m_errorMonitor->ExpectSuccess();
19401
19402 VkFence fence;
19403 VkFenceCreateInfo fence_create_info{};
19404 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19405 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19406
19407 VkSemaphore semaphore;
19408 VkSemaphoreCreateInfo semaphore_create_info{};
19409 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19410 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19411
19412 VkCommandPool command_pool;
19413 VkCommandPoolCreateInfo pool_create_info{};
19414 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19415 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19416 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19417 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19418
19419 VkCommandBuffer command_buffer[2];
19420 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19421 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19422 command_buffer_allocate_info.commandPool = command_pool;
19423 command_buffer_allocate_info.commandBufferCount = 2;
19424 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19425 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19426
19427 {
19428 VkCommandBufferBeginInfo begin_info{};
19429 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19430 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19431
19432 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19433 nullptr, 0, nullptr, 0, nullptr);
19434
19435 VkViewport viewport{};
19436 viewport.maxDepth = 1.0f;
19437 viewport.minDepth = 0.0f;
19438 viewport.width = 512;
19439 viewport.height = 512;
19440 viewport.x = 0;
19441 viewport.y = 0;
19442 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19443 vkEndCommandBuffer(command_buffer[0]);
19444 }
19445 {
19446 VkCommandBufferBeginInfo begin_info{};
19447 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19448 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19449
19450 VkViewport viewport{};
19451 viewport.maxDepth = 1.0f;
19452 viewport.minDepth = 0.0f;
19453 viewport.width = 512;
19454 viewport.height = 512;
19455 viewport.x = 0;
19456 viewport.y = 0;
19457 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19458 vkEndCommandBuffer(command_buffer[1]);
19459 }
19460 {
19461 VkSubmitInfo submit_info[2];
19462 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19463
19464 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19465 submit_info[0].pNext = NULL;
19466 submit_info[0].commandBufferCount = 1;
19467 submit_info[0].pCommandBuffers = &command_buffer[0];
19468 submit_info[0].signalSemaphoreCount = 1;
19469 submit_info[0].pSignalSemaphores = &semaphore;
19470 submit_info[0].waitSemaphoreCount = 0;
19471 submit_info[0].pWaitSemaphores = NULL;
19472 submit_info[0].pWaitDstStageMask = 0;
19473
19474 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19475 submit_info[1].pNext = NULL;
19476 submit_info[1].commandBufferCount = 1;
19477 submit_info[1].pCommandBuffers = &command_buffer[1];
19478 submit_info[1].waitSemaphoreCount = 1;
19479 submit_info[1].pWaitSemaphores = &semaphore;
19480 submit_info[1].pWaitDstStageMask = flags;
19481 submit_info[1].signalSemaphoreCount = 0;
19482 submit_info[1].pSignalSemaphores = NULL;
19483 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19484 }
19485
19486 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19487
19488 vkDestroyFence(m_device->device(), fence, nullptr);
19489 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19490 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19491 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19492
19493 m_errorMonitor->VerifyNotFound();
19494}
19495
19496TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19497 m_errorMonitor->ExpectSuccess();
19498
19499 ASSERT_NO_FATAL_FAILURE(InitState());
19500 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19501
Tony Barbour552f6c02016-12-21 14:34:07 -070019502 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019503
19504 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19505 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19506 m_errorMonitor->VerifyNotFound();
19507 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19508 m_errorMonitor->VerifyNotFound();
19509 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19510 m_errorMonitor->VerifyNotFound();
19511
19512 m_commandBuffer->EndCommandBuffer();
19513 m_errorMonitor->VerifyNotFound();
19514}
19515
19516TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19517 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19518 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19519 "has a valid layout, and a second subpass then uses a "
19520 "valid *READ_ONLY* layout.");
19521 m_errorMonitor->ExpectSuccess();
19522 ASSERT_NO_FATAL_FAILURE(InitState());
19523
19524 VkAttachmentReference attach[2] = {};
19525 attach[0].attachment = 0;
19526 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19527 attach[1].attachment = 0;
19528 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19529 VkSubpassDescription subpasses[2] = {};
19530 // First subpass clears DS attach on load
19531 subpasses[0].pDepthStencilAttachment = &attach[0];
19532 // 2nd subpass reads in DS as input attachment
19533 subpasses[1].inputAttachmentCount = 1;
19534 subpasses[1].pInputAttachments = &attach[1];
19535 VkAttachmentDescription attach_desc = {};
19536 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19537 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19538 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19539 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19540 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19541 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19542 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19543 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19544 VkRenderPassCreateInfo rpci = {};
19545 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19546 rpci.attachmentCount = 1;
19547 rpci.pAttachments = &attach_desc;
19548 rpci.subpassCount = 2;
19549 rpci.pSubpasses = subpasses;
19550
19551 // Now create RenderPass and verify no errors
19552 VkRenderPass rp;
19553 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19554 m_errorMonitor->VerifyNotFound();
19555
19556 vkDestroyRenderPass(m_device->device(), rp, NULL);
19557}
19558
19559TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19560 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19561 "as vertex attributes");
19562 m_errorMonitor->ExpectSuccess();
19563
19564 ASSERT_NO_FATAL_FAILURE(InitState());
19565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19566
19567 VkVertexInputBindingDescription input_binding;
19568 memset(&input_binding, 0, sizeof(input_binding));
19569
19570 VkVertexInputAttributeDescription input_attribs[2];
19571 memset(input_attribs, 0, sizeof(input_attribs));
19572
19573 for (int i = 0; i < 2; i++) {
19574 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19575 input_attribs[i].location = i;
19576 }
19577
19578 char const *vsSource = "#version 450\n"
19579 "\n"
19580 "layout(location=0) in mat2x4 x;\n"
19581 "out gl_PerVertex {\n"
19582 " vec4 gl_Position;\n"
19583 "};\n"
19584 "void main(){\n"
19585 " gl_Position = x[0] + x[1];\n"
19586 "}\n";
19587 char const *fsSource = "#version 450\n"
19588 "\n"
19589 "layout(location=0) out vec4 color;\n"
19590 "void main(){\n"
19591 " color = vec4(1);\n"
19592 "}\n";
19593
19594 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19595 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19596
19597 VkPipelineObj pipe(m_device);
19598 pipe.AddColorAttachment();
19599 pipe.AddShader(&vs);
19600 pipe.AddShader(&fs);
19601
19602 pipe.AddVertexInputBindings(&input_binding, 1);
19603 pipe.AddVertexInputAttribs(input_attribs, 2);
19604
19605 VkDescriptorSetObj descriptorSet(m_device);
19606 descriptorSet.AppendDummy();
19607 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19608
19609 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19610
19611 /* expect success */
19612 m_errorMonitor->VerifyNotFound();
19613}
19614
19615TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19616 m_errorMonitor->ExpectSuccess();
19617
19618 ASSERT_NO_FATAL_FAILURE(InitState());
19619 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19620
19621 VkVertexInputBindingDescription input_binding;
19622 memset(&input_binding, 0, sizeof(input_binding));
19623
19624 VkVertexInputAttributeDescription input_attribs[2];
19625 memset(input_attribs, 0, sizeof(input_attribs));
19626
19627 for (int i = 0; i < 2; i++) {
19628 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19629 input_attribs[i].location = i;
19630 }
19631
19632 char const *vsSource = "#version 450\n"
19633 "\n"
19634 "layout(location=0) in vec4 x[2];\n"
19635 "out gl_PerVertex {\n"
19636 " vec4 gl_Position;\n"
19637 "};\n"
19638 "void main(){\n"
19639 " gl_Position = x[0] + x[1];\n"
19640 "}\n";
19641 char const *fsSource = "#version 450\n"
19642 "\n"
19643 "layout(location=0) out vec4 color;\n"
19644 "void main(){\n"
19645 " color = vec4(1);\n"
19646 "}\n";
19647
19648 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19649 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19650
19651 VkPipelineObj pipe(m_device);
19652 pipe.AddColorAttachment();
19653 pipe.AddShader(&vs);
19654 pipe.AddShader(&fs);
19655
19656 pipe.AddVertexInputBindings(&input_binding, 1);
19657 pipe.AddVertexInputAttribs(input_attribs, 2);
19658
19659 VkDescriptorSetObj descriptorSet(m_device);
19660 descriptorSet.AppendDummy();
19661 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19662
19663 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19664
19665 m_errorMonitor->VerifyNotFound();
19666}
19667
19668TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19669 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19670 "through multiple vertex shader inputs, each consuming a different "
19671 "subset of the components.");
19672 m_errorMonitor->ExpectSuccess();
19673
19674 ASSERT_NO_FATAL_FAILURE(InitState());
19675 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19676
19677 VkVertexInputBindingDescription input_binding;
19678 memset(&input_binding, 0, sizeof(input_binding));
19679
19680 VkVertexInputAttributeDescription input_attribs[3];
19681 memset(input_attribs, 0, sizeof(input_attribs));
19682
19683 for (int i = 0; i < 3; i++) {
19684 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19685 input_attribs[i].location = i;
19686 }
19687
19688 char const *vsSource = "#version 450\n"
19689 "\n"
19690 "layout(location=0) in vec4 x;\n"
19691 "layout(location=1) in vec3 y1;\n"
19692 "layout(location=1, component=3) in float y2;\n"
19693 "layout(location=2) in vec4 z;\n"
19694 "out gl_PerVertex {\n"
19695 " vec4 gl_Position;\n"
19696 "};\n"
19697 "void main(){\n"
19698 " gl_Position = x + vec4(y1, y2) + z;\n"
19699 "}\n";
19700 char const *fsSource = "#version 450\n"
19701 "\n"
19702 "layout(location=0) out vec4 color;\n"
19703 "void main(){\n"
19704 " color = vec4(1);\n"
19705 "}\n";
19706
19707 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19708 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19709
19710 VkPipelineObj pipe(m_device);
19711 pipe.AddColorAttachment();
19712 pipe.AddShader(&vs);
19713 pipe.AddShader(&fs);
19714
19715 pipe.AddVertexInputBindings(&input_binding, 1);
19716 pipe.AddVertexInputAttribs(input_attribs, 3);
19717
19718 VkDescriptorSetObj descriptorSet(m_device);
19719 descriptorSet.AppendDummy();
19720 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19721
19722 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19723
19724 m_errorMonitor->VerifyNotFound();
19725}
19726
19727TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19728 m_errorMonitor->ExpectSuccess();
19729
19730 ASSERT_NO_FATAL_FAILURE(InitState());
19731 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19732
19733 char const *vsSource = "#version 450\n"
19734 "out gl_PerVertex {\n"
19735 " vec4 gl_Position;\n"
19736 "};\n"
19737 "void main(){\n"
19738 " gl_Position = vec4(0);\n"
19739 "}\n";
19740 char const *fsSource = "#version 450\n"
19741 "\n"
19742 "layout(location=0) out vec4 color;\n"
19743 "void main(){\n"
19744 " color = vec4(1);\n"
19745 "}\n";
19746
19747 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19748 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19749
19750 VkPipelineObj pipe(m_device);
19751 pipe.AddColorAttachment();
19752 pipe.AddShader(&vs);
19753 pipe.AddShader(&fs);
19754
19755 VkDescriptorSetObj descriptorSet(m_device);
19756 descriptorSet.AppendDummy();
19757 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19758
19759 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19760
19761 m_errorMonitor->VerifyNotFound();
19762}
19763
19764TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19765 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19766 "set out in 14.1.3: fundamental type must match, and producer side must "
19767 "have at least as many components");
19768 m_errorMonitor->ExpectSuccess();
19769
19770 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19771
19772 ASSERT_NO_FATAL_FAILURE(InitState());
19773 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19774
19775 char const *vsSource = "#version 450\n"
19776 "out gl_PerVertex {\n"
19777 " vec4 gl_Position;\n"
19778 "};\n"
19779 "layout(location=0) out vec3 x;\n"
19780 "layout(location=1) out ivec3 y;\n"
19781 "layout(location=2) out vec3 z;\n"
19782 "void main(){\n"
19783 " gl_Position = vec4(0);\n"
19784 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19785 "}\n";
19786 char const *fsSource = "#version 450\n"
19787 "\n"
19788 "layout(location=0) out vec4 color;\n"
19789 "layout(location=0) in float x;\n"
19790 "layout(location=1) flat in int y;\n"
19791 "layout(location=2) in vec2 z;\n"
19792 "void main(){\n"
19793 " color = vec4(1 + x + y + z.x);\n"
19794 "}\n";
19795
19796 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19797 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19798
19799 VkPipelineObj pipe(m_device);
19800 pipe.AddColorAttachment();
19801 pipe.AddShader(&vs);
19802 pipe.AddShader(&fs);
19803
19804 VkDescriptorSetObj descriptorSet(m_device);
19805 descriptorSet.AppendDummy();
19806 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19807
19808 VkResult err = VK_SUCCESS;
19809 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19810 ASSERT_VK_SUCCESS(err);
19811
19812 m_errorMonitor->VerifyNotFound();
19813}
19814
19815TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19816 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19817 "passed between the TCS and TES stages");
19818 m_errorMonitor->ExpectSuccess();
19819
19820 ASSERT_NO_FATAL_FAILURE(InitState());
19821 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19822
19823 if (!m_device->phy().features().tessellationShader) {
19824 printf("Device does not support tessellation shaders; skipped.\n");
19825 return;
19826 }
19827
19828 char const *vsSource = "#version 450\n"
19829 "void main(){}\n";
19830 char const *tcsSource = "#version 450\n"
19831 "layout(location=0) out int x[];\n"
19832 "layout(vertices=3) out;\n"
19833 "void main(){\n"
19834 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19835 " gl_TessLevelInner[0] = 1;\n"
19836 " x[gl_InvocationID] = gl_InvocationID;\n"
19837 "}\n";
19838 char const *tesSource = "#version 450\n"
19839 "layout(triangles, equal_spacing, cw) in;\n"
19840 "layout(location=0) in int x[];\n"
19841 "out gl_PerVertex { vec4 gl_Position; };\n"
19842 "void main(){\n"
19843 " gl_Position.xyz = gl_TessCoord;\n"
19844 " gl_Position.w = x[0] + x[1] + x[2];\n"
19845 "}\n";
19846 char const *fsSource = "#version 450\n"
19847 "layout(location=0) out vec4 color;\n"
19848 "void main(){\n"
19849 " color = vec4(1);\n"
19850 "}\n";
19851
19852 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19853 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19854 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19855 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19856
19857 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19858 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19859
19860 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19861
19862 VkPipelineObj pipe(m_device);
19863 pipe.SetInputAssembly(&iasci);
19864 pipe.SetTessellation(&tsci);
19865 pipe.AddColorAttachment();
19866 pipe.AddShader(&vs);
19867 pipe.AddShader(&tcs);
19868 pipe.AddShader(&tes);
19869 pipe.AddShader(&fs);
19870
19871 VkDescriptorSetObj descriptorSet(m_device);
19872 descriptorSet.AppendDummy();
19873 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19874
19875 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19876
19877 m_errorMonitor->VerifyNotFound();
19878}
19879
19880TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19881 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19882 "interface block passed into the geometry shader. This "
19883 "is interesting because the 'extra' array level is not "
19884 "present on the member type, but on the block instance.");
19885 m_errorMonitor->ExpectSuccess();
19886
19887 ASSERT_NO_FATAL_FAILURE(InitState());
19888 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19889
19890 if (!m_device->phy().features().geometryShader) {
19891 printf("Device does not support geometry shaders; skipped.\n");
19892 return;
19893 }
19894
19895 char const *vsSource = "#version 450\n"
19896 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19897 "void main(){\n"
19898 " vs_out.x = vec4(1);\n"
19899 "}\n";
19900 char const *gsSource = "#version 450\n"
19901 "layout(triangles) in;\n"
19902 "layout(triangle_strip, max_vertices=3) out;\n"
19903 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19904 "out gl_PerVertex { vec4 gl_Position; };\n"
19905 "void main() {\n"
19906 " gl_Position = gs_in[0].x;\n"
19907 " EmitVertex();\n"
19908 "}\n";
19909 char const *fsSource = "#version 450\n"
19910 "layout(location=0) out vec4 color;\n"
19911 "void main(){\n"
19912 " color = vec4(1);\n"
19913 "}\n";
19914
19915 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19916 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19917 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19918
19919 VkPipelineObj pipe(m_device);
19920 pipe.AddColorAttachment();
19921 pipe.AddShader(&vs);
19922 pipe.AddShader(&gs);
19923 pipe.AddShader(&fs);
19924
19925 VkDescriptorSetObj descriptorSet(m_device);
19926 descriptorSet.AppendDummy();
19927 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19928
19929 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19930
19931 m_errorMonitor->VerifyNotFound();
19932}
19933
19934TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19935 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19936 "attributes. This is interesting because they consume multiple "
19937 "locations.");
19938 m_errorMonitor->ExpectSuccess();
19939
19940 ASSERT_NO_FATAL_FAILURE(InitState());
19941 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19942
19943 if (!m_device->phy().features().shaderFloat64) {
19944 printf("Device does not support 64bit vertex attributes; skipped.\n");
19945 return;
19946 }
19947
19948 VkVertexInputBindingDescription input_bindings[1];
19949 memset(input_bindings, 0, sizeof(input_bindings));
19950
19951 VkVertexInputAttributeDescription input_attribs[4];
19952 memset(input_attribs, 0, sizeof(input_attribs));
19953 input_attribs[0].location = 0;
19954 input_attribs[0].offset = 0;
19955 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19956 input_attribs[1].location = 2;
19957 input_attribs[1].offset = 32;
19958 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19959 input_attribs[2].location = 4;
19960 input_attribs[2].offset = 64;
19961 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19962 input_attribs[3].location = 6;
19963 input_attribs[3].offset = 96;
19964 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19965
19966 char const *vsSource = "#version 450\n"
19967 "\n"
19968 "layout(location=0) in dmat4 x;\n"
19969 "out gl_PerVertex {\n"
19970 " vec4 gl_Position;\n"
19971 "};\n"
19972 "void main(){\n"
19973 " gl_Position = vec4(x[0][0]);\n"
19974 "}\n";
19975 char const *fsSource = "#version 450\n"
19976 "\n"
19977 "layout(location=0) out vec4 color;\n"
19978 "void main(){\n"
19979 " color = vec4(1);\n"
19980 "}\n";
19981
19982 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19983 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19984
19985 VkPipelineObj pipe(m_device);
19986 pipe.AddColorAttachment();
19987 pipe.AddShader(&vs);
19988 pipe.AddShader(&fs);
19989
19990 pipe.AddVertexInputBindings(input_bindings, 1);
19991 pipe.AddVertexInputAttribs(input_attribs, 4);
19992
19993 VkDescriptorSetObj descriptorSet(m_device);
19994 descriptorSet.AppendDummy();
19995 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19996
19997 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19998
19999 m_errorMonitor->VerifyNotFound();
20000}
20001
20002TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20003 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20004 m_errorMonitor->ExpectSuccess();
20005
20006 ASSERT_NO_FATAL_FAILURE(InitState());
20007
20008 char const *vsSource = "#version 450\n"
20009 "\n"
20010 "out gl_PerVertex {\n"
20011 " vec4 gl_Position;\n"
20012 "};\n"
20013 "void main(){\n"
20014 " gl_Position = vec4(1);\n"
20015 "}\n";
20016 char const *fsSource = "#version 450\n"
20017 "\n"
20018 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20019 "layout(location=0) out vec4 color;\n"
20020 "void main() {\n"
20021 " color = subpassLoad(x);\n"
20022 "}\n";
20023
20024 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20025 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20026
20027 VkPipelineObj pipe(m_device);
20028 pipe.AddShader(&vs);
20029 pipe.AddShader(&fs);
20030 pipe.AddColorAttachment();
20031 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20032
20033 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
20034 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
20035 VkDescriptorSetLayout dsl;
20036 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20037 ASSERT_VK_SUCCESS(err);
20038
20039 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20040 VkPipelineLayout pl;
20041 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20042 ASSERT_VK_SUCCESS(err);
20043
20044 VkAttachmentDescription descs[2] = {
20045 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20046 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20047 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
20048 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20049 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
20050 };
20051 VkAttachmentReference color = {
20052 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20053 };
20054 VkAttachmentReference input = {
20055 1, VK_IMAGE_LAYOUT_GENERAL,
20056 };
20057
20058 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
20059
20060 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
20061 VkRenderPass rp;
20062 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20063 ASSERT_VK_SUCCESS(err);
20064
20065 // should be OK. would go wrong here if it's going to...
20066 pipe.CreateVKPipeline(pl, rp);
20067
20068 m_errorMonitor->VerifyNotFound();
20069
20070 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20071 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20072 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20073}
20074
20075TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
20076 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
20077 "descriptor-backed resource which is not provided, but the shader does not "
20078 "statically use it. This is interesting because it requires compute pipelines "
20079 "to have a proper descriptor use walk, which they didn't for some time.");
20080 m_errorMonitor->ExpectSuccess();
20081
20082 ASSERT_NO_FATAL_FAILURE(InitState());
20083
20084 char const *csSource = "#version 450\n"
20085 "\n"
20086 "layout(local_size_x=1) in;\n"
20087 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20088 "void main(){\n"
20089 " // x is not used.\n"
20090 "}\n";
20091
20092 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20093
20094 VkDescriptorSetObj descriptorSet(m_device);
20095 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20096
20097 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20098 nullptr,
20099 0,
20100 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20101 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20102 descriptorSet.GetPipelineLayout(),
20103 VK_NULL_HANDLE,
20104 -1 };
20105
20106 VkPipeline pipe;
20107 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20108
20109 m_errorMonitor->VerifyNotFound();
20110
20111 if (err == VK_SUCCESS) {
20112 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20113 }
20114}
20115
20116TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
20117 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20118 "sampler portion of a combined image + sampler");
20119 m_errorMonitor->ExpectSuccess();
20120
20121 ASSERT_NO_FATAL_FAILURE(InitState());
20122
20123 VkDescriptorSetLayoutBinding bindings[] = {
20124 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20125 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20126 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20127 };
20128 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20129 VkDescriptorSetLayout dsl;
20130 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20131 ASSERT_VK_SUCCESS(err);
20132
20133 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20134 VkPipelineLayout pl;
20135 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20136 ASSERT_VK_SUCCESS(err);
20137
20138 char const *csSource = "#version 450\n"
20139 "\n"
20140 "layout(local_size_x=1) in;\n"
20141 "layout(set=0, binding=0) uniform sampler s;\n"
20142 "layout(set=0, binding=1) uniform texture2D t;\n"
20143 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20144 "void main() {\n"
20145 " x = texture(sampler2D(t, s), vec2(0));\n"
20146 "}\n";
20147 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20148
20149 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20150 nullptr,
20151 0,
20152 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20153 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20154 pl,
20155 VK_NULL_HANDLE,
20156 -1 };
20157
20158 VkPipeline pipe;
20159 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20160
20161 m_errorMonitor->VerifyNotFound();
20162
20163 if (err == VK_SUCCESS) {
20164 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20165 }
20166
20167 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20168 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20169}
20170
20171TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
20172 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20173 "image portion of a combined image + sampler");
20174 m_errorMonitor->ExpectSuccess();
20175
20176 ASSERT_NO_FATAL_FAILURE(InitState());
20177
20178 VkDescriptorSetLayoutBinding bindings[] = {
20179 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20180 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20181 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20182 };
20183 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20184 VkDescriptorSetLayout dsl;
20185 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20186 ASSERT_VK_SUCCESS(err);
20187
20188 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20189 VkPipelineLayout pl;
20190 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20191 ASSERT_VK_SUCCESS(err);
20192
20193 char const *csSource = "#version 450\n"
20194 "\n"
20195 "layout(local_size_x=1) in;\n"
20196 "layout(set=0, binding=0) uniform texture2D t;\n"
20197 "layout(set=0, binding=1) uniform sampler s;\n"
20198 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20199 "void main() {\n"
20200 " x = texture(sampler2D(t, s), vec2(0));\n"
20201 "}\n";
20202 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20203
20204 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20205 nullptr,
20206 0,
20207 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20208 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20209 pl,
20210 VK_NULL_HANDLE,
20211 -1 };
20212
20213 VkPipeline pipe;
20214 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20215
20216 m_errorMonitor->VerifyNotFound();
20217
20218 if (err == VK_SUCCESS) {
20219 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20220 }
20221
20222 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20223 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20224}
20225
20226TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
20227 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
20228 "both the sampler and the image of a combined image+sampler "
20229 "but via separate variables");
20230 m_errorMonitor->ExpectSuccess();
20231
20232 ASSERT_NO_FATAL_FAILURE(InitState());
20233
20234 VkDescriptorSetLayoutBinding bindings[] = {
20235 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20236 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20237 };
20238 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
20239 VkDescriptorSetLayout dsl;
20240 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20241 ASSERT_VK_SUCCESS(err);
20242
20243 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20244 VkPipelineLayout pl;
20245 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20246 ASSERT_VK_SUCCESS(err);
20247
20248 char const *csSource = "#version 450\n"
20249 "\n"
20250 "layout(local_size_x=1) in;\n"
20251 "layout(set=0, binding=0) uniform texture2D t;\n"
20252 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20253 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20254 "void main() {\n"
20255 " x = texture(sampler2D(t, s), vec2(0));\n"
20256 "}\n";
20257 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20258
20259 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20260 nullptr,
20261 0,
20262 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20263 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20264 pl,
20265 VK_NULL_HANDLE,
20266 -1 };
20267
20268 VkPipeline pipe;
20269 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20270
20271 m_errorMonitor->VerifyNotFound();
20272
20273 if (err == VK_SUCCESS) {
20274 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20275 }
20276
20277 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20278 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20279}
20280
20281TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20282 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20283
20284 ASSERT_NO_FATAL_FAILURE(InitState());
20285
20286 // Positive test to check parameter_validation and unique_objects support
20287 // for NV_dedicated_allocation
20288 uint32_t extension_count = 0;
20289 bool supports_nv_dedicated_allocation = false;
20290 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20291 ASSERT_VK_SUCCESS(err);
20292
20293 if (extension_count > 0) {
20294 std::vector<VkExtensionProperties> available_extensions(extension_count);
20295
20296 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20297 ASSERT_VK_SUCCESS(err);
20298
20299 for (const auto &extension_props : available_extensions) {
20300 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20301 supports_nv_dedicated_allocation = true;
20302 }
20303 }
20304 }
20305
20306 if (supports_nv_dedicated_allocation) {
20307 m_errorMonitor->ExpectSuccess();
20308
20309 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20310 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20311 dedicated_buffer_create_info.pNext = nullptr;
20312 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20313
20314 uint32_t queue_family_index = 0;
20315 VkBufferCreateInfo buffer_create_info = {};
20316 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20317 buffer_create_info.pNext = &dedicated_buffer_create_info;
20318 buffer_create_info.size = 1024;
20319 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20320 buffer_create_info.queueFamilyIndexCount = 1;
20321 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20322
20323 VkBuffer buffer;
20324 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20325 ASSERT_VK_SUCCESS(err);
20326
20327 VkMemoryRequirements memory_reqs;
20328 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20329
20330 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20331 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20332 dedicated_memory_info.pNext = nullptr;
20333 dedicated_memory_info.buffer = buffer;
20334 dedicated_memory_info.image = VK_NULL_HANDLE;
20335
20336 VkMemoryAllocateInfo memory_info = {};
20337 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20338 memory_info.pNext = &dedicated_memory_info;
20339 memory_info.allocationSize = memory_reqs.size;
20340
20341 bool pass;
20342 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20343 ASSERT_TRUE(pass);
20344
20345 VkDeviceMemory buffer_memory;
20346 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20347 ASSERT_VK_SUCCESS(err);
20348
20349 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20350 ASSERT_VK_SUCCESS(err);
20351
20352 vkDestroyBuffer(m_device->device(), buffer, NULL);
20353 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20354
20355 m_errorMonitor->VerifyNotFound();
20356 }
20357}
20358
20359TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20360 VkResult err;
20361
20362 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20363
20364 ASSERT_NO_FATAL_FAILURE(InitState());
20365 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20366
20367 std::vector<const char *> device_extension_names;
20368 auto features = m_device->phy().features();
20369 // Artificially disable support for non-solid fill modes
20370 features.fillModeNonSolid = false;
20371 // The sacrificial device object
20372 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20373
20374 VkRenderpassObj render_pass(&test_device);
20375
20376 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20377 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20378 pipeline_layout_ci.setLayoutCount = 0;
20379 pipeline_layout_ci.pSetLayouts = NULL;
20380
20381 VkPipelineLayout pipeline_layout;
20382 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20383 ASSERT_VK_SUCCESS(err);
20384
20385 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20386 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20387 rs_ci.pNext = nullptr;
20388 rs_ci.lineWidth = 1.0f;
20389 rs_ci.rasterizerDiscardEnable = true;
20390
20391 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20392 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20393
20394 // Set polygonMode=FILL. No error is expected
20395 m_errorMonitor->ExpectSuccess();
20396 {
20397 VkPipelineObj pipe(&test_device);
20398 pipe.AddShader(&vs);
20399 pipe.AddShader(&fs);
20400 pipe.AddColorAttachment();
20401 // Set polygonMode to a good value
20402 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20403 pipe.SetRasterization(&rs_ci);
20404 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20405 }
20406 m_errorMonitor->VerifyNotFound();
20407
20408 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20409}
20410
20411TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20412 VkResult err;
20413 ASSERT_NO_FATAL_FAILURE(InitState());
20414 ASSERT_NO_FATAL_FAILURE(InitViewport());
20415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20416
20417 VkPipelineLayout pipeline_layout;
20418 VkPushConstantRange pc_range = {};
20419 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20420 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20421 pipeline_layout_ci.pushConstantRangeCount = 1;
20422 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20423
20424 //
20425 // Check for invalid push constant ranges in pipeline layouts.
20426 //
20427 struct PipelineLayoutTestCase {
20428 VkPushConstantRange const range;
20429 char const *msg;
20430 };
20431
20432 // Check for overlapping ranges
20433 const uint32_t ranges_per_test = 5;
20434 struct OverlappingRangeTestCase {
20435 VkPushConstantRange const ranges[ranges_per_test];
20436 char const *msg;
20437 };
20438
20439 // Run some positive tests to make sure overlap checking in the layer is OK
20440 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20441 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20442 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20443 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20444 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20445 "" },
20446 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20447 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20448 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20449 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20450 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20451 "" } } };
20452 for (const auto &iter : overlapping_range_tests_pos) {
20453 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20454 m_errorMonitor->ExpectSuccess();
20455 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20456 m_errorMonitor->VerifyNotFound();
20457 if (VK_SUCCESS == err) {
20458 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20459 }
20460 }
20461
20462 //
20463 // CmdPushConstants tests
20464 //
20465 const uint8_t dummy_values[100] = {};
20466
Tony Barbour552f6c02016-12-21 14:34:07 -070020467 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020468
20469 // positive overlapping range tests with cmd
20470 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20471 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20472 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20473 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20474 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20475 } };
20476
20477 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20478 const VkPushConstantRange pc_range4[] = {
20479 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20480 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20481 };
20482
20483 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20484 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20485 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20486 ASSERT_VK_SUCCESS(err);
20487 for (const auto &iter : cmd_overlap_tests_pos) {
20488 m_errorMonitor->ExpectSuccess();
20489 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20490 iter.range.size, dummy_values);
20491 m_errorMonitor->VerifyNotFound();
20492 }
20493 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20494
Tony Barbour552f6c02016-12-21 14:34:07 -070020495 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020496}
20497
20498
20499
20500
20501
20502
20503
20504#if 0 // A few devices have issues with this test so disabling for now
20505TEST_F(VkPositiveLayerTest, LongFenceChain)
20506{
20507 m_errorMonitor->ExpectSuccess();
20508
20509 ASSERT_NO_FATAL_FAILURE(InitState());
20510 VkResult err;
20511
20512 std::vector<VkFence> fences;
20513
20514 const int chainLength = 32768;
20515
20516 for (int i = 0; i < chainLength; i++) {
20517 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20518 VkFence fence;
20519 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20520 ASSERT_VK_SUCCESS(err);
20521
20522 fences.push_back(fence);
20523
20524 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20525 0, nullptr, 0, nullptr };
20526 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20527 ASSERT_VK_SUCCESS(err);
20528
20529 }
20530
20531 // BOOM, stack overflow.
20532 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20533
20534 for (auto fence : fences)
20535 vkDestroyFence(m_device->device(), fence, nullptr);
20536
20537 m_errorMonitor->VerifyNotFound();
20538}
20539#endif
20540
20541
Cody Northrop1242dfd2016-07-13 17:24:59 -060020542#if defined(ANDROID) && defined(VALIDATION_APK)
20543static bool initialized = false;
20544static bool active = false;
20545
20546// Convert Intents to argv
20547// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020548std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020549 std::vector<std::string> args;
20550 JavaVM &vm = *app.activity->vm;
20551 JNIEnv *p_env;
20552 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20553 return args;
20554
20555 JNIEnv &env = *p_env;
20556 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020557 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020558 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020559 jmethodID get_string_extra_method =
20560 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020561 jvalue get_string_extra_args;
20562 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020563 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020564
20565 std::string args_str;
20566 if (extra_str) {
20567 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20568 args_str = extra_utf;
20569 env.ReleaseStringUTFChars(extra_str, extra_utf);
20570 env.DeleteLocalRef(extra_str);
20571 }
20572
20573 env.DeleteLocalRef(get_string_extra_args.l);
20574 env.DeleteLocalRef(intent);
20575 vm.DetachCurrentThread();
20576
20577 // split args_str
20578 std::stringstream ss(args_str);
20579 std::string arg;
20580 while (std::getline(ss, arg, ' ')) {
20581 if (!arg.empty())
20582 args.push_back(arg);
20583 }
20584
20585 return args;
20586}
20587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020588static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020590static void processCommand(struct android_app *app, int32_t cmd) {
20591 switch (cmd) {
20592 case APP_CMD_INIT_WINDOW: {
20593 if (app->window) {
20594 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020595 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020596 break;
20597 }
20598 case APP_CMD_GAINED_FOCUS: {
20599 active = true;
20600 break;
20601 }
20602 case APP_CMD_LOST_FOCUS: {
20603 active = false;
20604 break;
20605 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020606 }
20607}
20608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020609void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020610 app_dummy();
20611
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020612 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020613
20614 int vulkanSupport = InitVulkan();
20615 if (vulkanSupport == 0) {
20616 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20617 return;
20618 }
20619
20620 app->onAppCmd = processCommand;
20621 app->onInputEvent = processInput;
20622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020623 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020624 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020625 struct android_poll_source *source;
20626 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020627 if (source) {
20628 source->process(app, source);
20629 }
20630
20631 if (app->destroyRequested != 0) {
20632 VkTestFramework::Finish();
20633 return;
20634 }
20635 }
20636
20637 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020638 // Use the following key to send arguments to gtest, i.e.
20639 // --es args "--gtest_filter=-VkLayerTest.foo"
20640 const char key[] = "args";
20641 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020642
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020643 std::string filter = "";
20644 if (args.size() > 0) {
20645 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20646 filter += args[0];
20647 } else {
20648 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20649 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020650
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020651 int argc = 2;
20652 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20653 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020654
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020655 // Route output to files until we can override the gtest output
20656 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20657 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020659 ::testing::InitGoogleTest(&argc, argv);
20660 VkTestFramework::InitArgs(&argc, argv);
20661 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020662
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020663 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020664
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020665 if (result != 0) {
20666 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20667 } else {
20668 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20669 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020670
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020671 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020673 fclose(stdout);
20674 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020675
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020676 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020677
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020678 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020679 }
20680 }
20681}
20682#endif
20683
Tony Barbour300a6082015-04-07 13:44:53 -060020684int main(int argc, char **argv) {
20685 int result;
20686
Cody Northrop8e54a402016-03-08 22:25:52 -070020687#ifdef ANDROID
20688 int vulkanSupport = InitVulkan();
20689 if (vulkanSupport == 0)
20690 return 1;
20691#endif
20692
Tony Barbour300a6082015-04-07 13:44:53 -060020693 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020694 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020695
20696 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20697
20698 result = RUN_ALL_TESTS();
20699
Tony Barbour6918cd52015-04-09 12:58:51 -060020700 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020701 return result;
20702}