blob: 5f420f989fd0a880bb44176f675237f15b81f209 [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;
Rene Lindsay144e4842017-01-20 14:27:15 -07007927 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06007928
Mark Young47107952016-05-02 15:59:55 -06007929 // Check too low (line width of -1.0f).
7930 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06007931
7932 VkPipelineColorBlendAttachmentState att = {};
7933 att.blendEnable = VK_FALSE;
7934 att.colorWriteMask = 0xf;
7935
7936 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7937 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7938 cb_ci.pNext = nullptr;
7939 cb_ci.attachmentCount = 1;
7940 cb_ci.pAttachments = &att;
7941
7942 VkGraphicsPipelineCreateInfo gp_ci = {};
7943 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7944 gp_ci.stageCount = 2;
7945 gp_ci.pStages = shaderStages;
7946 gp_ci.pVertexInputState = &vi_ci;
7947 gp_ci.pInputAssemblyState = &ia_ci;
7948 gp_ci.pViewportState = &vp_state_ci;
7949 gp_ci.pRasterizationState = &rs_ci;
7950 gp_ci.pColorBlendState = &cb_ci;
7951 gp_ci.pDynamicState = &dyn_state_ci;
7952 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7953 gp_ci.layout = pipeline_layout;
7954 gp_ci.renderPass = renderPass();
7955
7956 VkPipelineCacheCreateInfo pc_ci = {};
7957 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7958
7959 VkPipeline pipeline;
7960 VkPipelineCache pipelineCache;
7961
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007962 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007963 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007964 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007965
7966 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007967 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007970
7971 // Check too high (line width of 65536.0f).
7972 rs_ci.lineWidth = 65536.0f;
7973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007975 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007976 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007977
7978 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06007979 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06007980
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007982
7983 dyn_state_ci.dynamicStateCount = 3;
7984
7985 rs_ci.lineWidth = 1.0f;
7986
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007987 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06007988 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007989 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07007990 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007991 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06007992
7993 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06007994 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06007995 m_errorMonitor->VerifyFound();
7996
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06007998
7999 // Check too high with dynamic setting.
8000 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8001 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008002 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008003
8004 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8005 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8006 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8007 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008008 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008009}
8010
Karl Schultz6addd812016-02-02 17:17:23 -07008011TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008012 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008014 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008015
8016 ASSERT_NO_FATAL_FAILURE(InitState());
8017 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008018
Tony Barbour552f6c02016-12-21 14:34:07 -07008019 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008020 // Don't care about RenderPass handle b/c error should be flagged before
8021 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008022 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008023
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008024 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008025}
8026
Karl Schultz6addd812016-02-02 17:17:23 -07008027TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008028 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8030 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008031
8032 ASSERT_NO_FATAL_FAILURE(InitState());
8033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008034
Tony Barbour552f6c02016-12-21 14:34:07 -07008035 m_commandBuffer->BeginCommandBuffer();
8036 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008037 // Just create a dummy Renderpass that's non-NULL so we can get to the
8038 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008039 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008040
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008041 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008042}
8043
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008044TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
8045 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is less than"
8046 "the number of renderPass attachments that use loadOp"
8047 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8048
8049 ASSERT_NO_FATAL_FAILURE(InitState());
8050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8051
8052 // Create a renderPass with a single attachment that uses loadOp CLEAR
8053 VkAttachmentReference attach = {};
8054 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8055 VkSubpassDescription subpass = {};
8056 subpass.inputAttachmentCount = 1;
8057 subpass.pInputAttachments = &attach;
8058 VkRenderPassCreateInfo rpci = {};
8059 rpci.subpassCount = 1;
8060 rpci.pSubpasses = &subpass;
8061 rpci.attachmentCount = 1;
8062 VkAttachmentDescription attach_desc = {};
8063 attach_desc.format = VK_FORMAT_UNDEFINED;
8064 // Set loadOp to CLEAR
8065 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8066 rpci.pAttachments = &attach_desc;
8067 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8068 VkRenderPass rp;
8069 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8070
8071 VkCommandBufferInheritanceInfo hinfo = {};
8072 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8073 hinfo.renderPass = VK_NULL_HANDLE;
8074 hinfo.subpass = 0;
8075 hinfo.framebuffer = VK_NULL_HANDLE;
8076 hinfo.occlusionQueryEnable = VK_FALSE;
8077 hinfo.queryFlags = 0;
8078 hinfo.pipelineStatistics = 0;
8079 VkCommandBufferBeginInfo info = {};
8080 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8081 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8082 info.pInheritanceInfo = &hinfo;
8083
8084 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8085 VkRenderPassBeginInfo rp_begin = {};
8086 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8087 rp_begin.pNext = NULL;
8088 rp_begin.renderPass = renderPass();
8089 rp_begin.framebuffer = framebuffer();
8090 rp_begin.clearValueCount = 0; // Should be 1
8091
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008093
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008094 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008095
8096 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008097
8098 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008099}
8100
Slawomir Cygan0808f392016-11-28 17:53:23 +01008101TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
8102 TEST_DESCRIPTION("Begin a renderPass where clearValueCount is greater than"
8103 "the number of renderPass attachments that use loadOp"
8104 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
8105
8106 ASSERT_NO_FATAL_FAILURE(InitState());
8107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8108
8109 // Create a renderPass with a single attachment that uses loadOp CLEAR
8110 VkAttachmentReference attach = {};
8111 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8112 VkSubpassDescription subpass = {};
8113 subpass.inputAttachmentCount = 1;
8114 subpass.pInputAttachments = &attach;
8115 VkRenderPassCreateInfo rpci = {};
8116 rpci.subpassCount = 1;
8117 rpci.pSubpasses = &subpass;
8118 rpci.attachmentCount = 1;
8119 VkAttachmentDescription attach_desc = {};
8120 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8121 // Set loadOp to CLEAR
8122 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8123 rpci.pAttachments = &attach_desc;
8124 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8125 VkRenderPass rp;
8126 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8127
8128 VkCommandBufferBeginInfo info = {};
8129 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8130 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8131
8132 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8133 VkRenderPassBeginInfo rp_begin = {};
8134 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8135 rp_begin.pNext = NULL;
8136 rp_begin.renderPass = renderPass();
8137 rp_begin.framebuffer = framebuffer();
8138 rp_begin.clearValueCount = 2; // Should be 1
8139
8140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " has a clearValueCount of"
8141 " 2 but only first 1 entries in pClearValues array are used");
8142
8143 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8144
8145 m_errorMonitor->VerifyFound();
8146
8147 vkDestroyRenderPass(m_device->device(), rp, NULL);
8148}
8149
8150
Cody Northrop3bb4d962016-05-09 16:15:57 -06008151TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
8152
8153 TEST_DESCRIPTION("End a command buffer with an active render pass");
8154
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8156 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008157
8158 ASSERT_NO_FATAL_FAILURE(InitState());
8159 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8160
Tony Barbour552f6c02016-12-21 14:34:07 -07008161 m_commandBuffer->BeginCommandBuffer();
8162 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8163 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008164
8165 m_errorMonitor->VerifyFound();
8166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008167 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8168 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008169}
8170
Karl Schultz6addd812016-02-02 17:17:23 -07008171TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008172 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8174 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008175
8176 ASSERT_NO_FATAL_FAILURE(InitState());
8177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008178
Tony Barbour552f6c02016-12-21 14:34:07 -07008179 m_commandBuffer->BeginCommandBuffer();
8180 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008181
8182 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008183 vk_testing::Buffer dstBuffer;
8184 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008185
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008186 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008187
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008188 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008189}
8190
Karl Schultz6addd812016-02-02 17:17:23 -07008191TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008192 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8194 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008195
8196 ASSERT_NO_FATAL_FAILURE(InitState());
8197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008198
Tony Barbour552f6c02016-12-21 14:34:07 -07008199 m_commandBuffer->BeginCommandBuffer();
8200 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008201
8202 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008203 vk_testing::Buffer dstBuffer;
8204 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008205
Karl Schultz6addd812016-02-02 17:17:23 -07008206 VkDeviceSize dstOffset = 0;
8207 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008208 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008209
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008210 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008211
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008212 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008213}
8214
Karl Schultz6addd812016-02-02 17:17:23 -07008215TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008216 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8218 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008219
8220 ASSERT_NO_FATAL_FAILURE(InitState());
8221 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008222
Tony Barbour552f6c02016-12-21 14:34:07 -07008223 m_commandBuffer->BeginCommandBuffer();
8224 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008225
Michael Lentine0a369f62016-02-03 16:51:46 -06008226 VkClearColorValue clear_color;
8227 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008228 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8229 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8230 const int32_t tex_width = 32;
8231 const int32_t tex_height = 32;
8232 VkImageCreateInfo image_create_info = {};
8233 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8234 image_create_info.pNext = NULL;
8235 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8236 image_create_info.format = tex_format;
8237 image_create_info.extent.width = tex_width;
8238 image_create_info.extent.height = tex_height;
8239 image_create_info.extent.depth = 1;
8240 image_create_info.mipLevels = 1;
8241 image_create_info.arrayLayers = 1;
8242 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8243 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8244 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008245
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008246 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008247 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008248
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008249 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008250
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008251 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008252
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008253 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008254}
8255
Karl Schultz6addd812016-02-02 17:17:23 -07008256TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008257 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8259 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008260
8261 ASSERT_NO_FATAL_FAILURE(InitState());
8262 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008263
Tony Barbour552f6c02016-12-21 14:34:07 -07008264 m_commandBuffer->BeginCommandBuffer();
8265 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008266
8267 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008268 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008269 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8270 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8271 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8272 image_create_info.extent.width = 64;
8273 image_create_info.extent.height = 64;
8274 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8275 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008276
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008277 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008278 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008279
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008280 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008281
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008282 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(),
Rene Lindsay8247f392017-01-18 13:35:47 -07008283 VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008284
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008285 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008286}
8287
Karl Schultz6addd812016-02-02 17:17:23 -07008288TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008289 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008290 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008291
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearAttachments(): This call "
8293 "must be issued inside an active "
8294 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008295
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008296 ASSERT_NO_FATAL_FAILURE(InitState());
8297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008298
8299 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008300 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008301 ASSERT_VK_SUCCESS(err);
8302
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008303 VkClearAttachment color_attachment;
8304 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8305 color_attachment.clearValue.color.float32[0] = 0;
8306 color_attachment.clearValue.color.float32[1] = 0;
8307 color_attachment.clearValue.color.float32[2] = 0;
8308 color_attachment.clearValue.color.float32[3] = 0;
8309 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008310 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008311 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008312
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008313 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008314}
8315
Chris Forbes3b97e932016-09-07 11:29:24 +12008316TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
8317 TEST_DESCRIPTION("Test that an error is produced when CmdNextSubpass is "
8318 "called too many times in a renderpass instance");
8319
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdNextSubpass(): Attempted to advance "
8321 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008322
8323 ASSERT_NO_FATAL_FAILURE(InitState());
8324 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8325
Tony Barbour552f6c02016-12-21 14:34:07 -07008326 m_commandBuffer->BeginCommandBuffer();
8327 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008328
8329 // error here.
8330 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8331 m_errorMonitor->VerifyFound();
8332
Tony Barbour552f6c02016-12-21 14:34:07 -07008333 m_commandBuffer->EndRenderPass();
8334 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008335}
8336
Chris Forbes6d624702016-09-07 13:57:05 +12008337TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
8338 TEST_DESCRIPTION("Test that an error is produced when CmdEndRenderPass is "
8339 "called before the final subpass has been reached");
8340
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdEndRenderPass(): Called before reaching "
8342 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008343
8344 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008345 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8346 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008347
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008348 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008349
8350 VkRenderPass rp;
8351 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8352 ASSERT_VK_SUCCESS(err);
8353
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008354 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008355
8356 VkFramebuffer fb;
8357 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8358 ASSERT_VK_SUCCESS(err);
8359
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008360 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008361
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008362 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 +12008363
8364 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8365
8366 // Error here.
8367 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8368 m_errorMonitor->VerifyFound();
8369
8370 // Clean up.
8371 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8372 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8373}
8374
Karl Schultz9e66a292016-04-21 15:57:51 -06008375TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8376 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8378 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008379
8380 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008381 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008382
8383 VkBufferMemoryBarrier buf_barrier = {};
8384 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8385 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8386 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8387 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8388 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8389 buf_barrier.buffer = VK_NULL_HANDLE;
8390 buf_barrier.offset = 0;
8391 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008392 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8393 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008394
8395 m_errorMonitor->VerifyFound();
8396}
8397
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008398TEST_F(VkLayerTest, InvalidBarriers) {
8399 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8400
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008402
8403 ASSERT_NO_FATAL_FAILURE(InitState());
8404 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8405
8406 VkMemoryBarrier mem_barrier = {};
8407 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8408 mem_barrier.pNext = NULL;
8409 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8410 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008411 m_commandBuffer->BeginCommandBuffer();
8412 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008413 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008414 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008415 &mem_barrier, 0, nullptr, 0, nullptr);
8416 m_errorMonitor->VerifyFound();
8417
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008419 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008420 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 -06008421 ASSERT_TRUE(image.initialized());
8422 VkImageMemoryBarrier img_barrier = {};
8423 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8424 img_barrier.pNext = NULL;
8425 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8426 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8427 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8428 // New layout can't be UNDEFINED
8429 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8430 img_barrier.image = image.handle();
8431 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8432 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8433 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8434 img_barrier.subresourceRange.baseArrayLayer = 0;
8435 img_barrier.subresourceRange.baseMipLevel = 0;
8436 img_barrier.subresourceRange.layerCount = 1;
8437 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008438 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8439 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008440 m_errorMonitor->VerifyFound();
8441 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8442
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the "
8444 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008445 // baseArrayLayer + layerCount must be <= image's arrayLayers
8446 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008447 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8448 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008449 m_errorMonitor->VerifyFound();
8450 img_barrier.subresourceRange.baseArrayLayer = 0;
8451
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008453 // baseMipLevel + levelCount must be <= image's mipLevels
8454 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008455 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8456 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008457 m_errorMonitor->VerifyFound();
8458 img_barrier.subresourceRange.baseMipLevel = 0;
8459
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008460 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 -06008461 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008462 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8463 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008464 VkBufferMemoryBarrier buf_barrier = {};
8465 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8466 buf_barrier.pNext = NULL;
8467 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8468 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8469 buf_barrier.buffer = buffer.handle();
8470 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8471 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8472 buf_barrier.offset = 0;
8473 buf_barrier.size = VK_WHOLE_SIZE;
8474 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008475 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8476 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008477 m_errorMonitor->VerifyFound();
8478 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8479
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008480 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008481 buf_barrier.offset = 257;
8482 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008483 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8484 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008485 m_errorMonitor->VerifyFound();
8486 buf_barrier.offset = 0;
8487
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008489 buf_barrier.size = 257;
8490 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8492 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008493 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008494
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008495 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008496 m_errorMonitor->SetDesiredFailureMsg(
8497 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008498 "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 -06008499 VkDepthStencilObj ds_image(m_device);
8500 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8501 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008502 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8503 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008504 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008505
8506 // Not having DEPTH or STENCIL set is an error
8507 img_barrier.subresourceRange.aspectMask = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008508 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8509 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008510 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07008511
8512 // Having anything other than DEPTH or STENCIL is an error
8513 m_errorMonitor->SetDesiredFailureMsg(
8514 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8515 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8516 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
8517 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8518 nullptr, 0, nullptr, 1, &img_barrier);
8519 m_errorMonitor->VerifyFound();
8520
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008521 // Now test depth-only
8522 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008523 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8524 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008525 VkDepthStencilObj d_image(m_device);
8526 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8527 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008528 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008529 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008530 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008531
8532 // DEPTH bit must be set
8533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8534 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8535 img_barrier.subresourceRange.aspectMask = 0;
8536 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8537 0, nullptr, 0, nullptr, 1, &img_barrier);
8538 m_errorMonitor->VerifyFound();
8539
8540 // No bits other than DEPTH may be set
8541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8542 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8543 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008544 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8545 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008546 m_errorMonitor->VerifyFound();
8547 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008548
8549 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008550 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8551 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8553 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008554 VkDepthStencilObj s_image(m_device);
8555 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8556 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008557 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008558 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008559 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008560 // Use of COLOR aspect on depth image is error
8561 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008562 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8563 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008564 m_errorMonitor->VerifyFound();
8565 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008566
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008567 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008568 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008569 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 -06008570 ASSERT_TRUE(c_image.initialized());
8571 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8572 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8573 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008574
8575 // COLOR bit must be set
8576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8577 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8578 img_barrier.subresourceRange.aspectMask = 0;
8579 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8580 nullptr, 0, nullptr, 1, &img_barrier);
8581 m_errorMonitor->VerifyFound();
8582
8583 // No bits other than COLOR may be set
8584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8585 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
8586 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008587 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8588 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008589 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008590
8591 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8592
8593 // Create command pool with incompatible queueflags
8594 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8595 uint32_t queue_family_index = UINT32_MAX;
8596 for (uint32_t i = 0; i < queue_props.size(); i++) {
8597 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8598 queue_family_index = i;
8599 break;
8600 }
8601 }
8602 if (queue_family_index == UINT32_MAX) {
8603 printf("No non-compute queue found; skipped.\n");
8604 return;
8605 }
8606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8607
8608 VkCommandPool command_pool;
8609 VkCommandPoolCreateInfo pool_create_info{};
8610 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8611 pool_create_info.queueFamilyIndex = queue_family_index;
8612 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8613 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8614
8615 // Allocate a command buffer
8616 VkCommandBuffer bad_command_buffer;
8617 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8618 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8619 command_buffer_allocate_info.commandPool = command_pool;
8620 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8621 command_buffer_allocate_info.commandBufferCount = 1;
8622 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8623
8624 VkCommandBufferBeginInfo cbbi = {};
8625 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8626 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8627 buf_barrier.offset = 0;
8628 buf_barrier.size = VK_WHOLE_SIZE;
8629 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8630 &buf_barrier, 0, nullptr);
8631 m_errorMonitor->VerifyFound();
8632
8633 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8634 vkEndCommandBuffer(bad_command_buffer);
8635 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8636 printf("The non-compute queue does not support graphics; skipped.\n");
8637 return;
8638 }
8639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8640 VkEvent event;
8641 VkEventCreateInfo event_create_info{};
8642 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8643 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8644 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8645 nullptr, 0, nullptr);
8646 m_errorMonitor->VerifyFound();
8647
8648 vkEndCommandBuffer(bad_command_buffer);
8649 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008650}
8651
Tony Barbour18ba25c2016-09-29 13:42:40 -06008652TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8653 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8654
8655 m_errorMonitor->SetDesiredFailureMsg(
8656 VK_DEBUG_REPORT_WARNING_BIT_EXT,
8657 "must have required access bit");
8658 ASSERT_NO_FATAL_FAILURE(InitState());
8659 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008660 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 -06008661 ASSERT_TRUE(image.initialized());
8662
8663 VkImageMemoryBarrier barrier = {};
8664 VkImageSubresourceRange range;
8665 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8666 barrier.srcAccessMask = 0;
8667 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8668 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8669 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8670 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8671 barrier.image = image.handle();
8672 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8673 range.baseMipLevel = 0;
8674 range.levelCount = 1;
8675 range.baseArrayLayer = 0;
8676 range.layerCount = 1;
8677 barrier.subresourceRange = range;
8678 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8679 cmdbuf.BeginCommandBuffer();
8680 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8681 &barrier);
8682 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8683 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8684 barrier.srcAccessMask = 0;
8685 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8686 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8687 &barrier);
8688
8689 m_errorMonitor->VerifyFound();
8690}
8691
Karl Schultz6addd812016-02-02 17:17:23 -07008692TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008693 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008694 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008695
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008697
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008698 ASSERT_NO_FATAL_FAILURE(InitState());
8699 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008700 uint32_t qfi = 0;
8701 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008702 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8703 buffCI.size = 1024;
8704 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8705 buffCI.queueFamilyIndexCount = 1;
8706 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008707
8708 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008709 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008710 ASSERT_VK_SUCCESS(err);
8711
Tony Barbour552f6c02016-12-21 14:34:07 -07008712 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008713 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008714 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8715 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008716 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008717 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008718
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008719 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008720
Chia-I Wuf7458c52015-10-26 21:10:41 +08008721 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008722}
8723
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008724TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8725 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008726 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8727 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8728 "of the indices specified when the device was created, via the "
8729 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008730
8731 ASSERT_NO_FATAL_FAILURE(InitState());
8732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8733 VkBufferCreateInfo buffCI = {};
8734 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8735 buffCI.size = 1024;
8736 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8737 buffCI.queueFamilyIndexCount = 1;
8738 // Introduce failure by specifying invalid queue_family_index
8739 uint32_t qfi = 777;
8740 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis24aab042016-03-24 10:54:18 -06008741 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008742
8743 VkBuffer ib;
8744 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8745
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008746 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008747 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008748}
8749
Karl Schultz6addd812016-02-02 17:17:23 -07008750TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -06008751TEST_DESCRIPTION("Attempt vkCmdExecuteCommands with a primary command buffer"
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008752 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008753
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008754 ASSERT_NO_FATAL_FAILURE(InitState());
8755 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008756
Chris Forbesf29a84f2016-10-06 18:39:28 +13008757 // An empty primary command buffer
8758 VkCommandBufferObj cb(m_device, m_commandPool);
8759 cb.BeginCommandBuffer();
8760 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008761
Chris Forbesf29a84f2016-10-06 18:39:28 +13008762 m_commandBuffer->BeginCommandBuffer();
8763 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8764 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008765
Chris Forbesf29a84f2016-10-06 18:39:28 +13008766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8767 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008768 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008769}
8770
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008771TEST_F(VkLayerTest, DSUsageBitsErrors) {
8772 TEST_DESCRIPTION("Attempt to update descriptor sets for images and buffers "
8773 "that do not have correct usage bits sets.");
8774 VkResult err;
8775
8776 ASSERT_NO_FATAL_FAILURE(InitState());
8777 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8778 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8779 ds_type_count[i].type = VkDescriptorType(i);
8780 ds_type_count[i].descriptorCount = 1;
8781 }
8782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8784 ds_pool_ci.pNext = NULL;
8785 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8786 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8787 ds_pool_ci.pPoolSizes = ds_type_count;
8788
8789 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008790 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008791 ASSERT_VK_SUCCESS(err);
8792
8793 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008794 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008795 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8796 dsl_binding[i].binding = 0;
8797 dsl_binding[i].descriptorType = VkDescriptorType(i);
8798 dsl_binding[i].descriptorCount = 1;
8799 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8800 dsl_binding[i].pImmutableSamplers = NULL;
8801 }
8802
8803 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8804 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8805 ds_layout_ci.pNext = NULL;
8806 ds_layout_ci.bindingCount = 1;
8807 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8808 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8809 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008810 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008811 ASSERT_VK_SUCCESS(err);
8812 }
8813 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8814 VkDescriptorSetAllocateInfo alloc_info = {};
8815 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8816 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8817 alloc_info.descriptorPool = ds_pool;
8818 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008819 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008820 ASSERT_VK_SUCCESS(err);
8821
8822 // Create a buffer & bufferView to be used for invalid updates
8823 VkBufferCreateInfo buff_ci = {};
8824 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8825 // This usage is not valid for any descriptor type
8826 buff_ci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
8827 buff_ci.size = 256;
8828 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8829 VkBuffer buffer;
8830 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8831 ASSERT_VK_SUCCESS(err);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008832 VkMemoryRequirements mem_reqs;
8833 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8834 VkMemoryAllocateInfo mem_alloc_info = {};
8835 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8836 mem_alloc_info.pNext = NULL;
8837 mem_alloc_info.memoryTypeIndex = 0;
8838 mem_alloc_info.allocationSize = mem_reqs.size;
8839 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
8840 if (!pass) {
8841 vkDestroyBuffer(m_device->device(), buffer, NULL);
8842 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8843 return;
8844 }
8845 VkDeviceMemory mem;
8846 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
8847 ASSERT_VK_SUCCESS(err);
8848 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
8849 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008850
8851 VkBufferViewCreateInfo buff_view_ci = {};
8852 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
8853 buff_view_ci.buffer = buffer;
8854 buff_view_ci.format = VK_FORMAT_R8_UNORM;
8855 buff_view_ci.range = VK_WHOLE_SIZE;
8856 VkBufferView buff_view;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008857 // 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 -06008858 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008859 ASSERT_VK_SUCCESS(err);
8860
8861 // Create an image to be used for invalid updates
8862 VkImageCreateInfo image_ci = {};
8863 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8864 image_ci.imageType = VK_IMAGE_TYPE_2D;
8865 image_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8866 image_ci.extent.width = 64;
8867 image_ci.extent.height = 64;
8868 image_ci.extent.depth = 1;
8869 image_ci.mipLevels = 1;
8870 image_ci.arrayLayers = 1;
8871 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
8872 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
8873 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
8874 // This usage is not valid for any descriptor type
8875 image_ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
8876 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
8877 VkImage image;
8878 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
8879 ASSERT_VK_SUCCESS(err);
8880 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008881 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008882
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008883 VkMemoryAllocateInfo mem_alloc = {};
8884 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8885 mem_alloc.pNext = NULL;
8886 mem_alloc.allocationSize = 0;
8887 mem_alloc.memoryTypeIndex = 0;
8888 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
8889 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008890 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008891 ASSERT_TRUE(pass);
8892 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
8893 ASSERT_VK_SUCCESS(err);
8894 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
8895 ASSERT_VK_SUCCESS(err);
8896 // Now create view for image
8897 VkImageViewCreateInfo image_view_ci = {};
8898 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
8899 image_view_ci.image = image;
8900 image_view_ci.format = VK_FORMAT_R8G8B8A8_UNORM;
8901 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
8902 image_view_ci.subresourceRange.layerCount = 1;
8903 image_view_ci.subresourceRange.baseArrayLayer = 0;
8904 image_view_ci.subresourceRange.levelCount = 1;
8905 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8906 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008907 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008908 ASSERT_VK_SUCCESS(err);
8909
8910 VkDescriptorBufferInfo buff_info = {};
8911 buff_info.buffer = buffer;
8912 VkDescriptorImageInfo img_info = {};
8913 img_info.imageView = image_view;
8914 VkWriteDescriptorSet descriptor_write = {};
8915 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
8916 descriptor_write.dstBinding = 0;
8917 descriptor_write.descriptorCount = 1;
8918 descriptor_write.pTexelBufferView = &buff_view;
8919 descriptor_write.pBufferInfo = &buff_info;
8920 descriptor_write.pImageInfo = &img_info;
8921
8922 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008923 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
8924 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
8925 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
8926 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
8927 VALIDATION_ERROR_00943, // STORAGE_IMAGE
8928 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
8929 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
8930 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
8931 VALIDATION_ERROR_00947, // STORAGE_BUFFER
8932 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
8933 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
8934 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
8935 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008936 // Start loop at 1 as SAMPLER desc type has no usage bit error
8937 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8938 descriptor_write.descriptorType = VkDescriptorType(i);
8939 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008941
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008942 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008943
8944 m_errorMonitor->VerifyFound();
8945 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
8946 }
8947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
8948 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008949 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008950 vkDestroyImageView(m_device->device(), image_view, NULL);
8951 vkDestroyBuffer(m_device->device(), buffer, NULL);
8952 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008953 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008954 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
8955}
8956
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008957TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008958 TEST_DESCRIPTION("Attempt to update buffer descriptor set that has incorrect "
8959 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
8960 "1. offset value greater than buffer size\n"
8961 "2. range value of 0\n"
8962 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008963 VkResult err;
8964
8965 ASSERT_NO_FATAL_FAILURE(InitState());
8966 VkDescriptorPoolSize ds_type_count = {};
8967 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8968 ds_type_count.descriptorCount = 1;
8969
8970 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8971 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8972 ds_pool_ci.pNext = NULL;
8973 ds_pool_ci.maxSets = 1;
8974 ds_pool_ci.poolSizeCount = 1;
8975 ds_pool_ci.pPoolSizes = &ds_type_count;
8976
8977 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008978 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008979 ASSERT_VK_SUCCESS(err);
8980
8981 // Create layout with single uniform buffer descriptor
8982 VkDescriptorSetLayoutBinding dsl_binding = {};
8983 dsl_binding.binding = 0;
8984 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8985 dsl_binding.descriptorCount = 1;
8986 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8987 dsl_binding.pImmutableSamplers = NULL;
8988
8989 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8990 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8991 ds_layout_ci.pNext = NULL;
8992 ds_layout_ci.bindingCount = 1;
8993 ds_layout_ci.pBindings = &dsl_binding;
8994 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008995 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06008996 ASSERT_VK_SUCCESS(err);
8997
8998 VkDescriptorSet descriptor_set = {};
8999 VkDescriptorSetAllocateInfo alloc_info = {};
9000 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9001 alloc_info.descriptorSetCount = 1;
9002 alloc_info.descriptorPool = ds_pool;
9003 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009004 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009005 ASSERT_VK_SUCCESS(err);
9006
9007 // Create a buffer to be used for invalid updates
9008 VkBufferCreateInfo buff_ci = {};
9009 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9010 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9011 buff_ci.size = 256;
9012 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9013 VkBuffer buffer;
9014 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9015 ASSERT_VK_SUCCESS(err);
9016 // Have to bind memory to buffer before descriptor update
9017 VkMemoryAllocateInfo mem_alloc = {};
9018 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9019 mem_alloc.pNext = NULL;
9020 mem_alloc.allocationSize = 256;
9021 mem_alloc.memoryTypeIndex = 0;
9022
9023 VkMemoryRequirements mem_reqs;
9024 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009025 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009026 if (!pass) {
9027 vkDestroyBuffer(m_device->device(), buffer, NULL);
9028 return;
9029 }
9030
9031 VkDeviceMemory mem;
9032 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9033 ASSERT_VK_SUCCESS(err);
9034 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9035 ASSERT_VK_SUCCESS(err);
9036
9037 VkDescriptorBufferInfo buff_info = {};
9038 buff_info.buffer = buffer;
9039 // First make offset 1 larger than buffer size
9040 buff_info.offset = 257;
9041 buff_info.range = VK_WHOLE_SIZE;
9042 VkWriteDescriptorSet descriptor_write = {};
9043 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9044 descriptor_write.dstBinding = 0;
9045 descriptor_write.descriptorCount = 1;
9046 descriptor_write.pTexelBufferView = nullptr;
9047 descriptor_write.pBufferInfo = &buff_info;
9048 descriptor_write.pImageInfo = nullptr;
9049
9050 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9051 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009052 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009053
9054 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9055
9056 m_errorMonitor->VerifyFound();
9057 // Now cause error due to range of 0
9058 buff_info.offset = 0;
9059 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009061
9062 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9063
9064 m_errorMonitor->VerifyFound();
9065 // Now cause error due to range exceeding buffer size - offset
9066 buff_info.offset = 128;
9067 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009069
9070 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9071
9072 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009073 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009074 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9075 vkDestroyBuffer(m_device->device(), buffer, NULL);
9076 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9077 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9078}
9079
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009080TEST_F(VkLayerTest, DSAspectBitsErrors) {
9081 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9082 // are set, but could expand this test to hit more cases.
9083 TEST_DESCRIPTION("Attempt to update descriptor sets for images "
9084 "that do not have correct aspect bits sets.");
9085 VkResult err;
9086
9087 ASSERT_NO_FATAL_FAILURE(InitState());
9088 VkDescriptorPoolSize ds_type_count = {};
9089 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9090 ds_type_count.descriptorCount = 1;
9091
9092 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9093 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9094 ds_pool_ci.pNext = NULL;
9095 ds_pool_ci.maxSets = 5;
9096 ds_pool_ci.poolSizeCount = 1;
9097 ds_pool_ci.pPoolSizes = &ds_type_count;
9098
9099 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009100 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009101 ASSERT_VK_SUCCESS(err);
9102
9103 VkDescriptorSetLayoutBinding dsl_binding = {};
9104 dsl_binding.binding = 0;
9105 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9106 dsl_binding.descriptorCount = 1;
9107 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9108 dsl_binding.pImmutableSamplers = NULL;
9109
9110 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9111 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9112 ds_layout_ci.pNext = NULL;
9113 ds_layout_ci.bindingCount = 1;
9114 ds_layout_ci.pBindings = &dsl_binding;
9115 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009116 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009117 ASSERT_VK_SUCCESS(err);
9118
9119 VkDescriptorSet descriptor_set = {};
9120 VkDescriptorSetAllocateInfo alloc_info = {};
9121 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9122 alloc_info.descriptorSetCount = 1;
9123 alloc_info.descriptorPool = ds_pool;
9124 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009125 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009126 ASSERT_VK_SUCCESS(err);
9127
9128 // Create an image to be used for invalid updates
9129 VkImageCreateInfo image_ci = {};
9130 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9131 image_ci.imageType = VK_IMAGE_TYPE_2D;
9132 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9133 image_ci.extent.width = 64;
9134 image_ci.extent.height = 64;
9135 image_ci.extent.depth = 1;
9136 image_ci.mipLevels = 1;
9137 image_ci.arrayLayers = 1;
9138 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9139 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9140 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9141 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9142 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9143 VkImage image;
9144 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9145 ASSERT_VK_SUCCESS(err);
9146 // Bind memory to image
9147 VkMemoryRequirements mem_reqs;
9148 VkDeviceMemory image_mem;
9149 bool pass;
9150 VkMemoryAllocateInfo mem_alloc = {};
9151 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9152 mem_alloc.pNext = NULL;
9153 mem_alloc.allocationSize = 0;
9154 mem_alloc.memoryTypeIndex = 0;
9155 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9156 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009157 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009158 ASSERT_TRUE(pass);
9159 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9160 ASSERT_VK_SUCCESS(err);
9161 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9162 ASSERT_VK_SUCCESS(err);
9163 // Now create view for image
9164 VkImageViewCreateInfo image_view_ci = {};
9165 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9166 image_view_ci.image = image;
9167 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9168 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9169 image_view_ci.subresourceRange.layerCount = 1;
9170 image_view_ci.subresourceRange.baseArrayLayer = 0;
9171 image_view_ci.subresourceRange.levelCount = 1;
9172 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009173 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009174
9175 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009176 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009177 ASSERT_VK_SUCCESS(err);
9178
9179 VkDescriptorImageInfo img_info = {};
9180 img_info.imageView = image_view;
9181 VkWriteDescriptorSet descriptor_write = {};
9182 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9183 descriptor_write.dstBinding = 0;
9184 descriptor_write.descriptorCount = 1;
9185 descriptor_write.pTexelBufferView = NULL;
9186 descriptor_write.pBufferInfo = NULL;
9187 descriptor_write.pImageInfo = &img_info;
9188 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9189 descriptor_write.dstSet = descriptor_set;
9190 const char *error_msg = " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9191 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009193
9194 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9195
9196 m_errorMonitor->VerifyFound();
9197 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9198 vkDestroyImage(m_device->device(), image, NULL);
9199 vkFreeMemory(m_device->device(), image_mem, NULL);
9200 vkDestroyImageView(m_device->device(), image_view, NULL);
9201 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9202 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9203}
9204
Karl Schultz6addd812016-02-02 17:17:23 -07009205TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009206 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009207 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9210 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9211 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009212
Tobin Ehlis3b780662015-05-28 12:11:26 -06009213 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009214 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009215 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009216 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9217 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009218
9219 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009220 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9221 ds_pool_ci.pNext = NULL;
9222 ds_pool_ci.maxSets = 1;
9223 ds_pool_ci.poolSizeCount = 1;
9224 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009225
Tobin Ehlis3b780662015-05-28 12:11:26 -06009226 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009227 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009228 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009229 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009230 dsl_binding.binding = 0;
9231 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9232 dsl_binding.descriptorCount = 1;
9233 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9234 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009235
Tony Barboureb254902015-07-15 12:50:33 -06009236 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009237 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9238 ds_layout_ci.pNext = NULL;
9239 ds_layout_ci.bindingCount = 1;
9240 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009241
Tobin Ehlis3b780662015-05-28 12:11:26 -06009242 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009243 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009244 ASSERT_VK_SUCCESS(err);
9245
9246 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009247 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009248 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009249 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009250 alloc_info.descriptorPool = ds_pool;
9251 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009252 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009253 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009254
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009255 VkSamplerCreateInfo sampler_ci = {};
9256 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9257 sampler_ci.pNext = NULL;
9258 sampler_ci.magFilter = VK_FILTER_NEAREST;
9259 sampler_ci.minFilter = VK_FILTER_NEAREST;
9260 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9261 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9262 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9263 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9264 sampler_ci.mipLodBias = 1.0;
9265 sampler_ci.anisotropyEnable = VK_FALSE;
9266 sampler_ci.maxAnisotropy = 1;
9267 sampler_ci.compareEnable = VK_FALSE;
9268 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9269 sampler_ci.minLod = 1.0;
9270 sampler_ci.maxLod = 1.0;
9271 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9272 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9273 VkSampler sampler;
9274 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9275 ASSERT_VK_SUCCESS(err);
9276
9277 VkDescriptorImageInfo info = {};
9278 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009279
9280 VkWriteDescriptorSet descriptor_write;
9281 memset(&descriptor_write, 0, sizeof(descriptor_write));
9282 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009283 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009284 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009285 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009286 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009287 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009288
9289 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9290
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009291 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009292
Chia-I Wuf7458c52015-10-26 21:10:41 +08009293 vkDestroySampler(m_device->device(), sampler, NULL);
9294 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9295 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009296}
9297
Karl Schultz6addd812016-02-02 17:17:23 -07009298TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009299 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009300 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009301
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009303
Tobin Ehlis3b780662015-05-28 12:11:26 -06009304 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009305 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009306 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009307 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9308 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009309
9310 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009311 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9312 ds_pool_ci.pNext = NULL;
9313 ds_pool_ci.maxSets = 1;
9314 ds_pool_ci.poolSizeCount = 1;
9315 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009316
Tobin Ehlis3b780662015-05-28 12:11:26 -06009317 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009318 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009319 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009320
Tony Barboureb254902015-07-15 12:50:33 -06009321 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009322 dsl_binding.binding = 0;
9323 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9324 dsl_binding.descriptorCount = 1;
9325 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9326 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009327
9328 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009329 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9330 ds_layout_ci.pNext = NULL;
9331 ds_layout_ci.bindingCount = 1;
9332 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009333
Tobin Ehlis3b780662015-05-28 12:11:26 -06009334 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009335 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009336 ASSERT_VK_SUCCESS(err);
9337
9338 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009339 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009340 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009341 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009342 alloc_info.descriptorPool = ds_pool;
9343 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009344 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009345 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009346
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009347 // Correctly update descriptor to avoid "NOT_UPDATED" error
9348 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009349 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009350 buff_info.offset = 0;
9351 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009352
9353 VkWriteDescriptorSet descriptor_write;
9354 memset(&descriptor_write, 0, sizeof(descriptor_write));
9355 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009356 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009357 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009358 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009359 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9360 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009361
9362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9363
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009364 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009365
Chia-I Wuf7458c52015-10-26 21:10:41 +08009366 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9367 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009368}
9369
Karl Schultz6addd812016-02-02 17:17:23 -07009370TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009371 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009372 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009373
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009375
Tobin Ehlis3b780662015-05-28 12:11:26 -06009376 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009377 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009378 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009379 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9380 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009381
9382 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009383 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9384 ds_pool_ci.pNext = NULL;
9385 ds_pool_ci.maxSets = 1;
9386 ds_pool_ci.poolSizeCount = 1;
9387 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009388
Tobin Ehlis3b780662015-05-28 12:11:26 -06009389 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009390 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009391 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009392
Tony Barboureb254902015-07-15 12:50:33 -06009393 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009394 dsl_binding.binding = 0;
9395 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9396 dsl_binding.descriptorCount = 1;
9397 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9398 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009399
9400 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009401 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9402 ds_layout_ci.pNext = NULL;
9403 ds_layout_ci.bindingCount = 1;
9404 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009405 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009406 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009407 ASSERT_VK_SUCCESS(err);
9408
9409 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009410 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009411 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009412 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009413 alloc_info.descriptorPool = ds_pool;
9414 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009415 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009416 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009417
Tony Barboureb254902015-07-15 12:50:33 -06009418 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009419 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9420 sampler_ci.pNext = NULL;
9421 sampler_ci.magFilter = VK_FILTER_NEAREST;
9422 sampler_ci.minFilter = VK_FILTER_NEAREST;
9423 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9424 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9425 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9426 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9427 sampler_ci.mipLodBias = 1.0;
9428 sampler_ci.anisotropyEnable = VK_FALSE;
9429 sampler_ci.maxAnisotropy = 1;
9430 sampler_ci.compareEnable = VK_FALSE;
9431 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9432 sampler_ci.minLod = 1.0;
9433 sampler_ci.maxLod = 1.0;
9434 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9435 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009436
Tobin Ehlis3b780662015-05-28 12:11:26 -06009437 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009438 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009439 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009440
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009441 VkDescriptorImageInfo info = {};
9442 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009443
9444 VkWriteDescriptorSet descriptor_write;
9445 memset(&descriptor_write, 0, sizeof(descriptor_write));
9446 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009447 descriptor_write.dstSet = descriptorSet;
9448 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009449 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009450 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009451 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009452 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009453
9454 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9455
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009456 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009457
Chia-I Wuf7458c52015-10-26 21:10:41 +08009458 vkDestroySampler(m_device->device(), sampler, NULL);
9459 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9460 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009461}
9462
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009463TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9464 // Create layout w/ empty binding and attempt to update it
9465 VkResult err;
9466
9467 ASSERT_NO_FATAL_FAILURE(InitState());
9468
9469 VkDescriptorPoolSize ds_type_count = {};
9470 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9471 ds_type_count.descriptorCount = 1;
9472
9473 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9474 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9475 ds_pool_ci.pNext = NULL;
9476 ds_pool_ci.maxSets = 1;
9477 ds_pool_ci.poolSizeCount = 1;
9478 ds_pool_ci.pPoolSizes = &ds_type_count;
9479
9480 VkDescriptorPool ds_pool;
9481 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9482 ASSERT_VK_SUCCESS(err);
9483
9484 VkDescriptorSetLayoutBinding dsl_binding = {};
9485 dsl_binding.binding = 0;
9486 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9487 dsl_binding.descriptorCount = 0;
9488 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9489 dsl_binding.pImmutableSamplers = NULL;
9490
9491 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9492 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9493 ds_layout_ci.pNext = NULL;
9494 ds_layout_ci.bindingCount = 1;
9495 ds_layout_ci.pBindings = &dsl_binding;
9496 VkDescriptorSetLayout ds_layout;
9497 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9498 ASSERT_VK_SUCCESS(err);
9499
9500 VkDescriptorSet descriptor_set;
9501 VkDescriptorSetAllocateInfo alloc_info = {};
9502 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9503 alloc_info.descriptorSetCount = 1;
9504 alloc_info.descriptorPool = ds_pool;
9505 alloc_info.pSetLayouts = &ds_layout;
9506 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9507 ASSERT_VK_SUCCESS(err);
9508
9509 VkSamplerCreateInfo sampler_ci = {};
9510 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9511 sampler_ci.magFilter = VK_FILTER_NEAREST;
9512 sampler_ci.minFilter = VK_FILTER_NEAREST;
9513 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9514 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9515 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9516 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9517 sampler_ci.mipLodBias = 1.0;
9518 sampler_ci.maxAnisotropy = 1;
9519 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9520 sampler_ci.minLod = 1.0;
9521 sampler_ci.maxLod = 1.0;
9522 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9523
9524 VkSampler sampler;
9525 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9526 ASSERT_VK_SUCCESS(err);
9527
9528 VkDescriptorImageInfo info = {};
9529 info.sampler = sampler;
9530
9531 VkWriteDescriptorSet descriptor_write;
9532 memset(&descriptor_write, 0, sizeof(descriptor_write));
9533 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9534 descriptor_write.dstSet = descriptor_set;
9535 descriptor_write.dstBinding = 0;
9536 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
9537 // This is the wrong type, but empty binding error will be flagged first
9538 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9539 descriptor_write.pImageInfo = &info;
9540
9541 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9542 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9543 m_errorMonitor->VerifyFound();
9544
9545 vkDestroySampler(m_device->device(), sampler, NULL);
9546 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9547 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9548}
9549
Karl Schultz6addd812016-02-02 17:17:23 -07009550TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9551 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9552 // types
9553 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009554
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009555 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 -06009556
Tobin Ehlis3b780662015-05-28 12:11:26 -06009557 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009558
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009559 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009560 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9561 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009562
9563 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009564 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9565 ds_pool_ci.pNext = NULL;
9566 ds_pool_ci.maxSets = 1;
9567 ds_pool_ci.poolSizeCount = 1;
9568 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009569
Tobin Ehlis3b780662015-05-28 12:11:26 -06009570 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009571 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009572 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009573 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009574 dsl_binding.binding = 0;
9575 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9576 dsl_binding.descriptorCount = 1;
9577 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9578 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009579
Tony Barboureb254902015-07-15 12:50:33 -06009580 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009581 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9582 ds_layout_ci.pNext = NULL;
9583 ds_layout_ci.bindingCount = 1;
9584 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009585
Tobin Ehlis3b780662015-05-28 12:11:26 -06009586 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009587 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009588 ASSERT_VK_SUCCESS(err);
9589
9590 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009591 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009592 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009593 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009594 alloc_info.descriptorPool = ds_pool;
9595 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009596 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009597 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009598
Tony Barboureb254902015-07-15 12:50:33 -06009599 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009600 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9601 sampler_ci.pNext = NULL;
9602 sampler_ci.magFilter = VK_FILTER_NEAREST;
9603 sampler_ci.minFilter = VK_FILTER_NEAREST;
9604 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9605 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9606 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9607 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9608 sampler_ci.mipLodBias = 1.0;
9609 sampler_ci.anisotropyEnable = VK_FALSE;
9610 sampler_ci.maxAnisotropy = 1;
9611 sampler_ci.compareEnable = VK_FALSE;
9612 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9613 sampler_ci.minLod = 1.0;
9614 sampler_ci.maxLod = 1.0;
9615 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9616 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009617 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009618 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009619 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009620
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009621 VkDescriptorImageInfo info = {};
9622 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009623
9624 VkWriteDescriptorSet descriptor_write;
9625 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009626 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009627 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009628 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009629 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009630 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009631 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009632
9633 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9634
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009635 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009636
Chia-I Wuf7458c52015-10-26 21:10:41 +08009637 vkDestroySampler(m_device->device(), sampler, NULL);
9638 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9639 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009640}
9641
Karl Schultz6addd812016-02-02 17:17:23 -07009642TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009643 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -07009644 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009645
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009647
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009648 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009649 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
9650 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009651 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009652 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9653 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009654
9655 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009656 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9657 ds_pool_ci.pNext = NULL;
9658 ds_pool_ci.maxSets = 1;
9659 ds_pool_ci.poolSizeCount = 1;
9660 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009661
9662 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009663 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009664 ASSERT_VK_SUCCESS(err);
9665
9666 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009667 dsl_binding.binding = 0;
9668 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9669 dsl_binding.descriptorCount = 1;
9670 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9671 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009672
9673 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009674 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9675 ds_layout_ci.pNext = NULL;
9676 ds_layout_ci.bindingCount = 1;
9677 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009678 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009679 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009680 ASSERT_VK_SUCCESS(err);
9681
9682 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009683 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009684 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009685 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009686 alloc_info.descriptorPool = ds_pool;
9687 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009688 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009689 ASSERT_VK_SUCCESS(err);
9690
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009691 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009692
9693 VkDescriptorImageInfo descriptor_info;
9694 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9695 descriptor_info.sampler = sampler;
9696
9697 VkWriteDescriptorSet descriptor_write;
9698 memset(&descriptor_write, 0, sizeof(descriptor_write));
9699 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009700 descriptor_write.dstSet = descriptorSet;
9701 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009702 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009703 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9704 descriptor_write.pImageInfo = &descriptor_info;
9705
9706 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9707
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009708 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009709
Chia-I Wuf7458c52015-10-26 21:10:41 +08009710 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9711 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009712}
9713
Karl Schultz6addd812016-02-02 17:17:23 -07009714TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
9715 // Create a single combined Image/Sampler descriptor and send it an invalid
9716 // imageView
9717 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009718
Karl Schultzf78bcdd2016-11-30 12:36:01 -07009719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009720
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009721 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009722 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009723 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9724 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009725
9726 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009727 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9728 ds_pool_ci.pNext = NULL;
9729 ds_pool_ci.maxSets = 1;
9730 ds_pool_ci.poolSizeCount = 1;
9731 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009732
9733 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009734 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009735 ASSERT_VK_SUCCESS(err);
9736
9737 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009738 dsl_binding.binding = 0;
9739 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9740 dsl_binding.descriptorCount = 1;
9741 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9742 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009743
9744 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009745 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9746 ds_layout_ci.pNext = NULL;
9747 ds_layout_ci.bindingCount = 1;
9748 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009749 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009750 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009751 ASSERT_VK_SUCCESS(err);
9752
9753 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009754 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009755 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009756 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009757 alloc_info.descriptorPool = ds_pool;
9758 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009759 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009760 ASSERT_VK_SUCCESS(err);
9761
9762 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009763 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9764 sampler_ci.pNext = NULL;
9765 sampler_ci.magFilter = VK_FILTER_NEAREST;
9766 sampler_ci.minFilter = VK_FILTER_NEAREST;
9767 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9768 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9769 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9770 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9771 sampler_ci.mipLodBias = 1.0;
9772 sampler_ci.anisotropyEnable = VK_FALSE;
9773 sampler_ci.maxAnisotropy = 1;
9774 sampler_ci.compareEnable = VK_FALSE;
9775 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9776 sampler_ci.minLod = 1.0;
9777 sampler_ci.maxLod = 1.0;
9778 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9779 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009780
9781 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009782 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009783 ASSERT_VK_SUCCESS(err);
9784
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009785 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009786
9787 VkDescriptorImageInfo descriptor_info;
9788 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
9789 descriptor_info.sampler = sampler;
9790 descriptor_info.imageView = view;
9791
9792 VkWriteDescriptorSet descriptor_write;
9793 memset(&descriptor_write, 0, sizeof(descriptor_write));
9794 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009795 descriptor_write.dstSet = descriptorSet;
9796 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009797 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009798 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
9799 descriptor_write.pImageInfo = &descriptor_info;
9800
9801 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9802
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009803 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009804
Chia-I Wuf7458c52015-10-26 21:10:41 +08009805 vkDestroySampler(m_device->device(), sampler, NULL);
9806 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9807 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -06009808}
9809
Karl Schultz6addd812016-02-02 17:17:23 -07009810TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
9811 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
9812 // into the other
9813 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009814
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding #1 with type "
9816 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
9817 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009818
Tobin Ehlis04356f92015-10-27 16:35:27 -06009819 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009820 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009821 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009822 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9823 ds_type_count[0].descriptorCount = 1;
9824 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
9825 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009826
9827 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009828 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9829 ds_pool_ci.pNext = NULL;
9830 ds_pool_ci.maxSets = 1;
9831 ds_pool_ci.poolSizeCount = 2;
9832 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009833
9834 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009835 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009836 ASSERT_VK_SUCCESS(err);
9837 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009838 dsl_binding[0].binding = 0;
9839 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9840 dsl_binding[0].descriptorCount = 1;
9841 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9842 dsl_binding[0].pImmutableSamplers = NULL;
9843 dsl_binding[1].binding = 1;
9844 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9845 dsl_binding[1].descriptorCount = 1;
9846 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9847 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009848
9849 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009850 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9851 ds_layout_ci.pNext = NULL;
9852 ds_layout_ci.bindingCount = 2;
9853 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009854
9855 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009856 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009857 ASSERT_VK_SUCCESS(err);
9858
9859 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009860 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009861 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009862 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009863 alloc_info.descriptorPool = ds_pool;
9864 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009865 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009866 ASSERT_VK_SUCCESS(err);
9867
9868 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009869 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9870 sampler_ci.pNext = NULL;
9871 sampler_ci.magFilter = VK_FILTER_NEAREST;
9872 sampler_ci.minFilter = VK_FILTER_NEAREST;
9873 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9874 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9875 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9876 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9877 sampler_ci.mipLodBias = 1.0;
9878 sampler_ci.anisotropyEnable = VK_FALSE;
9879 sampler_ci.maxAnisotropy = 1;
9880 sampler_ci.compareEnable = VK_FALSE;
9881 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9882 sampler_ci.minLod = 1.0;
9883 sampler_ci.maxLod = 1.0;
9884 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9885 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009886
9887 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009888 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009889 ASSERT_VK_SUCCESS(err);
9890
9891 VkDescriptorImageInfo info = {};
9892 info.sampler = sampler;
9893
9894 VkWriteDescriptorSet descriptor_write;
9895 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
9896 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009897 descriptor_write.dstSet = descriptorSet;
9898 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +08009899 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -06009900 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9901 descriptor_write.pImageInfo = &info;
9902 // This write update should succeed
9903 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9904 // Now perform a copy update that fails due to type mismatch
9905 VkCopyDescriptorSet copy_ds_update;
9906 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9907 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9908 copy_ds_update.srcSet = descriptorSet;
Mark Young29927482016-05-04 14:38:51 -06009909 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009910 copy_ds_update.dstSet = descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07009911 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
Chia-I Wud50a7d72015-10-26 20:48:51 +08009912 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009913 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9914
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009915 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009916 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009917 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 -06009918 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9919 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9920 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009921 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009922 copy_ds_update.dstSet = descriptorSet;
9923 copy_ds_update.dstBinding = 0;
Mark Young29927482016-05-04 14:38:51 -06009924 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -06009925 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9926
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009927 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009928
Tobin Ehlis04356f92015-10-27 16:35:27 -06009929 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " binding#1 with offset index of 1 plus "
9931 "update array offset of 0 and update of "
9932 "5 descriptors oversteps total number "
9933 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009934
Tobin Ehlis04356f92015-10-27 16:35:27 -06009935 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
9936 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
9937 copy_ds_update.srcSet = descriptorSet;
9938 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009939 copy_ds_update.dstSet = descriptorSet;
9940 copy_ds_update.dstBinding = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009941 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -06009942 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
9943
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009944 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -06009945
Chia-I Wuf7458c52015-10-26 21:10:41 +08009946 vkDestroySampler(m_device->device(), sampler, NULL);
9947 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9948 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -06009949}
9950
Karl Schultz6addd812016-02-02 17:17:23 -07009951TEST_F(VkLayerTest, NumSamplesMismatch) {
9952 // Create CommandBuffer where MSAA samples doesn't match RenderPass
9953 // sampleCount
9954 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009955
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009957
Tobin Ehlis3b780662015-05-28 12:11:26 -06009958 ASSERT_NO_FATAL_FAILURE(InitState());
9959 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009960 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -06009961 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009962 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009963
9964 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009965 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9966 ds_pool_ci.pNext = NULL;
9967 ds_pool_ci.maxSets = 1;
9968 ds_pool_ci.poolSizeCount = 1;
9969 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009970
Tobin Ehlis3b780662015-05-28 12:11:26 -06009971 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009972 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009973 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009974
Tony Barboureb254902015-07-15 12:50:33 -06009975 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08009976 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -06009977 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08009978 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009979 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9980 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009981
Tony Barboureb254902015-07-15 12:50:33 -06009982 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9983 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9984 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009985 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07009986 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009987
Tobin Ehlis3b780662015-05-28 12:11:26 -06009988 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009989 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009990 ASSERT_VK_SUCCESS(err);
9991
9992 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009993 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009994 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009995 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009996 alloc_info.descriptorPool = ds_pool;
9997 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009998 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009999 ASSERT_VK_SUCCESS(err);
10000
Tony Barboureb254902015-07-15 12:50:33 -060010001 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010002 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010003 pipe_ms_state_ci.pNext = NULL;
10004 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10005 pipe_ms_state_ci.sampleShadingEnable = 0;
10006 pipe_ms_state_ci.minSampleShading = 1.0;
10007 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010008
Tony Barboureb254902015-07-15 12:50:33 -060010009 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010010 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10011 pipeline_layout_ci.pNext = NULL;
10012 pipeline_layout_ci.setLayoutCount = 1;
10013 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010014
10015 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010016 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010017 ASSERT_VK_SUCCESS(err);
10018
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010019 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10020 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10021 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010022 VkPipelineObj pipe(m_device);
10023 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010024 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010025 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010026 pipe.SetMSAA(&pipe_ms_state_ci);
10027 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010028
Tony Barbour552f6c02016-12-21 14:34:07 -070010029 m_commandBuffer->BeginCommandBuffer();
10030 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010031 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010032
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010033 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10034 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10035 VkRect2D scissor = {{0, 0}, {16, 16}};
10036 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10037
Mark Young29927482016-05-04 14:38:51 -060010038 // Render triangle (the error should trigger on the attempt to draw).
10039 Draw(3, 1, 0, 0);
10040
10041 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010042 m_commandBuffer->EndRenderPass();
10043 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010044
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010045 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010046
Chia-I Wuf7458c52015-10-26 21:10:41 +080010047 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10048 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10049 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010050}
Mark Young29927482016-05-04 14:38:51 -060010051
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010052TEST_F(VkLayerTest, RenderPassIncompatible) {
10053 TEST_DESCRIPTION("Hit RenderPass incompatible cases. "
10054 "Initial case is drawing with an active renderpass that's "
Mike Weiblencce7ec72016-10-17 19:33:05 -060010055 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010056 VkResult err;
10057
10058 ASSERT_NO_FATAL_FAILURE(InitState());
10059 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10060
10061 VkDescriptorSetLayoutBinding dsl_binding = {};
10062 dsl_binding.binding = 0;
10063 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10064 dsl_binding.descriptorCount = 1;
10065 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10066 dsl_binding.pImmutableSamplers = NULL;
10067
10068 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10069 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10070 ds_layout_ci.pNext = NULL;
10071 ds_layout_ci.bindingCount = 1;
10072 ds_layout_ci.pBindings = &dsl_binding;
10073
10074 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010075 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010076 ASSERT_VK_SUCCESS(err);
10077
10078 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10079 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10080 pipeline_layout_ci.pNext = NULL;
10081 pipeline_layout_ci.setLayoutCount = 1;
10082 pipeline_layout_ci.pSetLayouts = &ds_layout;
10083
10084 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010086 ASSERT_VK_SUCCESS(err);
10087
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010088 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10089 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10090 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010091 // Create a renderpass that will be incompatible with default renderpass
10092 VkAttachmentReference attach = {};
10093 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10094 VkAttachmentReference color_att = {};
10095 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10096 VkSubpassDescription subpass = {};
10097 subpass.inputAttachmentCount = 1;
10098 subpass.pInputAttachments = &attach;
10099 subpass.colorAttachmentCount = 1;
10100 subpass.pColorAttachments = &color_att;
10101 VkRenderPassCreateInfo rpci = {};
10102 rpci.subpassCount = 1;
10103 rpci.pSubpasses = &subpass;
10104 rpci.attachmentCount = 1;
10105 VkAttachmentDescription attach_desc = {};
10106 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010107 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10108 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010109 rpci.pAttachments = &attach_desc;
10110 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10111 VkRenderPass rp;
10112 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10113 VkPipelineObj pipe(m_device);
10114 pipe.AddShader(&vs);
10115 pipe.AddShader(&fs);
10116 pipe.AddColorAttachment();
10117 VkViewport view_port = {};
10118 m_viewports.push_back(view_port);
10119 pipe.SetViewport(m_viewports);
10120 VkRect2D rect = {};
10121 m_scissors.push_back(rect);
10122 pipe.SetScissor(m_scissors);
10123 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10124
10125 VkCommandBufferInheritanceInfo cbii = {};
10126 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10127 cbii.renderPass = rp;
10128 cbii.subpass = 0;
10129 VkCommandBufferBeginInfo cbbi = {};
10130 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10131 cbbi.pInheritanceInfo = &cbii;
10132 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10133 VkRenderPassBeginInfo rpbi = {};
10134 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10135 rpbi.framebuffer = m_framebuffer;
10136 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010137 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10138 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010141 // Render triangle (the error should trigger on the attempt to draw).
10142 Draw(3, 1, 0, 0);
10143
10144 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010145 m_commandBuffer->EndRenderPass();
10146 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010147
10148 m_errorMonitor->VerifyFound();
10149
10150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10152 vkDestroyRenderPass(m_device->device(), rp, NULL);
10153}
10154
Mark Youngc89c6312016-03-31 16:03:20 -060010155TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10156 // Create Pipeline where the number of blend attachments doesn't match the
10157 // number of color attachments. In this case, we don't add any color
10158 // blend attachments even though we have a color attachment.
10159 VkResult err;
10160
10161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010162 "Render pass subpass 0 mismatch with blending state defined and blend state attachment");
Mark Youngc89c6312016-03-31 16:03:20 -060010163
10164 ASSERT_NO_FATAL_FAILURE(InitState());
10165 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10166 VkDescriptorPoolSize ds_type_count = {};
10167 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10168 ds_type_count.descriptorCount = 1;
10169
10170 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10171 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10172 ds_pool_ci.pNext = NULL;
10173 ds_pool_ci.maxSets = 1;
10174 ds_pool_ci.poolSizeCount = 1;
10175 ds_pool_ci.pPoolSizes = &ds_type_count;
10176
10177 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010178 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010179 ASSERT_VK_SUCCESS(err);
10180
10181 VkDescriptorSetLayoutBinding dsl_binding = {};
10182 dsl_binding.binding = 0;
10183 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10184 dsl_binding.descriptorCount = 1;
10185 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10186 dsl_binding.pImmutableSamplers = NULL;
10187
10188 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10189 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10190 ds_layout_ci.pNext = NULL;
10191 ds_layout_ci.bindingCount = 1;
10192 ds_layout_ci.pBindings = &dsl_binding;
10193
10194 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010195 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010196 ASSERT_VK_SUCCESS(err);
10197
10198 VkDescriptorSet descriptorSet;
10199 VkDescriptorSetAllocateInfo alloc_info = {};
10200 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10201 alloc_info.descriptorSetCount = 1;
10202 alloc_info.descriptorPool = ds_pool;
10203 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010204 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010205 ASSERT_VK_SUCCESS(err);
10206
10207 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010209 pipe_ms_state_ci.pNext = NULL;
10210 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10211 pipe_ms_state_ci.sampleShadingEnable = 0;
10212 pipe_ms_state_ci.minSampleShading = 1.0;
10213 pipe_ms_state_ci.pSampleMask = NULL;
10214
10215 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10216 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10217 pipeline_layout_ci.pNext = NULL;
10218 pipeline_layout_ci.setLayoutCount = 1;
10219 pipeline_layout_ci.pSetLayouts = &ds_layout;
10220
10221 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010222 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010223 ASSERT_VK_SUCCESS(err);
10224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010225 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10226 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10227 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010228 VkPipelineObj pipe(m_device);
10229 pipe.AddShader(&vs);
10230 pipe.AddShader(&fs);
10231 pipe.SetMSAA(&pipe_ms_state_ci);
10232 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10233
Tony Barbour552f6c02016-12-21 14:34:07 -070010234 m_commandBuffer->BeginCommandBuffer();
10235 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010236 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Youngc89c6312016-03-31 16:03:20 -060010237
Rene Lindsay6d5c4fe2017-01-13 09:41:19 -070010238 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10239 VkRect2D scissor = {{0, 0}, {16, 16}};
10240 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10241 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10242
Mark Young29927482016-05-04 14:38:51 -060010243 // Render triangle (the error should trigger on the attempt to draw).
10244 Draw(3, 1, 0, 0);
10245
10246 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010247 m_commandBuffer->EndRenderPass();
10248 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010249
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010250 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010251
10252 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10253 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10254 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10255}
Mark Young29927482016-05-04 14:38:51 -060010256
Mark Muellerd4914412016-06-13 17:52:06 -060010257TEST_F(VkLayerTest, MissingClearAttachment) {
10258 TEST_DESCRIPTION("Points to a wrong colorAttachment index in a VkClearAttachment "
10259 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010260 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010262
10263 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10264 m_errorMonitor->VerifyFound();
10265}
10266
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010267TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010268
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010269 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10270 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010271
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010272 ASSERT_NO_FATAL_FAILURE(InitState());
10273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010274
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010275 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010276 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10277 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010278
10279 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010280 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10281 ds_pool_ci.pNext = NULL;
10282 ds_pool_ci.maxSets = 1;
10283 ds_pool_ci.poolSizeCount = 1;
10284 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010285
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010286 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010287 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010288 ASSERT_VK_SUCCESS(err);
10289
Tony Barboureb254902015-07-15 12:50:33 -060010290 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010291 dsl_binding.binding = 0;
10292 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10293 dsl_binding.descriptorCount = 1;
10294 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10295 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010296
Tony Barboureb254902015-07-15 12:50:33 -060010297 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010298 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10299 ds_layout_ci.pNext = NULL;
10300 ds_layout_ci.bindingCount = 1;
10301 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010302
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010303 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010304 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010305 ASSERT_VK_SUCCESS(err);
10306
10307 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010308 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010309 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010310 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010311 alloc_info.descriptorPool = ds_pool;
10312 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010313 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010314 ASSERT_VK_SUCCESS(err);
10315
Tony Barboureb254902015-07-15 12:50:33 -060010316 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010317 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010318 pipe_ms_state_ci.pNext = NULL;
10319 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10320 pipe_ms_state_ci.sampleShadingEnable = 0;
10321 pipe_ms_state_ci.minSampleShading = 1.0;
10322 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010323
Tony Barboureb254902015-07-15 12:50:33 -060010324 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010325 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10326 pipeline_layout_ci.pNext = NULL;
10327 pipeline_layout_ci.setLayoutCount = 1;
10328 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010329
10330 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010331 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010332 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010333
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010334 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010335 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010336 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010337 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010338
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010339 VkPipelineObj pipe(m_device);
10340 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010341 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010342 pipe.SetMSAA(&pipe_ms_state_ci);
10343 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010344
Tony Barbour552f6c02016-12-21 14:34:07 -070010345 m_commandBuffer->BeginCommandBuffer();
10346 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010347
Karl Schultz6addd812016-02-02 17:17:23 -070010348 // Main thing we care about for this test is that the VkImage obj we're
10349 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010350 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010351 VkClearAttachment color_attachment;
10352 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10353 color_attachment.clearValue.color.float32[0] = 1.0;
10354 color_attachment.clearValue.color.float32[1] = 1.0;
10355 color_attachment.clearValue.color.float32[2] = 1.0;
10356 color_attachment.clearValue.color.float32[3] = 1.0;
10357 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010358 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010359
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010360 // Call for full-sized FB Color attachment prior to issuing a Draw
10361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10362 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010363 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010364 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010365
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010366
10367 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10368 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10370 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10371 m_errorMonitor->VerifyFound();
10372
10373 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10374 clear_rect.layerCount = 2;
10375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10376 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010377 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010378
Chia-I Wuf7458c52015-10-26 21:10:41 +080010379 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10380 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10381 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010382}
10383
Karl Schultz6addd812016-02-02 17:17:23 -070010384TEST_F(VkLayerTest, VtxBufferBadIndex) {
10385 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10388 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010389
Tobin Ehlis502480b2015-06-24 15:53:07 -060010390 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010391 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010393
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010394 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010395 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10396 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010397
10398 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010399 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10400 ds_pool_ci.pNext = NULL;
10401 ds_pool_ci.maxSets = 1;
10402 ds_pool_ci.poolSizeCount = 1;
10403 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010404
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010405 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010406 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010407 ASSERT_VK_SUCCESS(err);
10408
Tony Barboureb254902015-07-15 12:50:33 -060010409 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010410 dsl_binding.binding = 0;
10411 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10412 dsl_binding.descriptorCount = 1;
10413 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10414 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010415
Tony Barboureb254902015-07-15 12:50:33 -060010416 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010417 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10418 ds_layout_ci.pNext = NULL;
10419 ds_layout_ci.bindingCount = 1;
10420 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010421
Tobin Ehlis502480b2015-06-24 15:53:07 -060010422 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010423 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010424 ASSERT_VK_SUCCESS(err);
10425
10426 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010427 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010428 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010429 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010430 alloc_info.descriptorPool = ds_pool;
10431 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010432 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010433 ASSERT_VK_SUCCESS(err);
10434
Tony Barboureb254902015-07-15 12:50:33 -060010435 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010436 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010437 pipe_ms_state_ci.pNext = NULL;
10438 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10439 pipe_ms_state_ci.sampleShadingEnable = 0;
10440 pipe_ms_state_ci.minSampleShading = 1.0;
10441 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010442
Tony Barboureb254902015-07-15 12:50:33 -060010443 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010444 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10445 pipeline_layout_ci.pNext = NULL;
10446 pipeline_layout_ci.setLayoutCount = 1;
10447 pipeline_layout_ci.pSetLayouts = &ds_layout;
10448 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010449
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010450 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010451 ASSERT_VK_SUCCESS(err);
10452
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010453 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10454 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
10455 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010456 VkPipelineObj pipe(m_device);
10457 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010458 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010459 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010460 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010461 pipe.SetViewport(m_viewports);
10462 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010463 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010464
Tony Barbour552f6c02016-12-21 14:34:07 -070010465 m_commandBuffer->BeginCommandBuffer();
10466 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010467 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010468 // Don't care about actual data, just need to get to draw to flag error
10469 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010470 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010471 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010472 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010473
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010474 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010475
Chia-I Wuf7458c52015-10-26 21:10:41 +080010476 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10477 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10478 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010479}
Mark Muellerdfe37552016-07-07 14:47:42 -060010480
Mark Mueller2ee294f2016-08-04 12:59:48 -060010481TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
10482 TEST_DESCRIPTION("Use an invalid count in a vkEnumeratePhysicalDevices call."
10483 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010484 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010486 const char *invalid_queueFamilyIndex_message = "Invalid queue create request in vkCreateDevice(). Invalid "
10487 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010489 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010490
Mark Mueller880fce52016-08-17 15:23:23 -060010491 // The following test fails with recent NVidia drivers.
10492 // By the time core_validation is reached, the NVidia
10493 // driver has sanitized the invalid condition and core_validation
10494 // is not introduced to the failure condition. This is not the case
10495 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010496 // uint32_t count = static_cast<uint32_t>(~0);
10497 // VkPhysicalDevice physical_device;
10498 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10499 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010500
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010502 float queue_priority = 0.0;
10503
10504 VkDeviceQueueCreateInfo queue_create_info = {};
10505 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10506 queue_create_info.queueCount = 1;
10507 queue_create_info.pQueuePriorities = &queue_priority;
10508 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10509
10510 VkPhysicalDeviceFeatures features = m_device->phy().features();
10511 VkDevice testDevice;
10512 VkDeviceCreateInfo device_create_info = {};
10513 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10514 device_create_info.queueCreateInfoCount = 1;
10515 device_create_info.pQueueCreateInfos = &queue_create_info;
10516 device_create_info.pEnabledFeatures = &features;
10517 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10518 m_errorMonitor->VerifyFound();
10519
10520 queue_create_info.queueFamilyIndex = 1;
10521
10522 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10523 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10524 for (unsigned i = 0; i < feature_count; i++) {
10525 if (VK_FALSE == feature_array[i]) {
10526 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010528 device_create_info.pEnabledFeatures = &features;
10529 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10530 m_errorMonitor->VerifyFound();
10531 break;
10532 }
10533 }
10534}
10535
Tobin Ehlis16edf082016-11-21 12:33:49 -070010536TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10537 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10538
10539 ASSERT_NO_FATAL_FAILURE(InitState());
10540
10541 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10542 std::vector<VkDeviceQueueCreateInfo> queue_info;
10543 queue_info.reserve(queue_props.size());
10544 std::vector<std::vector<float>> queue_priorities;
10545 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10546 VkDeviceQueueCreateInfo qi{};
10547 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10548 qi.queueFamilyIndex = i;
10549 qi.queueCount = queue_props[i].queueCount;
10550 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10551 qi.pQueuePriorities = queue_priorities[i].data();
10552 queue_info.push_back(qi);
10553 }
10554
10555 std::vector<const char *> device_extension_names;
10556
10557 VkDevice local_device;
10558 VkDeviceCreateInfo device_create_info = {};
10559 auto features = m_device->phy().features();
10560 // Intentionally disable pipeline stats
10561 features.pipelineStatisticsQuery = VK_FALSE;
10562 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10563 device_create_info.pNext = NULL;
10564 device_create_info.queueCreateInfoCount = queue_info.size();
10565 device_create_info.pQueueCreateInfos = queue_info.data();
10566 device_create_info.enabledLayerCount = 0;
10567 device_create_info.ppEnabledLayerNames = NULL;
10568 device_create_info.pEnabledFeatures = &features;
10569 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10570 ASSERT_VK_SUCCESS(err);
10571
10572 VkQueryPoolCreateInfo qpci{};
10573 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10574 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10575 qpci.queryCount = 1;
10576 VkQueryPool query_pool;
10577
10578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10579 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10580 m_errorMonitor->VerifyFound();
10581
10582 vkDestroyDevice(local_device, nullptr);
10583}
10584
Mark Mueller2ee294f2016-08-04 12:59:48 -060010585TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
10586 TEST_DESCRIPTION("Use an invalid queue index in a vkCmdWaitEvents call."
10587 "End a command buffer with a query still in progress.");
10588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010589 const char *invalid_queue_index = "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10590 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10591 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010592
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010593 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010594
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010596
10597 ASSERT_NO_FATAL_FAILURE(InitState());
10598
10599 VkEvent event;
10600 VkEventCreateInfo event_create_info{};
10601 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10602 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10603
Mark Mueller2ee294f2016-08-04 12:59:48 -060010604 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010605 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010606
Tony Barbour552f6c02016-12-21 14:34:07 -070010607 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010608
10609 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010610 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 -060010611 ASSERT_TRUE(image.initialized());
10612 VkImageMemoryBarrier img_barrier = {};
10613 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10614 img_barrier.pNext = NULL;
10615 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10616 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10617 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10618 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10619 img_barrier.image = image.handle();
10620 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010621
10622 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10623 // that layer validation catches the case when it is not.
10624 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010625 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10626 img_barrier.subresourceRange.baseArrayLayer = 0;
10627 img_barrier.subresourceRange.baseMipLevel = 0;
10628 img_barrier.subresourceRange.layerCount = 1;
10629 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010630 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10631 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010632 m_errorMonitor->VerifyFound();
10633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010635
10636 VkQueryPool query_pool;
10637 VkQueryPoolCreateInfo query_pool_create_info = {};
10638 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10639 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
10640 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010641 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010642
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010643 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010644 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
10645
10646 vkEndCommandBuffer(m_commandBuffer->handle());
10647 m_errorMonitor->VerifyFound();
10648
10649 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
10650 vkDestroyEvent(m_device->device(), event, nullptr);
10651}
10652
Mark Muellerdfe37552016-07-07 14:47:42 -060010653TEST_F(VkLayerTest, VertexBufferInvalid) {
10654 TEST_DESCRIPTION("Submit a command buffer using deleted vertex buffer, "
10655 "delete a buffer twice, use an invalid offset for each "
10656 "buffer type, and attempt to bind a null buffer");
10657
10658 const char *deleted_buffer_in_command_buffer = "Cannot submit cmd buffer "
10659 "using deleted buffer ";
Mark Muellerdfe37552016-07-07 14:47:42 -060010660 const char *invalid_offset_message = "vkBindBufferMemory(): "
10661 "memoryOffset is 0x";
10662 const char *invalid_storage_buffer_offset_message = "vkBindBufferMemory(): "
10663 "storage memoryOffset "
10664 "is 0x";
10665 const char *invalid_texel_buffer_offset_message = "vkBindBufferMemory(): "
10666 "texel memoryOffset "
10667 "is 0x";
10668 const char *invalid_uniform_buffer_offset_message = "vkBindBufferMemory(): "
10669 "uniform memoryOffset "
10670 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060010671
10672 ASSERT_NO_FATAL_FAILURE(InitState());
10673 ASSERT_NO_FATAL_FAILURE(InitViewport());
10674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10675
10676 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010677 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060010678 pipe_ms_state_ci.pNext = NULL;
10679 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10680 pipe_ms_state_ci.sampleShadingEnable = 0;
10681 pipe_ms_state_ci.minSampleShading = 1.0;
10682 pipe_ms_state_ci.pSampleMask = nullptr;
10683
10684 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10685 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10686 VkPipelineLayout pipeline_layout;
10687
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010688 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060010689 ASSERT_VK_SUCCESS(err);
10690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010691 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
10692 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060010693 VkPipelineObj pipe(m_device);
10694 pipe.AddShader(&vs);
10695 pipe.AddShader(&fs);
10696 pipe.AddColorAttachment();
10697 pipe.SetMSAA(&pipe_ms_state_ci);
10698 pipe.SetViewport(m_viewports);
10699 pipe.SetScissor(m_scissors);
10700 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10701
Tony Barbour552f6c02016-12-21 14:34:07 -070010702 m_commandBuffer->BeginCommandBuffer();
10703 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010704 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060010705
10706 {
10707 // Create and bind a vertex buffer in a reduced scope, which will cause
10708 // it to be deleted upon leaving this scope
10709 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010710 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060010711 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
10712 draw_verticies.AddVertexInputToPipe(pipe);
10713 }
10714
10715 Draw(1, 0, 0, 0);
10716
Tony Barbour552f6c02016-12-21 14:34:07 -070010717 m_commandBuffer->EndRenderPass();
10718 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060010719
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060010721 QueueCommandBuffer(false);
10722 m_errorMonitor->VerifyFound();
10723
10724 {
10725 // Create and bind a vertex buffer in a reduced scope, and delete it
10726 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010727 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060010729 buffer_test.TestDoubleDestroy();
10730 }
10731 m_errorMonitor->VerifyFound();
10732
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010733 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010734 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
10736 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
10737 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010738 m_errorMonitor->VerifyFound();
10739 }
10740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010741 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
10742 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010743 // Create and bind a memory buffer with an invalid offset again,
10744 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
10746 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10747 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010748 m_errorMonitor->VerifyFound();
10749 }
10750
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010751 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010752 // Create and bind a memory buffer with an invalid offset again, but
10753 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
10755 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10756 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010757 m_errorMonitor->VerifyFound();
10758 }
10759
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010760 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060010761 // Create and bind a memory buffer with an invalid offset again, but
10762 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010763 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
10764 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
10765 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010766 m_errorMonitor->VerifyFound();
10767 }
10768
10769 {
10770 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010772 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
10773 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010774 m_errorMonitor->VerifyFound();
10775 }
10776
10777 {
10778 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010779 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010780 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
10781 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060010782 }
10783 m_errorMonitor->VerifyFound();
10784
10785 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10786}
10787
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010788// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
10789TEST_F(VkLayerTest, InvalidImageLayout) {
10790 TEST_DESCRIPTION("Hit all possible validation checks associated with the "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010791 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
10792 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010793 // 3 in ValidateCmdBufImageLayouts
10794 // * -1 Attempt to submit cmd buf w/ deleted image
10795 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
10796 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010797
10798 ASSERT_NO_FATAL_FAILURE(InitState());
10799 // Create src & dst images to use for copy operations
10800 VkImage src_image;
10801 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080010802 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010803
10804 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
10805 const int32_t tex_width = 32;
10806 const int32_t tex_height = 32;
10807
10808 VkImageCreateInfo image_create_info = {};
10809 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10810 image_create_info.pNext = NULL;
10811 image_create_info.imageType = VK_IMAGE_TYPE_2D;
10812 image_create_info.format = tex_format;
10813 image_create_info.extent.width = tex_width;
10814 image_create_info.extent.height = tex_height;
10815 image_create_info.extent.depth = 1;
10816 image_create_info.mipLevels = 1;
10817 image_create_info.arrayLayers = 4;
10818 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
10819 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
10820 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080010821 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010822 image_create_info.flags = 0;
10823
10824 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
10825 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010826 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010827 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
10828 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080010829 image_create_info.format = VK_FORMAT_D32_SFLOAT;
10830 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
10831 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
10832 ASSERT_VK_SUCCESS(err);
10833
10834 // Allocate memory
10835 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080010836 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080010837 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080010838 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10839 mem_alloc.pNext = NULL;
10840 mem_alloc.allocationSize = 0;
10841 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080010842
10843 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010844 mem_alloc.allocationSize = img_mem_reqs.size;
10845 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010846 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080010847 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080010848 ASSERT_VK_SUCCESS(err);
10849
10850 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010851 mem_alloc.allocationSize = img_mem_reqs.size;
10852 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010853 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010854 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080010855 ASSERT_VK_SUCCESS(err);
10856
10857 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080010858 mem_alloc.allocationSize = img_mem_reqs.size;
10859 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080010860 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080010861 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080010862 ASSERT_VK_SUCCESS(err);
10863
10864 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
10865 ASSERT_VK_SUCCESS(err);
10866 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
10867 ASSERT_VK_SUCCESS(err);
10868 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
10869 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010870
Tony Barbour552f6c02016-12-21 14:34:07 -070010871 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080010872 VkImageCopy copy_region;
10873 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10874 copy_region.srcSubresource.mipLevel = 0;
10875 copy_region.srcSubresource.baseArrayLayer = 0;
10876 copy_region.srcSubresource.layerCount = 1;
10877 copy_region.srcOffset.x = 0;
10878 copy_region.srcOffset.y = 0;
10879 copy_region.srcOffset.z = 0;
10880 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10881 copy_region.dstSubresource.mipLevel = 0;
10882 copy_region.dstSubresource.baseArrayLayer = 0;
10883 copy_region.dstSubresource.layerCount = 1;
10884 copy_region.dstOffset.x = 0;
10885 copy_region.dstOffset.y = 0;
10886 copy_region.dstOffset.z = 0;
10887 copy_region.extent.width = 1;
10888 copy_region.extent.height = 1;
10889 copy_region.extent.depth = 1;
10890
10891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10892 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
10893 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 -060010894 m_errorMonitor->VerifyFound();
10895 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose source layout is "
10897 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10898 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010899 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 -060010900 m_errorMonitor->VerifyFound();
10901 // Final src error is due to bad layout type
10902 m_errorMonitor->SetDesiredFailureMsg(
10903 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10904 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010905 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 -060010906 m_errorMonitor->VerifyFound();
10907 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10909 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010910 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 -060010911 m_errorMonitor->VerifyFound();
10912 // Now cause error due to src image layout changing
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot copy from an image whose dest layout is "
10914 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
10915 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010916 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 -060010917 m_errorMonitor->VerifyFound();
10918 m_errorMonitor->SetDesiredFailureMsg(
10919 VK_DEBUG_REPORT_ERROR_BIT_EXT,
10920 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080010921 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 -060010922 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010923
Cort3b021012016-12-07 12:00:57 -080010924 // Convert dst and depth images to TRANSFER_DST for subsequent tests
10925 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
10926 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10927 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
10928 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
10929 transfer_dst_image_barrier[0].srcAccessMask = 0;
10930 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
10931 transfer_dst_image_barrier[0].image = dst_image;
10932 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10933 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
10934 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10935 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10936 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10937 transfer_dst_image_barrier[0].image = depth_image;
10938 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
10939 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10940 NULL, 0, NULL, 1, transfer_dst_image_barrier);
10941
10942 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080010943 VkClearColorValue color_clear_value = {};
10944 VkImageSubresourceRange clear_range;
10945 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10946 clear_range.baseMipLevel = 0;
10947 clear_range.baseArrayLayer = 0;
10948 clear_range.layerCount = 1;
10949 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010950
Cort3b021012016-12-07 12:00:57 -080010951 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
10952 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
10954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010955 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010956 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010957 // Fail due to provided layout not matching actual current layout for color clear.
10958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080010959 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010960 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080010961
Cort530cf382016-12-08 09:59:47 -080010962 VkClearDepthStencilValue depth_clear_value = {};
10963 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080010964
10965 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
10966 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
10967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
10968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010969 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010970 m_errorMonitor->VerifyFound();
10971 // Fail due to provided layout not matching actual current layout for depth clear.
10972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080010973 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080010974 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010010975
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010976 // Now cause error due to bad image layout transition in PipelineBarrier
10977 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080010978 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010979 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080010980 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010981 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080010982 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
10983 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010984 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Alex Smithc4659e42017-01-10 09:51:22 +000010985 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 -060010986 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
10987 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
10988 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
10989 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060010990 m_errorMonitor->VerifyFound();
10991
10992 // Finally some layout errors at RenderPass create time
10993 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
10994 VkAttachmentReference attach = {};
10995 // perf warning for GENERAL layout w/ non-DS input attachment
10996 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
10997 VkSubpassDescription subpass = {};
10998 subpass.inputAttachmentCount = 1;
10999 subpass.pInputAttachments = &attach;
11000 VkRenderPassCreateInfo rpci = {};
11001 rpci.subpassCount = 1;
11002 rpci.pSubpasses = &subpass;
11003 rpci.attachmentCount = 1;
11004 VkAttachmentDescription attach_desc = {};
11005 attach_desc.format = VK_FORMAT_UNDEFINED;
11006 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011007 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011008 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011009 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11010 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011011 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11012 m_errorMonitor->VerifyFound();
11013 // error w/ non-general layout
11014 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11015
11016 m_errorMonitor->SetDesiredFailureMsg(
11017 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11018 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11019 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11020 m_errorMonitor->VerifyFound();
11021 subpass.inputAttachmentCount = 0;
11022 subpass.colorAttachmentCount = 1;
11023 subpass.pColorAttachments = &attach;
11024 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11025 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11027 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011028 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11029 m_errorMonitor->VerifyFound();
11030 // error w/ non-color opt or GENERAL layout for color attachment
11031 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11032 m_errorMonitor->SetDesiredFailureMsg(
11033 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11034 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11035 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11036 m_errorMonitor->VerifyFound();
11037 subpass.colorAttachmentCount = 0;
11038 subpass.pDepthStencilAttachment = &attach;
11039 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11040 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011041 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11042 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011043 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11044 m_errorMonitor->VerifyFound();
11045 // error w/ non-ds opt or GENERAL layout for color attachment
11046 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11048 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11049 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011050 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11051 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011052 // For this error we need a valid renderpass so create default one
11053 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11054 attach.attachment = 0;
11055 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11056 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11057 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11058 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11059 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11060 // Can't do a CLEAR load on READ_ONLY initialLayout
11061 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11062 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11063 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " with invalid first layout "
11065 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11066 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011067 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11068 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011069
Cort3b021012016-12-07 12:00:57 -080011070 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11071 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11072 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011073 vkDestroyImage(m_device->device(), src_image, NULL);
11074 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011075 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011076}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011077
Tobin Ehlise0936662016-10-11 08:10:51 -060011078TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11079 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11080 VkResult err;
11081
11082 ASSERT_NO_FATAL_FAILURE(InitState());
11083
11084 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11085 VkImageTiling tiling;
11086 VkFormatProperties format_properties;
11087 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11088 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11089 tiling = VK_IMAGE_TILING_LINEAR;
11090 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11091 tiling = VK_IMAGE_TILING_OPTIMAL;
11092 } else {
11093 printf("Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11094 "skipped.\n");
11095 return;
11096 }
11097
11098 VkDescriptorPoolSize ds_type = {};
11099 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11100 ds_type.descriptorCount = 1;
11101
11102 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11103 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11104 ds_pool_ci.maxSets = 1;
11105 ds_pool_ci.poolSizeCount = 1;
11106 ds_pool_ci.pPoolSizes = &ds_type;
11107 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11108
11109 VkDescriptorPool ds_pool;
11110 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11111 ASSERT_VK_SUCCESS(err);
11112
11113 VkDescriptorSetLayoutBinding dsl_binding = {};
11114 dsl_binding.binding = 0;
11115 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11116 dsl_binding.descriptorCount = 1;
11117 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11118 dsl_binding.pImmutableSamplers = NULL;
11119
11120 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11121 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11122 ds_layout_ci.pNext = NULL;
11123 ds_layout_ci.bindingCount = 1;
11124 ds_layout_ci.pBindings = &dsl_binding;
11125
11126 VkDescriptorSetLayout ds_layout;
11127 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11128 ASSERT_VK_SUCCESS(err);
11129
11130 VkDescriptorSetAllocateInfo alloc_info = {};
11131 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11132 alloc_info.descriptorSetCount = 1;
11133 alloc_info.descriptorPool = ds_pool;
11134 alloc_info.pSetLayouts = &ds_layout;
11135 VkDescriptorSet descriptor_set;
11136 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11137 ASSERT_VK_SUCCESS(err);
11138
11139 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11140 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11141 pipeline_layout_ci.pNext = NULL;
11142 pipeline_layout_ci.setLayoutCount = 1;
11143 pipeline_layout_ci.pSetLayouts = &ds_layout;
11144 VkPipelineLayout pipeline_layout;
11145 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11146 ASSERT_VK_SUCCESS(err);
11147
11148 VkImageObj image(m_device);
11149 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11150 ASSERT_TRUE(image.initialized());
11151 VkImageView view = image.targetView(tex_format);
11152
11153 VkDescriptorImageInfo image_info = {};
11154 image_info.imageView = view;
11155 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11156
11157 VkWriteDescriptorSet descriptor_write = {};
11158 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11159 descriptor_write.dstSet = descriptor_set;
11160 descriptor_write.dstBinding = 0;
11161 descriptor_write.descriptorCount = 1;
11162 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11163 descriptor_write.pImageInfo = &image_info;
11164
11165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11166 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11167 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11168 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11169 m_errorMonitor->VerifyFound();
11170
11171 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11172 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11173 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11174 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11175}
11176
Mark Mueller93b938f2016-08-18 10:27:40 -060011177TEST_F(VkLayerTest, SimultaneousUse) {
11178 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11179 "in primary and secondary command buffers.");
11180
11181 ASSERT_NO_FATAL_FAILURE(InitState());
11182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11183
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011184 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011185 const char *simultaneous_use_message2 = "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11186 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011187
11188 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011189 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011190 command_buffer_allocate_info.commandPool = m_commandPool;
11191 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11192 command_buffer_allocate_info.commandBufferCount = 1;
11193
11194 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011195 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011196 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11197 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011199 command_buffer_inheritance_info.renderPass = m_renderPass;
11200 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011201
Mark Mueller93b938f2016-08-18 10:27:40 -060011202 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011203 command_buffer_begin_info.flags =
11204 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011205 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11206
11207 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11208 vkEndCommandBuffer(secondary_command_buffer);
11209
Mark Mueller93b938f2016-08-18 10:27:40 -060011210 VkSubmitInfo submit_info = {};
11211 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11212 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011213 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011214
Mark Mueller4042b652016-09-05 22:52:21 -060011215 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011216 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11218 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011219 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011220 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011221 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11222 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011223
Dave Houltonfbf52152017-01-06 12:55:29 -070011224 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011225 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011226 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011227
Mark Mueller4042b652016-09-05 22:52:21 -060011228 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011229 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011230 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11233 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011234 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011235 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11236 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011237
11238 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011239}
11240
Tobin Ehlisb093da82017-01-19 12:05:27 -070011241TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
11242 TEST_DESCRIPTION("Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11243 "disabled on the device.");
11244
11245 ASSERT_NO_FATAL_FAILURE(InitState());
11246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11247
11248 std::vector<const char *> device_extension_names;
11249 auto features = m_device->phy().features();
11250 // Make sure gs & ts are disabled
11251 features.geometryShader = false;
11252 features.tessellationShader = false;
11253 // The sacrificial device object
11254 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11255
11256 VkCommandPoolCreateInfo pool_create_info{};
11257 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11258 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11259
11260 VkCommandPool command_pool;
11261 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11262
11263 VkCommandBufferAllocateInfo cmd = {};
11264 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11265 cmd.pNext = NULL;
11266 cmd.commandPool = command_pool;
11267 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11268 cmd.commandBufferCount = 1;
11269
11270 VkCommandBuffer cmd_buffer;
11271 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11272 ASSERT_VK_SUCCESS(err);
11273
11274 VkEvent event;
11275 VkEventCreateInfo evci = {};
11276 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11277 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11278 ASSERT_VK_SUCCESS(result);
11279
11280 VkCommandBufferBeginInfo cbbi = {};
11281 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11282 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11284 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11285 m_errorMonitor->VerifyFound();
11286
11287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11288 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11289 m_errorMonitor->VerifyFound();
11290
11291 vkDestroyEvent(test_device.handle(), event, NULL);
11292 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11293}
11294
Mark Mueller917f6bc2016-08-30 10:57:19 -060011295TEST_F(VkLayerTest, InUseDestroyedSignaled) {
11296 TEST_DESCRIPTION("Use vkCmdExecuteCommands with invalid state "
11297 "in primary and secondary command buffers. "
Mark Muellerc8d441e2016-08-23 17:36:00 -060011298 "Delete objects that are inuse. Call VkQueueSubmit "
11299 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011300
11301 ASSERT_NO_FATAL_FAILURE(InitState());
11302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011304 const char *submit_with_deleted_event_message = "Cannot submit cmd buffer using deleted event 0x";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011305 const char *cannot_destroy_fence_message = "Fence 0x";
Mark Mueller917f6bc2016-08-30 10:57:19 -060011306
Tony Barbour552f6c02016-12-21 14:34:07 -070011307 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011308
11309 VkEvent event;
11310 VkEventCreateInfo event_create_info = {};
11311 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11312 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011313 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011314
Tony Barbour552f6c02016-12-21 14:34:07 -070011315 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011316 vkDestroyEvent(m_device->device(), event, nullptr);
11317
11318 VkSubmitInfo submit_info = {};
11319 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11320 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011321 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, submit_with_deleted_event_message);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011323 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11324 m_errorMonitor->VerifyFound();
11325
Dave Houltonfbf52152017-01-06 12:55:29 -070011326 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011327 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11328
11329 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11330
Mark Mueller917f6bc2016-08-30 10:57:19 -060011331 VkSemaphoreCreateInfo semaphore_create_info = {};
11332 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11333 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011334 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011335 VkFenceCreateInfo fence_create_info = {};
11336 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11337 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011338 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011339
11340 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011341 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011342 descriptor_pool_type_count.descriptorCount = 1;
11343
11344 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11345 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11346 descriptor_pool_create_info.maxSets = 1;
11347 descriptor_pool_create_info.poolSizeCount = 1;
11348 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011349 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011350
11351 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011352 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011353
11354 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011355 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011356 descriptorset_layout_binding.descriptorCount = 1;
11357 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11358
11359 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011360 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011361 descriptorset_layout_create_info.bindingCount = 1;
11362 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11363
11364 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011365 ASSERT_VK_SUCCESS(
11366 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011367
11368 VkDescriptorSet descriptorset;
11369 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011370 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011371 descriptorset_allocate_info.descriptorSetCount = 1;
11372 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11373 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011374 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011375
Mark Mueller4042b652016-09-05 22:52:21 -060011376 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11377
11378 VkDescriptorBufferInfo buffer_info = {};
11379 buffer_info.buffer = buffer_test.GetBuffer();
11380 buffer_info.offset = 0;
11381 buffer_info.range = 1024;
11382
11383 VkWriteDescriptorSet write_descriptor_set = {};
11384 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11385 write_descriptor_set.dstSet = descriptorset;
11386 write_descriptor_set.descriptorCount = 1;
11387 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11388 write_descriptor_set.pBufferInfo = &buffer_info;
11389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011390 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011392 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11393 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011394
11395 VkPipelineObj pipe(m_device);
11396 pipe.AddColorAttachment();
11397 pipe.AddShader(&vs);
11398 pipe.AddShader(&fs);
11399
11400 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011401 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011402 pipeline_layout_create_info.setLayoutCount = 1;
11403 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11404
11405 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011406 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011407
11408 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11409
Tony Barbour552f6c02016-12-21 14:34:07 -070011410 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011411 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011412
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011413 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11414 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11415 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011416
Tony Barbour552f6c02016-12-21 14:34:07 -070011417 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011418
Mark Mueller917f6bc2016-08-30 10:57:19 -060011419 submit_info.signalSemaphoreCount = 1;
11420 submit_info.pSignalSemaphores = &semaphore;
11421 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Dave Houltonfbf52152017-01-06 12:55:29 -070011422 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011423
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011425 vkDestroyEvent(m_device->device(), event, nullptr);
11426 m_errorMonitor->VerifyFound();
11427
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011429 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11430 m_errorMonitor->VerifyFound();
11431
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, cannot_destroy_fence_message);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011433 vkDestroyFence(m_device->device(), fence, nullptr);
11434 m_errorMonitor->VerifyFound();
11435
Tobin Ehlis122207b2016-09-01 08:50:06 -070011436 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011437 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11438 vkDestroyFence(m_device->device(), fence, nullptr);
11439 vkDestroyEvent(m_device->device(), event, nullptr);
11440 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011441 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011442 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11443}
11444
Tobin Ehlis2adda372016-09-01 08:51:06 -070011445TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11446 TEST_DESCRIPTION("Delete in-use query pool.");
11447
11448 ASSERT_NO_FATAL_FAILURE(InitState());
11449 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11450
11451 VkQueryPool query_pool;
11452 VkQueryPoolCreateInfo query_pool_ci{};
11453 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11454 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11455 query_pool_ci.queryCount = 1;
11456 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011457 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011458 // Reset query pool to create binding with cmd buffer
11459 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11460
Tony Barbour552f6c02016-12-21 14:34:07 -070011461 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011462
11463 VkSubmitInfo submit_info = {};
11464 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11465 submit_info.commandBufferCount = 1;
11466 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11467 // Submit cmd buffer and then destroy query pool while in-flight
11468 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11469
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011470 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011471 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11472 m_errorMonitor->VerifyFound();
11473
11474 vkQueueWaitIdle(m_device->m_queue);
11475 // Now that cmd buffer done we can safely destroy query_pool
11476 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11477}
11478
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011479TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11480 TEST_DESCRIPTION("Delete in-use pipeline.");
11481
11482 ASSERT_NO_FATAL_FAILURE(InitState());
11483 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11484
11485 // Empty pipeline layout used for binding PSO
11486 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11487 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11488 pipeline_layout_ci.setLayoutCount = 0;
11489 pipeline_layout_ci.pSetLayouts = NULL;
11490
11491 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011492 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011493 ASSERT_VK_SUCCESS(err);
11494
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011496 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011497 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11498 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011499 // Store pipeline handle so we can actually delete it before test finishes
11500 VkPipeline delete_this_pipeline;
11501 { // Scope pipeline so it will be auto-deleted
11502 VkPipelineObj pipe(m_device);
11503 pipe.AddShader(&vs);
11504 pipe.AddShader(&fs);
11505 pipe.AddColorAttachment();
11506 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11507 delete_this_pipeline = pipe.handle();
11508
Tony Barbour552f6c02016-12-21 14:34:07 -070011509 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011510 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011511 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011512
Tony Barbour552f6c02016-12-21 14:34:07 -070011513 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011514
11515 VkSubmitInfo submit_info = {};
11516 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11517 submit_info.commandBufferCount = 1;
11518 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11519 // Submit cmd buffer and then pipeline destroyed while in-flight
11520 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11521 } // Pipeline deletion triggered here
11522 m_errorMonitor->VerifyFound();
11523 // Make sure queue finished and then actually delete pipeline
11524 vkQueueWaitIdle(m_device->m_queue);
11525 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11526 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11527}
11528
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011529TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11530 TEST_DESCRIPTION("Delete in-use imageView.");
11531
11532 ASSERT_NO_FATAL_FAILURE(InitState());
11533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11534
11535 VkDescriptorPoolSize ds_type_count;
11536 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11537 ds_type_count.descriptorCount = 1;
11538
11539 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11540 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11541 ds_pool_ci.maxSets = 1;
11542 ds_pool_ci.poolSizeCount = 1;
11543 ds_pool_ci.pPoolSizes = &ds_type_count;
11544
11545 VkDescriptorPool ds_pool;
11546 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11547 ASSERT_VK_SUCCESS(err);
11548
11549 VkSamplerCreateInfo sampler_ci = {};
11550 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11551 sampler_ci.pNext = NULL;
11552 sampler_ci.magFilter = VK_FILTER_NEAREST;
11553 sampler_ci.minFilter = VK_FILTER_NEAREST;
11554 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11555 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11556 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11557 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11558 sampler_ci.mipLodBias = 1.0;
11559 sampler_ci.anisotropyEnable = VK_FALSE;
11560 sampler_ci.maxAnisotropy = 1;
11561 sampler_ci.compareEnable = VK_FALSE;
11562 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11563 sampler_ci.minLod = 1.0;
11564 sampler_ci.maxLod = 1.0;
11565 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11566 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11567 VkSampler sampler;
11568
11569 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11570 ASSERT_VK_SUCCESS(err);
11571
11572 VkDescriptorSetLayoutBinding layout_binding;
11573 layout_binding.binding = 0;
11574 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11575 layout_binding.descriptorCount = 1;
11576 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11577 layout_binding.pImmutableSamplers = NULL;
11578
11579 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11580 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11581 ds_layout_ci.bindingCount = 1;
11582 ds_layout_ci.pBindings = &layout_binding;
11583 VkDescriptorSetLayout ds_layout;
11584 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11585 ASSERT_VK_SUCCESS(err);
11586
11587 VkDescriptorSetAllocateInfo alloc_info = {};
11588 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11589 alloc_info.descriptorSetCount = 1;
11590 alloc_info.descriptorPool = ds_pool;
11591 alloc_info.pSetLayouts = &ds_layout;
11592 VkDescriptorSet descriptor_set;
11593 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11594 ASSERT_VK_SUCCESS(err);
11595
11596 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11597 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11598 pipeline_layout_ci.pNext = NULL;
11599 pipeline_layout_ci.setLayoutCount = 1;
11600 pipeline_layout_ci.pSetLayouts = &ds_layout;
11601
11602 VkPipelineLayout pipeline_layout;
11603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11604 ASSERT_VK_SUCCESS(err);
11605
11606 VkImageObj image(m_device);
11607 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11608 ASSERT_TRUE(image.initialized());
11609
11610 VkImageView view;
11611 VkImageViewCreateInfo ivci = {};
11612 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11613 ivci.image = image.handle();
11614 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11615 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11616 ivci.subresourceRange.layerCount = 1;
11617 ivci.subresourceRange.baseMipLevel = 0;
11618 ivci.subresourceRange.levelCount = 1;
11619 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11620
11621 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11622 ASSERT_VK_SUCCESS(err);
11623
11624 VkDescriptorImageInfo image_info{};
11625 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11626 image_info.imageView = view;
11627 image_info.sampler = sampler;
11628
11629 VkWriteDescriptorSet descriptor_write = {};
11630 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11631 descriptor_write.dstSet = descriptor_set;
11632 descriptor_write.dstBinding = 0;
11633 descriptor_write.descriptorCount = 1;
11634 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11635 descriptor_write.pImageInfo = &image_info;
11636
11637 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11638
11639 // Create PSO to use the sampler
11640 char const *vsSource = "#version 450\n"
11641 "\n"
11642 "out gl_PerVertex { \n"
11643 " vec4 gl_Position;\n"
11644 "};\n"
11645 "void main(){\n"
11646 " gl_Position = vec4(1);\n"
11647 "}\n";
11648 char const *fsSource = "#version 450\n"
11649 "\n"
11650 "layout(set=0, binding=0) uniform sampler2D s;\n"
11651 "layout(location=0) out vec4 x;\n"
11652 "void main(){\n"
11653 " x = texture(s, vec2(1));\n"
11654 "}\n";
11655 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11656 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11657 VkPipelineObj pipe(m_device);
11658 pipe.AddShader(&vs);
11659 pipe.AddShader(&fs);
11660 pipe.AddColorAttachment();
11661 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11662
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011664
Tony Barbour552f6c02016-12-21 14:34:07 -070011665 m_commandBuffer->BeginCommandBuffer();
11666 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011667 // Bind pipeline to cmd buffer
11668 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11669 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11670 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070011671
11672 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11673 VkRect2D scissor = {{0, 0}, {16, 16}};
11674 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11675 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11676
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011677 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011678 m_commandBuffer->EndRenderPass();
11679 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011680 // Submit cmd buffer then destroy sampler
11681 VkSubmitInfo submit_info = {};
11682 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11683 submit_info.commandBufferCount = 1;
11684 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11685 // Submit cmd buffer and then destroy imageView while in-flight
11686 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11687
11688 vkDestroyImageView(m_device->device(), view, nullptr);
11689 m_errorMonitor->VerifyFound();
11690 vkQueueWaitIdle(m_device->m_queue);
11691 // Now we can actually destroy imageView
11692 vkDestroyImageView(m_device->device(), view, NULL);
11693 vkDestroySampler(m_device->device(), sampler, nullptr);
11694 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11695 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11696 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11697}
11698
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011699TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
11700 TEST_DESCRIPTION("Delete in-use bufferView.");
11701
11702 ASSERT_NO_FATAL_FAILURE(InitState());
11703 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11704
11705 VkDescriptorPoolSize ds_type_count;
11706 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11707 ds_type_count.descriptorCount = 1;
11708
11709 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11710 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11711 ds_pool_ci.maxSets = 1;
11712 ds_pool_ci.poolSizeCount = 1;
11713 ds_pool_ci.pPoolSizes = &ds_type_count;
11714
11715 VkDescriptorPool ds_pool;
11716 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11717 ASSERT_VK_SUCCESS(err);
11718
11719 VkDescriptorSetLayoutBinding layout_binding;
11720 layout_binding.binding = 0;
11721 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11722 layout_binding.descriptorCount = 1;
11723 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11724 layout_binding.pImmutableSamplers = NULL;
11725
11726 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11727 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11728 ds_layout_ci.bindingCount = 1;
11729 ds_layout_ci.pBindings = &layout_binding;
11730 VkDescriptorSetLayout ds_layout;
11731 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11732 ASSERT_VK_SUCCESS(err);
11733
11734 VkDescriptorSetAllocateInfo alloc_info = {};
11735 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11736 alloc_info.descriptorSetCount = 1;
11737 alloc_info.descriptorPool = ds_pool;
11738 alloc_info.pSetLayouts = &ds_layout;
11739 VkDescriptorSet descriptor_set;
11740 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11741 ASSERT_VK_SUCCESS(err);
11742
11743 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11744 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11745 pipeline_layout_ci.pNext = NULL;
11746 pipeline_layout_ci.setLayoutCount = 1;
11747 pipeline_layout_ci.pSetLayouts = &ds_layout;
11748
11749 VkPipelineLayout pipeline_layout;
11750 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11751 ASSERT_VK_SUCCESS(err);
11752
11753 VkBuffer buffer;
11754 uint32_t queue_family_index = 0;
11755 VkBufferCreateInfo buffer_create_info = {};
11756 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
11757 buffer_create_info.size = 1024;
11758 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
11759 buffer_create_info.queueFamilyIndexCount = 1;
11760 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
11761
11762 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
11763 ASSERT_VK_SUCCESS(err);
11764
11765 VkMemoryRequirements memory_reqs;
11766 VkDeviceMemory buffer_memory;
11767
11768 VkMemoryAllocateInfo memory_info = {};
11769 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11770 memory_info.allocationSize = 0;
11771 memory_info.memoryTypeIndex = 0;
11772
11773 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
11774 memory_info.allocationSize = memory_reqs.size;
11775 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
11776 ASSERT_TRUE(pass);
11777
11778 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
11779 ASSERT_VK_SUCCESS(err);
11780 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
11781 ASSERT_VK_SUCCESS(err);
11782
11783 VkBufferView view;
11784 VkBufferViewCreateInfo bvci = {};
11785 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
11786 bvci.buffer = buffer;
11787 bvci.format = VK_FORMAT_R8_UNORM;
11788 bvci.range = VK_WHOLE_SIZE;
11789
11790 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
11791 ASSERT_VK_SUCCESS(err);
11792
11793 VkWriteDescriptorSet descriptor_write = {};
11794 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11795 descriptor_write.dstSet = descriptor_set;
11796 descriptor_write.dstBinding = 0;
11797 descriptor_write.descriptorCount = 1;
11798 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
11799 descriptor_write.pTexelBufferView = &view;
11800
11801 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11802
11803 char const *vsSource = "#version 450\n"
11804 "\n"
11805 "out gl_PerVertex { \n"
11806 " vec4 gl_Position;\n"
11807 "};\n"
11808 "void main(){\n"
11809 " gl_Position = vec4(1);\n"
11810 "}\n";
11811 char const *fsSource = "#version 450\n"
11812 "\n"
11813 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
11814 "layout(location=0) out vec4 x;\n"
11815 "void main(){\n"
11816 " x = imageLoad(s, 0);\n"
11817 "}\n";
11818 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11819 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11820 VkPipelineObj pipe(m_device);
11821 pipe.AddShader(&vs);
11822 pipe.AddShader(&fs);
11823 pipe.AddColorAttachment();
11824 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11825
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011827
Tony Barbour552f6c02016-12-21 14:34:07 -070011828 m_commandBuffer->BeginCommandBuffer();
11829 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011830 VkViewport viewport = {0, 0, 16, 16, 0, 1};
11831 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
11832 VkRect2D scissor = {{0, 0}, {16, 16}};
11833 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
11834 // Bind pipeline to cmd buffer
11835 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11836 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11837 &descriptor_set, 0, nullptr);
11838 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070011839 m_commandBuffer->EndRenderPass();
11840 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060011841
11842 VkSubmitInfo submit_info = {};
11843 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11844 submit_info.commandBufferCount = 1;
11845 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11846 // Submit cmd buffer and then destroy bufferView while in-flight
11847 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11848
11849 vkDestroyBufferView(m_device->device(), view, nullptr);
11850 m_errorMonitor->VerifyFound();
11851 vkQueueWaitIdle(m_device->m_queue);
11852 // Now we can actually destroy bufferView
11853 vkDestroyBufferView(m_device->device(), view, NULL);
11854 vkDestroyBuffer(m_device->device(), buffer, NULL);
11855 vkFreeMemory(m_device->device(), buffer_memory, NULL);
11856 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11857 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11858 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11859}
11860
Tobin Ehlis209532e2016-09-07 13:52:18 -060011861TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
11862 TEST_DESCRIPTION("Delete in-use sampler.");
11863
11864 ASSERT_NO_FATAL_FAILURE(InitState());
11865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11866
11867 VkDescriptorPoolSize ds_type_count;
11868 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11869 ds_type_count.descriptorCount = 1;
11870
11871 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11872 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11873 ds_pool_ci.maxSets = 1;
11874 ds_pool_ci.poolSizeCount = 1;
11875 ds_pool_ci.pPoolSizes = &ds_type_count;
11876
11877 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011878 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011879 ASSERT_VK_SUCCESS(err);
11880
11881 VkSamplerCreateInfo sampler_ci = {};
11882 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11883 sampler_ci.pNext = NULL;
11884 sampler_ci.magFilter = VK_FILTER_NEAREST;
11885 sampler_ci.minFilter = VK_FILTER_NEAREST;
11886 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11887 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11888 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11889 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11890 sampler_ci.mipLodBias = 1.0;
11891 sampler_ci.anisotropyEnable = VK_FALSE;
11892 sampler_ci.maxAnisotropy = 1;
11893 sampler_ci.compareEnable = VK_FALSE;
11894 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11895 sampler_ci.minLod = 1.0;
11896 sampler_ci.maxLod = 1.0;
11897 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11898 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11899 VkSampler sampler;
11900
11901 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11902 ASSERT_VK_SUCCESS(err);
11903
11904 VkDescriptorSetLayoutBinding layout_binding;
11905 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060011906 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060011907 layout_binding.descriptorCount = 1;
11908 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11909 layout_binding.pImmutableSamplers = NULL;
11910
11911 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11912 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11913 ds_layout_ci.bindingCount = 1;
11914 ds_layout_ci.pBindings = &layout_binding;
11915 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011916 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011917 ASSERT_VK_SUCCESS(err);
11918
11919 VkDescriptorSetAllocateInfo alloc_info = {};
11920 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11921 alloc_info.descriptorSetCount = 1;
11922 alloc_info.descriptorPool = ds_pool;
11923 alloc_info.pSetLayouts = &ds_layout;
11924 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011925 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011926 ASSERT_VK_SUCCESS(err);
11927
11928 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11929 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11930 pipeline_layout_ci.pNext = NULL;
11931 pipeline_layout_ci.setLayoutCount = 1;
11932 pipeline_layout_ci.pSetLayouts = &ds_layout;
11933
11934 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011935 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011936 ASSERT_VK_SUCCESS(err);
11937
11938 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011939 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 -060011940 ASSERT_TRUE(image.initialized());
11941
11942 VkImageView view;
11943 VkImageViewCreateInfo ivci = {};
11944 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11945 ivci.image = image.handle();
11946 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11947 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11948 ivci.subresourceRange.layerCount = 1;
11949 ivci.subresourceRange.baseMipLevel = 0;
11950 ivci.subresourceRange.levelCount = 1;
11951 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11952
11953 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
11954 ASSERT_VK_SUCCESS(err);
11955
11956 VkDescriptorImageInfo image_info{};
11957 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11958 image_info.imageView = view;
11959 image_info.sampler = sampler;
11960
11961 VkWriteDescriptorSet descriptor_write = {};
11962 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11963 descriptor_write.dstSet = descriptor_set;
11964 descriptor_write.dstBinding = 0;
11965 descriptor_write.descriptorCount = 1;
11966 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11967 descriptor_write.pImageInfo = &image_info;
11968
11969 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11970
11971 // Create PSO to use the sampler
11972 char const *vsSource = "#version 450\n"
11973 "\n"
11974 "out gl_PerVertex { \n"
11975 " vec4 gl_Position;\n"
11976 "};\n"
11977 "void main(){\n"
11978 " gl_Position = vec4(1);\n"
11979 "}\n";
11980 char const *fsSource = "#version 450\n"
11981 "\n"
11982 "layout(set=0, binding=0) uniform sampler2D s;\n"
11983 "layout(location=0) out vec4 x;\n"
11984 "void main(){\n"
11985 " x = texture(s, vec2(1));\n"
11986 "}\n";
11987 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
11988 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
11989 VkPipelineObj pipe(m_device);
11990 pipe.AddShader(&vs);
11991 pipe.AddShader(&fs);
11992 pipe.AddColorAttachment();
11993 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11994
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011996
Tony Barbour552f6c02016-12-21 14:34:07 -070011997 m_commandBuffer->BeginCommandBuffer();
11998 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060011999 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012000 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12001 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12002 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012003
12004 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12005 VkRect2D scissor = {{0, 0}, {16, 16}};
12006 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12007 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12008
Tobin Ehlis209532e2016-09-07 13:52:18 -060012009 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012010 m_commandBuffer->EndRenderPass();
12011 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012012 // Submit cmd buffer then destroy sampler
12013 VkSubmitInfo submit_info = {};
12014 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12015 submit_info.commandBufferCount = 1;
12016 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12017 // Submit cmd buffer and then destroy sampler while in-flight
12018 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12019
Rene Lindsay4da11732017-01-13 14:42:10 -070012020 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012021 m_errorMonitor->VerifyFound();
12022 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012023
Tobin Ehlis209532e2016-09-07 13:52:18 -060012024 // Now we can actually destroy sampler
Rene Lindsay4da11732017-01-13 14:42:10 -070012025 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012026 vkDestroyImageView(m_device->device(), view, NULL);
12027 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12028 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12029 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12030}
12031
Mark Mueller1cd9f412016-08-25 13:23:52 -060012032TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Mueller96a56d52016-08-24 10:28:05 -060012033 TEST_DESCRIPTION("Call VkQueueSubmit with a semaphore that is already "
Mark Mueller1cd9f412016-08-25 13:23:52 -060012034 "signaled but not waited on by the queue. Wait on a "
12035 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012036
12037 ASSERT_NO_FATAL_FAILURE(InitState());
12038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012040 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
12041 const char *invalid_fence_wait_message = " which has not been submitted on a Queue or during "
12042 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012043
Tony Barbour552f6c02016-12-21 14:34:07 -070012044 m_commandBuffer->BeginCommandBuffer();
12045 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012046
12047 VkSemaphoreCreateInfo semaphore_create_info = {};
12048 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12049 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012050 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012051 VkSubmitInfo submit_info = {};
12052 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12053 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012054 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012055 submit_info.signalSemaphoreCount = 1;
12056 submit_info.pSignalSemaphores = &semaphore;
12057 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012058 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012059 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012060 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012061 m_commandBuffer->BeginCommandBuffer();
12062 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012064 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12065 m_errorMonitor->VerifyFound();
12066
Mark Mueller1cd9f412016-08-25 13:23:52 -060012067 VkFenceCreateInfo fence_create_info = {};
12068 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12069 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012070 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012073 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12074 m_errorMonitor->VerifyFound();
12075
Mark Mueller4042b652016-09-05 22:52:21 -060012076 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012077 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012078 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12079}
12080
Tobin Ehlis4af23302016-07-19 10:50:30 -060012081TEST_F(VkLayerTest, FramebufferIncompatible) {
12082 TEST_DESCRIPTION("Bind a secondary command buffer with with a framebuffer "
12083 "that does not match the framebuffer for the active "
12084 "renderpass.");
12085 ASSERT_NO_FATAL_FAILURE(InitState());
12086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12087
12088 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012089 VkAttachmentDescription attachment = {0,
12090 VK_FORMAT_B8G8R8A8_UNORM,
12091 VK_SAMPLE_COUNT_1_BIT,
12092 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12093 VK_ATTACHMENT_STORE_OP_STORE,
12094 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12095 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12096 VK_IMAGE_LAYOUT_UNDEFINED,
12097 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012099 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012100
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012101 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012102
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012103 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012104
12105 VkRenderPass rp;
12106 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12107 ASSERT_VK_SUCCESS(err);
12108
12109 // A compatible framebuffer.
12110 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012111 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 -060012112 ASSERT_TRUE(image.initialized());
12113
12114 VkImageViewCreateInfo ivci = {
12115 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12116 nullptr,
12117 0,
12118 image.handle(),
12119 VK_IMAGE_VIEW_TYPE_2D,
12120 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012121 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12122 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012123 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12124 };
12125 VkImageView view;
12126 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12127 ASSERT_VK_SUCCESS(err);
12128
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012129 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012130 VkFramebuffer fb;
12131 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12132 ASSERT_VK_SUCCESS(err);
12133
12134 VkCommandBufferAllocateInfo cbai = {};
12135 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12136 cbai.commandPool = m_commandPool;
12137 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12138 cbai.commandBufferCount = 1;
12139
12140 VkCommandBuffer sec_cb;
12141 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12142 ASSERT_VK_SUCCESS(err);
12143 VkCommandBufferBeginInfo cbbi = {};
12144 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012145 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012146 cbii.renderPass = renderPass();
12147 cbii.framebuffer = fb;
12148 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12149 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012150 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 -060012151 cbbi.pInheritanceInfo = &cbii;
12152 vkBeginCommandBuffer(sec_cb, &cbbi);
12153 vkEndCommandBuffer(sec_cb);
12154
Chris Forbes3400bc52016-09-13 18:10:34 +120012155 VkCommandBufferBeginInfo cbbi2 = {
12156 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
12157 0, nullptr
12158 };
12159 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12160 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012163 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012164 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12165 m_errorMonitor->VerifyFound();
12166 // Cleanup
12167 vkDestroyImageView(m_device->device(), view, NULL);
12168 vkDestroyRenderPass(m_device->device(), rp, NULL);
12169 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12170}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012171
12172TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
12173 TEST_DESCRIPTION("If logicOp is available on the device, set it to an "
12174 "invalid value. If logicOp is not available, attempt to "
12175 "use it and verify that we see the correct error.");
12176 ASSERT_NO_FATAL_FAILURE(InitState());
12177 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12178
12179 auto features = m_device->phy().features();
12180 // Set the expected error depending on whether or not logicOp available
12181 if (VK_FALSE == features.logicOp) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If logic operations feature not "
12183 "enabled, logicOpEnable must be "
12184 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012185 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012187 }
12188 // Create a pipeline using logicOp
12189 VkResult err;
12190
12191 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12192 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12193
12194 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012195 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012196 ASSERT_VK_SUCCESS(err);
12197
12198 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12199 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12200 vp_state_ci.viewportCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012201 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012202 vp_state_ci.pViewports = &vp;
12203 vp_state_ci.scissorCount = 1;
12204 VkRect2D scissors = {}; // Dummy scissors to point to
12205 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012206
12207 VkPipelineShaderStageCreateInfo shaderStages[2];
12208 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12209
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012210 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12211 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012212 shaderStages[0] = vs.GetStageCreateInfo();
12213 shaderStages[1] = fs.GetStageCreateInfo();
12214
12215 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12216 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12217
12218 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12219 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12220 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12221
12222 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12223 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012224 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012225
12226 VkPipelineColorBlendAttachmentState att = {};
12227 att.blendEnable = VK_FALSE;
12228 att.colorWriteMask = 0xf;
12229
12230 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12231 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12232 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12233 cb_ci.logicOpEnable = VK_TRUE;
12234 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
12235 cb_ci.attachmentCount = 1;
12236 cb_ci.pAttachments = &att;
12237
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012238 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12239 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12240 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12241
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012242 VkGraphicsPipelineCreateInfo gp_ci = {};
12243 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12244 gp_ci.stageCount = 2;
12245 gp_ci.pStages = shaderStages;
12246 gp_ci.pVertexInputState = &vi_ci;
12247 gp_ci.pInputAssemblyState = &ia_ci;
12248 gp_ci.pViewportState = &vp_state_ci;
12249 gp_ci.pRasterizationState = &rs_ci;
12250 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012251 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012252 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12253 gp_ci.layout = pipeline_layout;
12254 gp_ci.renderPass = renderPass();
12255
12256 VkPipelineCacheCreateInfo pc_ci = {};
12257 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12258
12259 VkPipeline pipeline;
12260 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012261 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012262 ASSERT_VK_SUCCESS(err);
12263
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012264 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012265 m_errorMonitor->VerifyFound();
12266 if (VK_SUCCESS == err) {
12267 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12268 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012269 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12270 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12271}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012272#endif // DRAW_STATE_TESTS
12273
Tobin Ehlis0788f522015-05-26 16:11:58 -060012274#if THREADING_TESTS
Mike Stroyanaccf7692015-05-12 16:00:45 -060012275#if GTEST_IS_THREADSAFE
12276struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012277 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012278 VkEvent event;
12279 bool bailout;
12280};
12281
Karl Schultz6addd812016-02-02 17:17:23 -070012282extern "C" void *AddToCommandBuffer(void *arg) {
12283 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012284
Mike Stroyana6d14942016-07-13 15:10:05 -060012285 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012286 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012287 if (data->bailout) {
12288 break;
12289 }
12290 }
12291 return NULL;
12292}
12293
Karl Schultz6addd812016-02-02 17:17:23 -070012294TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012295 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012296
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012298
Mike Stroyanaccf7692015-05-12 16:00:45 -060012299 ASSERT_NO_FATAL_FAILURE(InitState());
12300 ASSERT_NO_FATAL_FAILURE(InitViewport());
12301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12302
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012303 // Calls AllocateCommandBuffers
12304 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012305
12306 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012307 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012308
12309 VkEventCreateInfo event_info;
12310 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012311 VkResult err;
12312
12313 memset(&event_info, 0, sizeof(event_info));
12314 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12315
Chia-I Wuf7458c52015-10-26 21:10:41 +080012316 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012317 ASSERT_VK_SUCCESS(err);
12318
Mike Stroyanaccf7692015-05-12 16:00:45 -060012319 err = vkResetEvent(device(), event);
12320 ASSERT_VK_SUCCESS(err);
12321
12322 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012323 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012324 data.event = event;
12325 data.bailout = false;
12326 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012327
12328 // First do some correct operations using multiple threads.
12329 // Add many entries to command buffer from another thread.
12330 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12331 // Make non-conflicting calls from this thread at the same time.
12332 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012333 uint32_t count;
12334 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012335 }
12336 test_platform_thread_join(thread, NULL);
12337
12338 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012339 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012340 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012341 // Add many entries to command buffer from this thread at the same time.
12342 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012343
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012344 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012345 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012346
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012347 m_errorMonitor->SetBailout(NULL);
12348
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012349 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012350
Chia-I Wuf7458c52015-10-26 21:10:41 +080012351 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012352}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012353#endif // GTEST_IS_THREADSAFE
12354#endif // THREADING_TESTS
12355
Chris Forbes9f7ff632015-05-25 11:13:08 +120012356#if SHADER_CHECKER_TESTS
Karl Schultz6addd812016-02-02 17:17:23 -070012357TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012358 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12359 "with an impossible code size");
12360
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012362
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012363 ASSERT_NO_FATAL_FAILURE(InitState());
12364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12365
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012366 VkShaderModule module;
12367 VkShaderModuleCreateInfo moduleCreateInfo;
12368 struct icd_spv_header spv;
12369
12370 spv.magic = ICD_SPV_MAGIC;
12371 spv.version = ICD_SPV_VERSION;
12372 spv.gen_magic = 0;
12373
12374 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12375 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012376 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012377 moduleCreateInfo.codeSize = 4;
12378 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012379 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012380
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012381 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012382}
12383
Karl Schultz6addd812016-02-02 17:17:23 -070012384TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012385 TEST_DESCRIPTION("Test that an error is produced for a spirv module "
12386 "with a bad magic number");
12387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012389
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012390 ASSERT_NO_FATAL_FAILURE(InitState());
12391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12392
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012393 VkShaderModule module;
12394 VkShaderModuleCreateInfo moduleCreateInfo;
12395 struct icd_spv_header spv;
12396
12397 spv.magic = ~ICD_SPV_MAGIC;
12398 spv.version = ICD_SPV_VERSION;
12399 spv.gen_magic = 0;
12400
12401 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12402 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012403 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012404 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12405 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012406 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012407
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012408 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012409}
12410
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012411#if 0
12412// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012413TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012415 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012416
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012417 ASSERT_NO_FATAL_FAILURE(InitState());
12418 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12419
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012420 VkShaderModule module;
12421 VkShaderModuleCreateInfo moduleCreateInfo;
12422 struct icd_spv_header spv;
12423
12424 spv.magic = ICD_SPV_MAGIC;
12425 spv.version = ~ICD_SPV_VERSION;
12426 spv.gen_magic = 0;
12427
12428 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12429 moduleCreateInfo.pNext = NULL;
12430
Karl Schultz6addd812016-02-02 17:17:23 -070012431 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012432 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12433 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012434 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012435
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012436 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012437}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012438#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012439
Karl Schultz6addd812016-02-02 17:17:23 -070012440TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012441 TEST_DESCRIPTION("Test that a warning is produced for a vertex output that "
12442 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012444
Chris Forbes9f7ff632015-05-25 11:13:08 +120012445 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012446 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012448 char const *vsSource = "#version 450\n"
12449 "\n"
12450 "layout(location=0) out float x;\n"
12451 "out gl_PerVertex {\n"
12452 " vec4 gl_Position;\n"
12453 "};\n"
12454 "void main(){\n"
12455 " gl_Position = vec4(1);\n"
12456 " x = 0;\n"
12457 "}\n";
12458 char const *fsSource = "#version 450\n"
12459 "\n"
12460 "layout(location=0) out vec4 color;\n"
12461 "void main(){\n"
12462 " color = vec4(1);\n"
12463 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012464
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012465 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12466 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012467
12468 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012469 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012470 pipe.AddShader(&vs);
12471 pipe.AddShader(&fs);
12472
Chris Forbes9f7ff632015-05-25 11:13:08 +120012473 VkDescriptorSetObj descriptorSet(m_device);
12474 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012475 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012476
Tony Barbour5781e8f2015-08-04 16:23:11 -060012477 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012478
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012479 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012480}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012481
Mark Mueller098c9cb2016-09-08 09:01:57 -060012482TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12483 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12484
12485 ASSERT_NO_FATAL_FAILURE(InitState());
12486 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12487
12488 const char *bad_specialization_message =
12489 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
12490
12491 char const *vsSource =
12492 "#version 450\n"
12493 "\n"
12494 "out gl_PerVertex {\n"
12495 " vec4 gl_Position;\n"
12496 "};\n"
12497 "void main(){\n"
12498 " gl_Position = vec4(1);\n"
12499 "}\n";
12500
12501 char const *fsSource =
12502 "#version 450\n"
12503 "\n"
12504 "layout (constant_id = 0) const float r = 0.0f;\n"
12505 "layout(location = 0) out vec4 uFragColor;\n"
12506 "void main(){\n"
12507 " uFragColor = vec4(r,1,0,1);\n"
12508 "}\n";
12509
12510 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12511 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12512
12513 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12514 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12515
12516 VkPipelineLayout pipeline_layout;
12517 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12518
12519 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12520 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12521 vp_state_create_info.viewportCount = 1;
12522 VkViewport viewport = {};
12523 vp_state_create_info.pViewports = &viewport;
12524 vp_state_create_info.scissorCount = 1;
12525 VkRect2D scissors = {};
12526 vp_state_create_info.pScissors = &scissors;
12527
12528 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12529
12530 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12531 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12532 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12533 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12534
12535 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {
12536 vs.GetStageCreateInfo(),
12537 fs.GetStageCreateInfo()
12538 };
12539
12540 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12541 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12542
12543 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12544 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12545 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12546
12547 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12548 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12549 rasterization_state_create_info.pNext = nullptr;
12550 rasterization_state_create_info.lineWidth = 1.0f;
12551 rasterization_state_create_info.rasterizerDiscardEnable = true;
12552
12553 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12554 color_blend_attachment_state.blendEnable = VK_FALSE;
12555 color_blend_attachment_state.colorWriteMask = 0xf;
12556
12557 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12558 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12559 color_blend_state_create_info.attachmentCount = 1;
12560 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12561
12562 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12563 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12564 graphicspipe_create_info.stageCount = 2;
12565 graphicspipe_create_info.pStages = shader_stage_create_info;
12566 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12567 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12568 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12569 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12570 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12571 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12572 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12573 graphicspipe_create_info.layout = pipeline_layout;
12574 graphicspipe_create_info.renderPass = renderPass();
12575
12576 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12577 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12578
12579 VkPipelineCache pipelineCache;
12580 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12581
12582 // This structure maps constant ids to data locations.
12583 const VkSpecializationMapEntry entry =
12584 // id, offset, size
12585 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
12586
12587 uint32_t data = 1;
12588
12589 // Set up the info describing spec map and data
12590 const VkSpecializationInfo specialization_info = {
12591 1,
12592 &entry,
12593 1 * sizeof(float),
12594 &data,
12595 };
12596 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12597
12598 VkPipeline pipeline;
12599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12600 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12601 m_errorMonitor->VerifyFound();
12602
12603 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12604 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12605}
12606
12607TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12608 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12609
12610 ASSERT_NO_FATAL_FAILURE(InitState());
12611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12612
12613 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12614
12615 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12616 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12617 descriptor_pool_type_count[0].descriptorCount = 1;
12618 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12619 descriptor_pool_type_count[1].descriptorCount = 1;
12620
12621 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12622 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12623 descriptor_pool_create_info.maxSets = 1;
12624 descriptor_pool_create_info.poolSizeCount = 2;
12625 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
12626 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12627
12628 VkDescriptorPool descriptorset_pool;
12629 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12630
12631 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12632 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
12633 descriptorset_layout_binding.descriptorCount = 1;
12634 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12635
12636 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12637 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12638 descriptorset_layout_create_info.bindingCount = 1;
12639 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12640
12641 VkDescriptorSetLayout descriptorset_layout;
12642 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
12643
12644 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12645 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12646 descriptorset_allocate_info.descriptorSetCount = 1;
12647 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12648 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12649 VkDescriptorSet descriptorset;
12650 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12651
12652 // Challenge core_validation with a non uniform buffer type.
12653 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
12654
Mark Mueller098c9cb2016-09-08 09:01:57 -060012655 char const *vsSource =
12656 "#version 450\n"
12657 "\n"
12658 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12659 " mat4 mvp;\n"
12660 "} ubuf;\n"
12661 "out gl_PerVertex {\n"
12662 " vec4 gl_Position;\n"
12663 "};\n"
12664 "void main(){\n"
12665 " gl_Position = ubuf.mvp * vec4(1);\n"
12666 "}\n";
12667
12668 char const *fsSource =
12669 "#version 450\n"
12670 "\n"
12671 "layout(location = 0) out vec4 uFragColor;\n"
12672 "void main(){\n"
12673 " uFragColor = vec4(0,1,0,1);\n"
12674 "}\n";
12675
12676 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12677 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12678
12679 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12680 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12681 pipeline_layout_create_info.setLayoutCount = 1;
12682 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12683
12684 VkPipelineLayout pipeline_layout;
12685 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12686
12687 VkPipelineObj pipe(m_device);
12688 pipe.AddColorAttachment();
12689 pipe.AddShader(&vs);
12690 pipe.AddShader(&fs);
12691
12692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
12693 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12694 m_errorMonitor->VerifyFound();
12695
12696 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12697 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12698 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12699}
12700
12701TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
12702 TEST_DESCRIPTION(
12703 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
12704
12705 ASSERT_NO_FATAL_FAILURE(InitState());
12706 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12707
12708 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
12709
12710 VkDescriptorPoolSize descriptor_pool_type_count = {};
12711 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12712 descriptor_pool_type_count.descriptorCount = 1;
12713
12714 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12715 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12716 descriptor_pool_create_info.maxSets = 1;
12717 descriptor_pool_create_info.poolSizeCount = 1;
12718 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
12719 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12720
12721 VkDescriptorPool descriptorset_pool;
12722 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
12723
12724 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
12725 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12726 descriptorset_layout_binding.descriptorCount = 1;
12727 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
12728 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12729
12730 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
12731 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12732 descriptorset_layout_create_info.bindingCount = 1;
12733 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12734
12735 VkDescriptorSetLayout descriptorset_layout;
12736 ASSERT_VK_SUCCESS(vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info,
12737 nullptr, &descriptorset_layout));
12738
12739 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
12740 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12741 descriptorset_allocate_info.descriptorSetCount = 1;
12742 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12743 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
12744 VkDescriptorSet descriptorset;
12745 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
12746
12747 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12748
Mark Mueller098c9cb2016-09-08 09:01:57 -060012749 char const *vsSource =
12750 "#version 450\n"
12751 "\n"
12752 "layout (std140, set = 0, binding = 0) uniform buf {\n"
12753 " mat4 mvp;\n"
12754 "} ubuf;\n"
12755 "out gl_PerVertex {\n"
12756 " vec4 gl_Position;\n"
12757 "};\n"
12758 "void main(){\n"
12759 " gl_Position = ubuf.mvp * vec4(1);\n"
12760 "}\n";
12761
12762 char const *fsSource =
12763 "#version 450\n"
12764 "\n"
12765 "layout(location = 0) out vec4 uFragColor;\n"
12766 "void main(){\n"
12767 " uFragColor = vec4(0,1,0,1);\n"
12768 "}\n";
12769
12770 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12771 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12772
12773 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12774 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12775 pipeline_layout_create_info.setLayoutCount = 1;
12776 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12777
12778 VkPipelineLayout pipeline_layout;
12779 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12780
12781 VkPipelineObj pipe(m_device);
12782 pipe.AddColorAttachment();
12783 pipe.AddShader(&vs);
12784 pipe.AddShader(&fs);
12785
12786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
12787 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12788 m_errorMonitor->VerifyFound();
12789
12790 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12791 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
12792 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
12793}
12794
12795TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
12796 TEST_DESCRIPTION("Create a graphics pipleine in which a push constant range containing a push constant block member is not "
12797 "accessible from the current shader stage.");
12798
12799 ASSERT_NO_FATAL_FAILURE(InitState());
12800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12801
12802 const char *push_constant_not_accessible_message =
12803 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
12804
12805 char const *vsSource =
12806 "#version 450\n"
12807 "\n"
12808 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
12809 "out gl_PerVertex {\n"
12810 " vec4 gl_Position;\n"
12811 "};\n"
12812 "void main(){\n"
12813 " gl_Position = vec4(consts.x);\n"
12814 "}\n";
12815
12816 char const *fsSource =
12817 "#version 450\n"
12818 "\n"
12819 "layout(location = 0) out vec4 uFragColor;\n"
12820 "void main(){\n"
12821 " uFragColor = vec4(0,1,0,1);\n"
12822 "}\n";
12823
12824 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12825 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12826
12827 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12828 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12829
12830 // Set up a push constant range
12831 VkPushConstantRange push_constant_ranges = {};
12832 // Set to the wrong stage to challenge core_validation
12833 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12834 push_constant_ranges.size = 4;
12835
12836 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
12837 pipeline_layout_create_info.pushConstantRangeCount = 1;
12838
12839 VkPipelineLayout pipeline_layout;
12840 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12841
12842 VkPipelineObj pipe(m_device);
12843 pipe.AddColorAttachment();
12844 pipe.AddShader(&vs);
12845 pipe.AddShader(&fs);
12846
12847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
12848 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12849 m_errorMonitor->VerifyFound();
12850
12851 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12852}
12853
12854TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
12855 TEST_DESCRIPTION(
12856 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
12857
12858 ASSERT_NO_FATAL_FAILURE(InitState());
12859 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12860
12861 const char *feature_not_enabled_message =
12862 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
12863
12864 // Some awkward steps are required to test with custom device features.
12865 std::vector<const char *> device_extension_names;
12866 auto features = m_device->phy().features();
12867 // Disable support for 64 bit floats
12868 features.shaderFloat64 = false;
12869 // The sacrificial device object
12870 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12871
12872 char const *vsSource = "#version 450\n"
12873 "\n"
12874 "out gl_PerVertex {\n"
12875 " vec4 gl_Position;\n"
12876 "};\n"
12877 "void main(){\n"
12878 " gl_Position = vec4(1);\n"
12879 "}\n";
12880 char const *fsSource = "#version 450\n"
12881 "\n"
12882 "layout(location=0) out vec4 color;\n"
12883 "void main(){\n"
12884 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12885 " color = vec4(green);\n"
12886 "}\n";
12887
12888 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12889 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12890
12891 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060012892
12893 VkPipelineObj pipe(&test_device);
12894 pipe.AddColorAttachment();
12895 pipe.AddShader(&vs);
12896 pipe.AddShader(&fs);
12897
12898 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12899 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12900 VkPipelineLayout pipeline_layout;
12901 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12902
12903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
12904 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
12905 m_errorMonitor->VerifyFound();
12906
12907 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
12908}
12909
12910TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
12911 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
12912
12913 ASSERT_NO_FATAL_FAILURE(InitState());
12914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12915
12916 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
12917
12918 char const *vsSource = "#version 450\n"
12919 "\n"
12920 "out gl_PerVertex {\n"
12921 " vec4 gl_Position;\n"
12922 "};\n"
12923 "layout(xfb_buffer = 1) out;"
12924 "void main(){\n"
12925 " gl_Position = vec4(1);\n"
12926 "}\n";
12927 char const *fsSource = "#version 450\n"
12928 "\n"
12929 "layout(location=0) out vec4 color;\n"
12930 "void main(){\n"
12931 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
12932 " color = vec4(green);\n"
12933 "}\n";
12934
12935 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12936 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12937
12938 VkPipelineObj pipe(m_device);
12939 pipe.AddColorAttachment();
12940 pipe.AddShader(&vs);
12941 pipe.AddShader(&fs);
12942
12943 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12944 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12945 VkPipelineLayout pipeline_layout;
12946 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12947
12948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
12949 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12950 m_errorMonitor->VerifyFound();
12951
12952 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12953}
12954
Karl Schultz6addd812016-02-02 17:17:23 -070012955TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012956 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12957 "which is not present in the outputs of the previous stage");
12958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012960
Chris Forbes59cb88d2015-05-25 11:13:13 +120012961 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012962 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012963
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012964 char const *vsSource = "#version 450\n"
12965 "\n"
12966 "out gl_PerVertex {\n"
12967 " vec4 gl_Position;\n"
12968 "};\n"
12969 "void main(){\n"
12970 " gl_Position = vec4(1);\n"
12971 "}\n";
12972 char const *fsSource = "#version 450\n"
12973 "\n"
12974 "layout(location=0) in float x;\n"
12975 "layout(location=0) out vec4 color;\n"
12976 "void main(){\n"
12977 " color = vec4(x);\n"
12978 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120012979
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012980 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12981 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012982
12983 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012984 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012985 pipe.AddShader(&vs);
12986 pipe.AddShader(&fs);
12987
Chris Forbes59cb88d2015-05-25 11:13:13 +120012988 VkDescriptorSetObj descriptorSet(m_device);
12989 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012990 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120012991
Tony Barbour5781e8f2015-08-04 16:23:11 -060012992 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120012993
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012994 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120012995}
12996
Karl Schultz6addd812016-02-02 17:17:23 -070012997TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120012998 TEST_DESCRIPTION("Test that an error is produced for a fragment shader input "
12999 "within an interace block, which is not present in the outputs "
13000 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013002
13003 ASSERT_NO_FATAL_FAILURE(InitState());
13004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013006 char const *vsSource = "#version 450\n"
13007 "\n"
13008 "out gl_PerVertex {\n"
13009 " vec4 gl_Position;\n"
13010 "};\n"
13011 "void main(){\n"
13012 " gl_Position = vec4(1);\n"
13013 "}\n";
13014 char const *fsSource = "#version 450\n"
13015 "\n"
13016 "in block { layout(location=0) float x; } ins;\n"
13017 "layout(location=0) out vec4 color;\n"
13018 "void main(){\n"
13019 " color = vec4(ins.x);\n"
13020 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013021
13022 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13023 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13024
13025 VkPipelineObj pipe(m_device);
13026 pipe.AddColorAttachment();
13027 pipe.AddShader(&vs);
13028 pipe.AddShader(&fs);
13029
13030 VkDescriptorSetObj descriptorSet(m_device);
13031 descriptorSet.AppendDummy();
13032 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13033
13034 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13035
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013036 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013037}
13038
Karl Schultz6addd812016-02-02 17:17:23 -070013039TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013040 TEST_DESCRIPTION("Test that an error is produced for mismatched array sizes "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013041 "across the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0.0: 'ptr to "
13043 "output arr[2] of float32' vs 'ptr to "
Rene Lindsay479c2fa2017-01-10 11:43:26 -070013044 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013045
13046 ASSERT_NO_FATAL_FAILURE(InitState());
13047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13048
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013049 char const *vsSource = "#version 450\n"
13050 "\n"
13051 "layout(location=0) out float x[2];\n"
13052 "out gl_PerVertex {\n"
13053 " vec4 gl_Position;\n"
13054 "};\n"
13055 "void main(){\n"
13056 " x[0] = 0; x[1] = 0;\n"
13057 " gl_Position = vec4(1);\n"
13058 "}\n";
13059 char const *fsSource = "#version 450\n"
13060 "\n"
Rene Lindsay479c2fa2017-01-10 11:43:26 -070013061 "layout(location=0) in float x[1];\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013062 "layout(location=0) out vec4 color;\n"
13063 "void main(){\n"
Rene Lindsay479c2fa2017-01-10 11:43:26 -070013064 " color = vec4(x[0]);\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013065 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013066
13067 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13068 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13069
13070 VkPipelineObj pipe(m_device);
13071 pipe.AddColorAttachment();
13072 pipe.AddShader(&vs);
13073 pipe.AddShader(&fs);
13074
13075 VkDescriptorSetObj descriptorSet(m_device);
13076 descriptorSet.AppendDummy();
13077 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13078
13079 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13080
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013081 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013082}
13083
Karl Schultz6addd812016-02-02 17:17:23 -070013084TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013085 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013086 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013088
Chris Forbesb56af562015-05-25 11:13:17 +120013089 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013092 char const *vsSource = "#version 450\n"
13093 "\n"
13094 "layout(location=0) out int x;\n"
13095 "out gl_PerVertex {\n"
13096 " vec4 gl_Position;\n"
13097 "};\n"
13098 "void main(){\n"
13099 " x = 0;\n"
13100 " gl_Position = vec4(1);\n"
13101 "}\n";
13102 char const *fsSource = "#version 450\n"
13103 "\n"
13104 "layout(location=0) in float x;\n" /* VS writes int */
13105 "layout(location=0) out vec4 color;\n"
13106 "void main(){\n"
13107 " color = vec4(x);\n"
13108 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013109
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013110 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13111 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013112
13113 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013114 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013115 pipe.AddShader(&vs);
13116 pipe.AddShader(&fs);
13117
Chris Forbesb56af562015-05-25 11:13:17 +120013118 VkDescriptorSetObj descriptorSet(m_device);
13119 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013120 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013121
Tony Barbour5781e8f2015-08-04 16:23:11 -060013122 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013123
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013124 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013125}
13126
Karl Schultz6addd812016-02-02 17:17:23 -070013127TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013128 TEST_DESCRIPTION("Test that an error is produced for mismatched types across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013129 "the vertex->fragment shader interface, when the variable is contained within "
Chris Forbes1cc79542016-07-20 11:13:44 +120013130 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013132
13133 ASSERT_NO_FATAL_FAILURE(InitState());
13134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013136 char const *vsSource = "#version 450\n"
13137 "\n"
13138 "out block { layout(location=0) int x; } outs;\n"
13139 "out gl_PerVertex {\n"
13140 " vec4 gl_Position;\n"
13141 "};\n"
13142 "void main(){\n"
13143 " outs.x = 0;\n"
13144 " gl_Position = vec4(1);\n"
13145 "}\n";
13146 char const *fsSource = "#version 450\n"
13147 "\n"
13148 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13149 "layout(location=0) out vec4 color;\n"
13150 "void main(){\n"
13151 " color = vec4(ins.x);\n"
13152 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013153
13154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13156
13157 VkPipelineObj pipe(m_device);
13158 pipe.AddColorAttachment();
13159 pipe.AddShader(&vs);
13160 pipe.AddShader(&fs);
13161
13162 VkDescriptorSetObj descriptorSet(m_device);
13163 descriptorSet.AppendDummy();
13164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13165
13166 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13167
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013168 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013169}
13170
13171TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013172 TEST_DESCRIPTION("Test that an error is produced for location mismatches across "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013173 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
Chris Forbes1cc79542016-07-20 11:13:44 +120013174 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013175 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 +130013176
13177 ASSERT_NO_FATAL_FAILURE(InitState());
13178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13179
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013180 char const *vsSource = "#version 450\n"
13181 "\n"
13182 "out block { layout(location=1) float x; } outs;\n"
13183 "out gl_PerVertex {\n"
13184 " vec4 gl_Position;\n"
13185 "};\n"
13186 "void main(){\n"
13187 " outs.x = 0;\n"
13188 " gl_Position = vec4(1);\n"
13189 "}\n";
13190 char const *fsSource = "#version 450\n"
13191 "\n"
13192 "in block { layout(location=0) float x; } ins;\n"
13193 "layout(location=0) out vec4 color;\n"
13194 "void main(){\n"
13195 " color = vec4(ins.x);\n"
13196 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013197
13198 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13199 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13200
13201 VkPipelineObj pipe(m_device);
13202 pipe.AddColorAttachment();
13203 pipe.AddShader(&vs);
13204 pipe.AddShader(&fs);
13205
13206 VkDescriptorSetObj descriptorSet(m_device);
13207 descriptorSet.AppendDummy();
13208 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13209
13210 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13211
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013212 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013213}
13214
13215TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013216 TEST_DESCRIPTION("Test that an error is produced for component mismatches across the "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013217 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
Chris Forbes1cc79542016-07-20 11:13:44 +120013218 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013219 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 +130013220
13221 ASSERT_NO_FATAL_FAILURE(InitState());
13222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13223
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013224 char const *vsSource = "#version 450\n"
13225 "\n"
13226 "out block { layout(location=0, component=0) float x; } outs;\n"
13227 "out gl_PerVertex {\n"
13228 " vec4 gl_Position;\n"
13229 "};\n"
13230 "void main(){\n"
13231 " outs.x = 0;\n"
13232 " gl_Position = vec4(1);\n"
13233 "}\n";
13234 char const *fsSource = "#version 450\n"
13235 "\n"
13236 "in block { layout(location=0, component=1) float x; } ins;\n"
13237 "layout(location=0) out vec4 color;\n"
13238 "void main(){\n"
13239 " color = vec4(ins.x);\n"
13240 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013241
13242 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13243 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13244
13245 VkPipelineObj pipe(m_device);
13246 pipe.AddColorAttachment();
13247 pipe.AddShader(&vs);
13248 pipe.AddShader(&fs);
13249
13250 VkDescriptorSetObj descriptorSet(m_device);
13251 descriptorSet.AppendDummy();
13252 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13253
13254 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13255
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013256 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013257}
13258
Chris Forbes1f3b0152016-11-30 12:48:40 +130013259TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13260 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13261
13262 ASSERT_NO_FATAL_FAILURE(InitState());
13263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13264
13265 char const *vsSource = "#version 450\n"
13266 "layout(location=0) out mediump float x;\n"
13267 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13268 char const *fsSource = "#version 450\n"
13269 "layout(location=0) in highp float x;\n"
13270 "layout(location=0) out vec4 color;\n"
13271 "void main() { color = vec4(x); }\n";
13272
13273 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13274 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13275
13276 VkPipelineObj pipe(m_device);
13277 pipe.AddColorAttachment();
13278 pipe.AddShader(&vs);
13279 pipe.AddShader(&fs);
13280
13281 VkDescriptorSetObj descriptorSet(m_device);
13282 descriptorSet.AppendDummy();
13283 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13284
13285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13286
13287 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13288
13289 m_errorMonitor->VerifyFound();
13290}
13291
Chris Forbes870a39e2016-11-30 12:55:56 +130013292TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13293 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13294
13295 ASSERT_NO_FATAL_FAILURE(InitState());
13296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13297
13298 char const *vsSource = "#version 450\n"
13299 "out block { layout(location=0) mediump float x; };\n"
13300 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13301 char const *fsSource = "#version 450\n"
13302 "in block { layout(location=0) highp float x; };\n"
13303 "layout(location=0) out vec4 color;\n"
13304 "void main() { color = vec4(x); }\n";
13305
13306 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13307 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13308
13309 VkPipelineObj pipe(m_device);
13310 pipe.AddColorAttachment();
13311 pipe.AddShader(&vs);
13312 pipe.AddShader(&fs);
13313
13314 VkDescriptorSetObj descriptorSet(m_device);
13315 descriptorSet.AppendDummy();
13316 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13317
13318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13319
13320 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13321
13322 m_errorMonitor->VerifyFound();
13323}
13324
Karl Schultz6addd812016-02-02 17:17:23 -070013325TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013326 TEST_DESCRIPTION("Test that a warning is produced for a vertex attribute which is "
13327 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013329
Chris Forbesde136e02015-05-25 11:13:28 +120013330 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013332
13333 VkVertexInputBindingDescription input_binding;
13334 memset(&input_binding, 0, sizeof(input_binding));
13335
13336 VkVertexInputAttributeDescription input_attrib;
13337 memset(&input_attrib, 0, sizeof(input_attrib));
13338 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13339
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013340 char const *vsSource = "#version 450\n"
13341 "\n"
13342 "out gl_PerVertex {\n"
13343 " vec4 gl_Position;\n"
13344 "};\n"
13345 "void main(){\n"
13346 " gl_Position = vec4(1);\n"
13347 "}\n";
13348 char const *fsSource = "#version 450\n"
13349 "\n"
13350 "layout(location=0) out vec4 color;\n"
13351 "void main(){\n"
13352 " color = vec4(1);\n"
13353 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013354
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013355 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13356 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013357
13358 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013359 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013360 pipe.AddShader(&vs);
13361 pipe.AddShader(&fs);
13362
13363 pipe.AddVertexInputBindings(&input_binding, 1);
13364 pipe.AddVertexInputAttribs(&input_attrib, 1);
13365
Chris Forbesde136e02015-05-25 11:13:28 +120013366 VkDescriptorSetObj descriptorSet(m_device);
13367 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013368 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013369
Tony Barbour5781e8f2015-08-04 16:23:11 -060013370 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013371
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013372 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013373}
13374
Karl Schultz6addd812016-02-02 17:17:23 -070013375TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013376 TEST_DESCRIPTION("Test that a warning is produced for a location mismatch on "
13377 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013379
13380 ASSERT_NO_FATAL_FAILURE(InitState());
13381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13382
13383 VkVertexInputBindingDescription input_binding;
13384 memset(&input_binding, 0, sizeof(input_binding));
13385
13386 VkVertexInputAttributeDescription input_attrib;
13387 memset(&input_attrib, 0, sizeof(input_attrib));
13388 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013390 char const *vsSource = "#version 450\n"
13391 "\n"
13392 "layout(location=1) in float x;\n"
13393 "out gl_PerVertex {\n"
13394 " vec4 gl_Position;\n"
13395 "};\n"
13396 "void main(){\n"
13397 " gl_Position = vec4(x);\n"
13398 "}\n";
13399 char const *fsSource = "#version 450\n"
13400 "\n"
13401 "layout(location=0) out vec4 color;\n"
13402 "void main(){\n"
13403 " color = vec4(1);\n"
13404 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013405
13406 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13407 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13408
13409 VkPipelineObj pipe(m_device);
13410 pipe.AddColorAttachment();
13411 pipe.AddShader(&vs);
13412 pipe.AddShader(&fs);
13413
13414 pipe.AddVertexInputBindings(&input_binding, 1);
13415 pipe.AddVertexInputAttribs(&input_attrib, 1);
13416
13417 VkDescriptorSetObj descriptorSet(m_device);
13418 descriptorSet.AppendDummy();
13419 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13420
13421 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13422
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013423 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013424}
13425
Karl Schultz6addd812016-02-02 17:17:23 -070013426TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013427 TEST_DESCRIPTION("Test that an error is produced for a vertex shader input which is not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013428 "provided by a vertex attribute");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013429 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 -060013430
Chris Forbes62e8e502015-05-25 11:13:29 +120013431 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013433
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013434 char const *vsSource = "#version 450\n"
13435 "\n"
13436 "layout(location=0) in vec4 x;\n" /* not provided */
13437 "out gl_PerVertex {\n"
13438 " vec4 gl_Position;\n"
13439 "};\n"
13440 "void main(){\n"
13441 " gl_Position = x;\n"
13442 "}\n";
13443 char const *fsSource = "#version 450\n"
13444 "\n"
13445 "layout(location=0) out vec4 color;\n"
13446 "void main(){\n"
13447 " color = vec4(1);\n"
13448 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013449
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013450 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13451 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013452
13453 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013454 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013455 pipe.AddShader(&vs);
13456 pipe.AddShader(&fs);
13457
Chris Forbes62e8e502015-05-25 11:13:29 +120013458 VkDescriptorSetObj descriptorSet(m_device);
13459 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013460 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013461
Tony Barbour5781e8f2015-08-04 16:23:11 -060013462 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013463
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013464 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013465}
13466
Karl Schultz6addd812016-02-02 17:17:23 -070013467TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013468 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the "
13469 "fundamental type (float/int/uint) of an attribute and the "
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013470 "vertex shader input that consumes it");
13471 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 -060013472
Chris Forbesc97d98e2015-05-25 11:13:31 +120013473 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013474 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013475
13476 VkVertexInputBindingDescription input_binding;
13477 memset(&input_binding, 0, sizeof(input_binding));
13478
13479 VkVertexInputAttributeDescription input_attrib;
13480 memset(&input_attrib, 0, sizeof(input_attrib));
13481 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13482
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013483 char const *vsSource = "#version 450\n"
13484 "\n"
13485 "layout(location=0) in int x;\n" /* attrib provided float */
13486 "out gl_PerVertex {\n"
13487 " vec4 gl_Position;\n"
13488 "};\n"
13489 "void main(){\n"
13490 " gl_Position = vec4(x);\n"
13491 "}\n";
13492 char const *fsSource = "#version 450\n"
13493 "\n"
13494 "layout(location=0) out vec4 color;\n"
13495 "void main(){\n"
13496 " color = vec4(1);\n"
13497 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013498
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013501
13502 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013503 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013504 pipe.AddShader(&vs);
13505 pipe.AddShader(&fs);
13506
13507 pipe.AddVertexInputBindings(&input_binding, 1);
13508 pipe.AddVertexInputAttribs(&input_attrib, 1);
13509
Chris Forbesc97d98e2015-05-25 11:13:31 +120013510 VkDescriptorSetObj descriptorSet(m_device);
13511 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013512 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013513
Tony Barbour5781e8f2015-08-04 16:23:11 -060013514 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013515
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013516 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013517}
13518
Chris Forbesc68b43c2016-04-06 11:18:47 +120013519TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013520 TEST_DESCRIPTION("Test that an error is produced for a pipeline containing multiple "
13521 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13523 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013524
13525 ASSERT_NO_FATAL_FAILURE(InitState());
13526 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13527
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013528 char const *vsSource = "#version 450\n"
13529 "\n"
13530 "out gl_PerVertex {\n"
13531 " vec4 gl_Position;\n"
13532 "};\n"
13533 "void main(){\n"
13534 " gl_Position = vec4(1);\n"
13535 "}\n";
13536 char const *fsSource = "#version 450\n"
13537 "\n"
13538 "layout(location=0) out vec4 color;\n"
13539 "void main(){\n"
13540 " color = vec4(1);\n"
13541 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013542
13543 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13544 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13545
13546 VkPipelineObj pipe(m_device);
13547 pipe.AddColorAttachment();
13548 pipe.AddShader(&vs);
Mike Weiblencce7ec72016-10-17 19:33:05 -060013549 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013550 pipe.AddShader(&fs);
13551
13552 VkDescriptorSetObj descriptorSet(m_device);
13553 descriptorSet.AppendDummy();
13554 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13555
13556 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13557
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013558 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013559}
13560
Chris Forbes82ff92a2016-09-09 10:50:24 +120013561TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
13562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13563 "No entrypoint found named `foo`");
13564
13565 ASSERT_NO_FATAL_FAILURE(InitState());
13566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13567
13568 char const *vsSource = "#version 450\n"
13569 "out gl_PerVertex {\n"
13570 " vec4 gl_Position;\n"
13571 "};\n"
13572 "void main(){\n"
13573 " gl_Position = vec4(0);\n"
13574 "}\n";
13575 char const *fsSource = "#version 450\n"
13576 "\n"
13577 "layout(location=0) out vec4 color;\n"
13578 "void main(){\n"
13579 " color = vec4(1);\n"
13580 "}\n";
13581
13582 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13583 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
13584
13585 VkPipelineObj pipe(m_device);
13586 pipe.AddColorAttachment();
13587 pipe.AddShader(&vs);
13588 pipe.AddShader(&fs);
13589
13590 VkDescriptorSetObj descriptorSet(m_device);
13591 descriptorSet.AppendDummy();
13592 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13593
13594 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13595
13596 m_errorMonitor->VerifyFound();
13597}
13598
Chris Forbesae9d8cd2016-09-13 16:32:57 +120013599TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
13600 m_errorMonitor->SetDesiredFailureMsg(
13601 VK_DEBUG_REPORT_ERROR_BIT_EXT,
13602 "pDepthStencilState is NULL when rasterization is enabled and subpass "
13603 "uses a depth/stencil attachment");
13604
13605 ASSERT_NO_FATAL_FAILURE(InitState());
13606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13607
13608 char const *vsSource = "#version 450\n"
13609 "void main(){ gl_Position = vec4(0); }\n";
13610 char const *fsSource = "#version 450\n"
13611 "\n"
13612 "layout(location=0) out vec4 color;\n"
13613 "void main(){\n"
13614 " color = vec4(1);\n"
13615 "}\n";
13616
13617 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13618 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13619
13620 VkPipelineObj pipe(m_device);
13621 pipe.AddColorAttachment();
13622 pipe.AddShader(&vs);
13623 pipe.AddShader(&fs);
13624
13625 VkDescriptorSetObj descriptorSet(m_device);
13626 descriptorSet.AppendDummy();
13627 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13628
13629 VkAttachmentDescription attachments[] = {
13630 { 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT,
13631 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13632 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13633 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
13634 },
13635 { 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT,
13636 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13637 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
13638 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
13639 },
13640 };
13641 VkAttachmentReference refs[] = {
13642 { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
13643 { 1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL },
13644 };
13645 VkSubpassDescription subpass = {
13646 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr,
13647 1, &refs[0], nullptr, &refs[1],
13648 0, nullptr
13649 };
13650 VkRenderPassCreateInfo rpci = {
13651 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr,
13652 0, 2, attachments, 1, &subpass, 0, nullptr
13653 };
13654 VkRenderPass rp;
13655 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13656 ASSERT_VK_SUCCESS(err);
13657
13658 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
13659
13660 m_errorMonitor->VerifyFound();
13661
13662 vkDestroyRenderPass(m_device->device(), rp, nullptr);
13663}
13664
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013665TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013666 TEST_DESCRIPTION("Test that an error is produced for a variable output from "
13667 "the TCS without the patch decoration, but consumed in the TES "
13668 "with the decoration.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is per-vertex in tessellation control shader stage "
13670 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120013671
13672 ASSERT_NO_FATAL_FAILURE(InitState());
13673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13674
Chris Forbesc1e852d2016-04-04 19:26:42 +120013675 if (!m_device->phy().features().tessellationShader) {
13676 printf("Device does not support tessellation shaders; skipped.\n");
13677 return;
13678 }
13679
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013680 char const *vsSource = "#version 450\n"
13681 "void main(){}\n";
13682 char const *tcsSource = "#version 450\n"
13683 "layout(location=0) out int x[];\n"
13684 "layout(vertices=3) out;\n"
13685 "void main(){\n"
13686 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
13687 " gl_TessLevelInner[0] = 1;\n"
13688 " x[gl_InvocationID] = gl_InvocationID;\n"
13689 "}\n";
13690 char const *tesSource = "#version 450\n"
13691 "layout(triangles, equal_spacing, cw) in;\n"
13692 "layout(location=0) patch in int x;\n"
13693 "out gl_PerVertex { vec4 gl_Position; };\n"
13694 "void main(){\n"
13695 " gl_Position.xyz = gl_TessCoord;\n"
13696 " gl_Position.w = x;\n"
13697 "}\n";
13698 char const *fsSource = "#version 450\n"
13699 "layout(location=0) out vec4 color;\n"
13700 "void main(){\n"
13701 " color = vec4(1);\n"
13702 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120013703
13704 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13705 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
13706 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
13707 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013709 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
13710 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013712 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120013713
13714 VkPipelineObj pipe(m_device);
13715 pipe.SetInputAssembly(&iasci);
13716 pipe.SetTessellation(&tsci);
13717 pipe.AddColorAttachment();
13718 pipe.AddShader(&vs);
13719 pipe.AddShader(&tcs);
13720 pipe.AddShader(&tes);
13721 pipe.AddShader(&fs);
13722
13723 VkDescriptorSetObj descriptorSet(m_device);
13724 descriptorSet.AppendDummy();
13725 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13726
13727 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13728
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013729 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120013730}
13731
Karl Schultz6addd812016-02-02 17:17:23 -070013732TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013733 TEST_DESCRIPTION("Test that an error is produced for a vertex attribute setup where multiple "
13734 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13736 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013737
Chris Forbes280ba2c2015-06-12 11:16:41 +120013738 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013739 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013740
13741 /* Two binding descriptions for binding 0 */
13742 VkVertexInputBindingDescription input_bindings[2];
13743 memset(input_bindings, 0, sizeof(input_bindings));
13744
13745 VkVertexInputAttributeDescription input_attrib;
13746 memset(&input_attrib, 0, sizeof(input_attrib));
13747 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013749 char const *vsSource = "#version 450\n"
13750 "\n"
13751 "layout(location=0) in float x;\n" /* attrib provided float */
13752 "out gl_PerVertex {\n"
13753 " vec4 gl_Position;\n"
13754 "};\n"
13755 "void main(){\n"
13756 " gl_Position = vec4(x);\n"
13757 "}\n";
13758 char const *fsSource = "#version 450\n"
13759 "\n"
13760 "layout(location=0) out vec4 color;\n"
13761 "void main(){\n"
13762 " color = vec4(1);\n"
13763 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120013764
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013765 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13766 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013767
13768 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013769 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013770 pipe.AddShader(&vs);
13771 pipe.AddShader(&fs);
13772
13773 pipe.AddVertexInputBindings(input_bindings, 2);
13774 pipe.AddVertexInputAttribs(&input_attrib, 1);
13775
Chris Forbes280ba2c2015-06-12 11:16:41 +120013776 VkDescriptorSetObj descriptorSet(m_device);
13777 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013778 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120013779
Tony Barbour5781e8f2015-08-04 16:23:11 -060013780 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120013781
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013782 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120013783}
Chris Forbes8f68b562015-05-25 11:13:32 +120013784
Karl Schultz6addd812016-02-02 17:17:23 -070013785TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013786 TEST_DESCRIPTION("Test that an error is produced for a fragment shader which does not "
Chris Forbes1cc79542016-07-20 11:13:44 +120013787 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013789
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013790 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013791
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013792 char const *vsSource = "#version 450\n"
13793 "\n"
13794 "out gl_PerVertex {\n"
13795 " vec4 gl_Position;\n"
13796 "};\n"
13797 "void main(){\n"
13798 " gl_Position = vec4(1);\n"
13799 "}\n";
13800 char const *fsSource = "#version 450\n"
13801 "\n"
13802 "void main(){\n"
13803 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013804
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013805 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13806 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013807
13808 VkPipelineObj pipe(m_device);
13809 pipe.AddShader(&vs);
13810 pipe.AddShader(&fs);
13811
Chia-I Wu08accc62015-07-07 11:50:03 +080013812 /* set up CB 0, not written */
13813 pipe.AddColorAttachment();
13814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013815
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013816 VkDescriptorSetObj descriptorSet(m_device);
13817 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013818 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013819
Tony Barbour5781e8f2015-08-04 16:23:11 -060013820 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013821
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013822 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120013823}
13824
Karl Schultz6addd812016-02-02 17:17:23 -070013825TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mike Weiblencce7ec72016-10-17 19:33:05 -060013826 TEST_DESCRIPTION("Test that a warning is produced for a fragment shader which provides a spurious "
Chris Forbes1cc79542016-07-20 11:13:44 +120013827 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013829 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013830
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013831 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013832
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013833 char const *vsSource = "#version 450\n"
13834 "\n"
13835 "out gl_PerVertex {\n"
13836 " vec4 gl_Position;\n"
13837 "};\n"
13838 "void main(){\n"
13839 " gl_Position = vec4(1);\n"
13840 "}\n";
13841 char const *fsSource = "#version 450\n"
13842 "\n"
13843 "layout(location=0) out vec4 x;\n"
13844 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
13845 "void main(){\n"
13846 " x = vec4(1);\n"
13847 " y = vec4(1);\n"
13848 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013849
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013850 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13851 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013852
13853 VkPipelineObj pipe(m_device);
13854 pipe.AddShader(&vs);
13855 pipe.AddShader(&fs);
13856
Chia-I Wu08accc62015-07-07 11:50:03 +080013857 /* set up CB 0, not written */
13858 pipe.AddColorAttachment();
13859 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013860 /* FS writes CB 1, but we don't configure it */
13861
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013862 VkDescriptorSetObj descriptorSet(m_device);
13863 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013864 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013865
Tony Barbour5781e8f2015-08-04 16:23:11 -060013866 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013867
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013868 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120013869}
13870
Karl Schultz6addd812016-02-02 17:17:23 -070013871TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013872 TEST_DESCRIPTION("Test that an error is produced for a mismatch between the fundamental "
Mike Weiblencce7ec72016-10-17 19:33:05 -060013873 "type of an fragment shader output variable, and the format of the corresponding attachment");
13874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013875
Chris Forbesa36d69e2015-05-25 11:13:44 +120013876 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013877
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013878 char const *vsSource = "#version 450\n"
13879 "\n"
13880 "out gl_PerVertex {\n"
13881 " vec4 gl_Position;\n"
13882 "};\n"
13883 "void main(){\n"
13884 " gl_Position = vec4(1);\n"
13885 "}\n";
13886 char const *fsSource = "#version 450\n"
13887 "\n"
13888 "layout(location=0) out ivec4 x;\n" /* not UNORM */
13889 "void main(){\n"
13890 " x = ivec4(1);\n"
13891 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120013892
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013893 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13894 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013895
13896 VkPipelineObj pipe(m_device);
13897 pipe.AddShader(&vs);
13898 pipe.AddShader(&fs);
13899
Chia-I Wu08accc62015-07-07 11:50:03 +080013900 /* set up CB 0; type is UNORM by default */
13901 pipe.AddColorAttachment();
13902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013903
Chris Forbesa36d69e2015-05-25 11:13:44 +120013904 VkDescriptorSetObj descriptorSet(m_device);
13905 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013906 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120013907
Tony Barbour5781e8f2015-08-04 16:23:11 -060013908 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120013909
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013910 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120013911}
Chris Forbes7b1b8932015-06-05 14:43:36 +120013912
Karl Schultz6addd812016-02-02 17:17:23 -070013913TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013914 TEST_DESCRIPTION("Test that an error is produced for a shader consuming a uniform "
13915 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013917
Chris Forbes556c76c2015-08-14 12:04:59 +120013918 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120013919
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013920 char const *vsSource = "#version 450\n"
13921 "\n"
13922 "out gl_PerVertex {\n"
13923 " vec4 gl_Position;\n"
13924 "};\n"
13925 "void main(){\n"
13926 " gl_Position = vec4(1);\n"
13927 "}\n";
13928 char const *fsSource = "#version 450\n"
13929 "\n"
13930 "layout(location=0) out vec4 x;\n"
13931 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
13932 "void main(){\n"
13933 " x = vec4(bar.y);\n"
13934 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120013935
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013936 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13937 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120013938
Chris Forbes556c76c2015-08-14 12:04:59 +120013939 VkPipelineObj pipe(m_device);
13940 pipe.AddShader(&vs);
13941 pipe.AddShader(&fs);
13942
13943 /* set up CB 0; type is UNORM by default */
13944 pipe.AddColorAttachment();
13945 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13946
13947 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013948 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120013949
13950 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13951
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013952 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120013953}
13954
Chris Forbes5c59e902016-02-26 16:56:09 +130013955TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Chris Forbes1cc79542016-07-20 11:13:44 +120013956 TEST_DESCRIPTION("Test that an error is produced for a shader consuming push constants "
13957 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130013959
13960 ASSERT_NO_FATAL_FAILURE(InitState());
13961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013962 char const *vsSource = "#version 450\n"
13963 "\n"
13964 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13965 "out gl_PerVertex {\n"
13966 " vec4 gl_Position;\n"
13967 "};\n"
13968 "void main(){\n"
13969 " gl_Position = vec4(consts.x);\n"
13970 "}\n";
13971 char const *fsSource = "#version 450\n"
13972 "\n"
13973 "layout(location=0) out vec4 x;\n"
13974 "void main(){\n"
13975 " x = vec4(1);\n"
13976 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130013977
13978 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13979 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13980
13981 VkPipelineObj pipe(m_device);
13982 pipe.AddShader(&vs);
13983 pipe.AddShader(&fs);
13984
13985 /* set up CB 0; type is UNORM by default */
13986 pipe.AddColorAttachment();
13987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13988
13989 VkDescriptorSetObj descriptorSet(m_device);
13990 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13991
13992 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13993
13994 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013995 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130013996}
13997
Chris Forbes3fb17902016-08-22 14:57:55 +120013998TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
13999 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14000 "which is not included in the subpass description");
14001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14002 "consumes input attachment index 0 but not provided in subpass");
14003
14004 ASSERT_NO_FATAL_FAILURE(InitState());
14005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014006 char const *vsSource = "#version 450\n"
14007 "\n"
14008 "out gl_PerVertex {\n"
14009 " vec4 gl_Position;\n"
14010 "};\n"
14011 "void main(){\n"
14012 " gl_Position = vec4(1);\n"
14013 "}\n";
14014 char const *fsSource = "#version 450\n"
14015 "\n"
14016 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14017 "layout(location=0) out vec4 color;\n"
14018 "void main() {\n"
14019 " color = subpassLoad(x);\n"
14020 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014021
14022 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14023 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14024
14025 VkPipelineObj pipe(m_device);
14026 pipe.AddShader(&vs);
14027 pipe.AddShader(&fs);
14028 pipe.AddColorAttachment();
14029 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014031 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14032 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014033 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014034 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014035 ASSERT_VK_SUCCESS(err);
14036
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014037 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014038 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014039 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014040 ASSERT_VK_SUCCESS(err);
14041
14042 // error here.
14043 pipe.CreateVKPipeline(pl, renderPass());
14044
14045 m_errorMonitor->VerifyFound();
14046
14047 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14048 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14049}
14050
Chris Forbes5a9a0472016-08-22 16:02:09 +120014051TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
14052 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14053 "with a format having a different fundamental type");
14054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14055 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14056
14057 ASSERT_NO_FATAL_FAILURE(InitState());
14058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014059 char const *vsSource = "#version 450\n"
14060 "\n"
14061 "out gl_PerVertex {\n"
14062 " vec4 gl_Position;\n"
14063 "};\n"
14064 "void main(){\n"
14065 " gl_Position = vec4(1);\n"
14066 "}\n";
14067 char const *fsSource = "#version 450\n"
14068 "\n"
14069 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14070 "layout(location=0) out vec4 color;\n"
14071 "void main() {\n"
14072 " color = subpassLoad(x);\n"
14073 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014074
14075 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14076 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14077
14078 VkPipelineObj pipe(m_device);
14079 pipe.AddShader(&vs);
14080 pipe.AddShader(&fs);
14081 pipe.AddColorAttachment();
14082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14083
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014084 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14085 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014086 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014087 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014088 ASSERT_VK_SUCCESS(err);
14089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014090 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014091 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014092 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014093 ASSERT_VK_SUCCESS(err);
14094
14095 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014096 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14097 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14098 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14099 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14100 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 +120014101 };
14102 VkAttachmentReference color = {
14103 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14104 };
14105 VkAttachmentReference input = {
14106 1, VK_IMAGE_LAYOUT_GENERAL,
14107 };
14108
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014109 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014111 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014112 VkRenderPass rp;
14113 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14114 ASSERT_VK_SUCCESS(err);
14115
14116 // error here.
14117 pipe.CreateVKPipeline(pl, rp);
14118
14119 m_errorMonitor->VerifyFound();
14120
14121 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14122 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14123 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14124}
14125
Chris Forbes541f7b02016-08-22 15:30:27 +120014126TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
14127 TEST_DESCRIPTION("Test that an error is produced for a shader consuming an input attachment "
14128 "which is not included in the subpass description -- array case");
14129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014130 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014131
14132 ASSERT_NO_FATAL_FAILURE(InitState());
14133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014134 char const *vsSource = "#version 450\n"
14135 "\n"
14136 "out gl_PerVertex {\n"
14137 " vec4 gl_Position;\n"
14138 "};\n"
14139 "void main(){\n"
14140 " gl_Position = vec4(1);\n"
14141 "}\n";
14142 char const *fsSource = "#version 450\n"
14143 "\n"
Rene Lindsay07b60af2017-01-10 15:57:55 -070014144 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014145 "layout(location=0) out vec4 color;\n"
14146 "void main() {\n"
Rene Lindsay07b60af2017-01-10 15:57:55 -070014147 " color = subpassLoad(xs[0]);\n"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014148 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014149
14150 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14151 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14152
14153 VkPipelineObj pipe(m_device);
14154 pipe.AddShader(&vs);
14155 pipe.AddShader(&fs);
14156 pipe.AddColorAttachment();
14157 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14158
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014159 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14160 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014161 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014162 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014163 ASSERT_VK_SUCCESS(err);
14164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014165 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014166 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014167 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014168 ASSERT_VK_SUCCESS(err);
14169
14170 // error here.
14171 pipe.CreateVKPipeline(pl, renderPass());
14172
14173 m_errorMonitor->VerifyFound();
14174
14175 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14176 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14177}
14178
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014179TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014180 TEST_DESCRIPTION("Test that an error is produced for a compute pipeline consuming a "
14181 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014183
14184 ASSERT_NO_FATAL_FAILURE(InitState());
14185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014186 char const *csSource = "#version 450\n"
14187 "\n"
14188 "layout(local_size_x=1) in;\n"
14189 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14190 "void main(){\n"
14191 " x = vec4(1);\n"
14192 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014193
14194 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14195
14196 VkDescriptorSetObj descriptorSet(m_device);
14197 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14198
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014199 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14200 nullptr,
14201 0,
14202 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14203 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14204 descriptorSet.GetPipelineLayout(),
14205 VK_NULL_HANDLE,
14206 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014207
14208 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014209 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014210
14211 m_errorMonitor->VerifyFound();
14212
14213 if (err == VK_SUCCESS) {
14214 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14215 }
14216}
14217
Chris Forbes22a9b092016-07-19 14:34:05 +120014218TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Chris Forbes1cc79542016-07-20 11:13:44 +120014219 TEST_DESCRIPTION("Test that an error is produced for a pipeline consuming a "
14220 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14222 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014223
14224 ASSERT_NO_FATAL_FAILURE(InitState());
14225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014226 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14227 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014228 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014229 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014230 ASSERT_VK_SUCCESS(err);
14231
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014232 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014233 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014234 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014235 ASSERT_VK_SUCCESS(err);
14236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014237 char const *csSource = "#version 450\n"
14238 "\n"
14239 "layout(local_size_x=1) in;\n"
14240 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14241 "void main() {\n"
14242 " x.x = 1.0f;\n"
14243 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014244 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014246 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14247 nullptr,
14248 0,
14249 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14250 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14251 pl,
14252 VK_NULL_HANDLE,
14253 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014254
14255 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014256 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014257
14258 m_errorMonitor->VerifyFound();
14259
14260 if (err == VK_SUCCESS) {
14261 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14262 }
14263
14264 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14265 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14266}
14267
Chris Forbes50020592016-07-27 13:52:41 +120014268TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
14269 TEST_DESCRIPTION("Test that an error is produced when an image view type "
14270 "does not match the dimensionality declared in the shader");
14271
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014272 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 +120014273
14274 ASSERT_NO_FATAL_FAILURE(InitState());
14275 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014277 char const *vsSource = "#version 450\n"
14278 "\n"
14279 "out gl_PerVertex { vec4 gl_Position; };\n"
14280 "void main() { gl_Position = vec4(0); }\n";
14281 char const *fsSource = "#version 450\n"
14282 "\n"
14283 "layout(set=0, binding=0) uniform sampler3D s;\n"
14284 "layout(location=0) out vec4 color;\n"
14285 "void main() {\n"
14286 " color = texture(s, vec3(0));\n"
14287 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014288 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14289 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14290
14291 VkPipelineObj pipe(m_device);
14292 pipe.AddShader(&vs);
14293 pipe.AddShader(&fs);
14294 pipe.AddColorAttachment();
14295
14296 VkTextureObj texture(m_device, nullptr);
14297 VkSamplerObj sampler(m_device);
14298
14299 VkDescriptorSetObj descriptorSet(m_device);
14300 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14301 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14302
14303 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14304 ASSERT_VK_SUCCESS(err);
14305
Tony Barbour552f6c02016-12-21 14:34:07 -070014306 m_commandBuffer->BeginCommandBuffer();
14307 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014308
14309 m_commandBuffer->BindPipeline(pipe);
14310 m_commandBuffer->BindDescriptorSet(descriptorSet);
14311
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014312 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014313 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014314 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014315 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14316
14317 // error produced here.
14318 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14319
14320 m_errorMonitor->VerifyFound();
14321
Tony Barbour552f6c02016-12-21 14:34:07 -070014322 m_commandBuffer->EndRenderPass();
14323 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014324}
14325
Chris Forbes5533bfc2016-07-27 14:12:34 +120014326TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
14327 TEST_DESCRIPTION("Test that an error is produced when a multisampled images "
14328 "are consumed via singlesample images types in the shader, or vice versa.");
14329
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014331
14332 ASSERT_NO_FATAL_FAILURE(InitState());
14333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014335 char const *vsSource = "#version 450\n"
14336 "\n"
14337 "out gl_PerVertex { vec4 gl_Position; };\n"
14338 "void main() { gl_Position = vec4(0); }\n";
14339 char const *fsSource = "#version 450\n"
14340 "\n"
14341 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14342 "layout(location=0) out vec4 color;\n"
14343 "void main() {\n"
14344 " color = texelFetch(s, ivec2(0), 0);\n"
14345 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014346 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14347 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14348
14349 VkPipelineObj pipe(m_device);
14350 pipe.AddShader(&vs);
14351 pipe.AddShader(&fs);
14352 pipe.AddColorAttachment();
14353
14354 VkTextureObj texture(m_device, nullptr);
14355 VkSamplerObj sampler(m_device);
14356
14357 VkDescriptorSetObj descriptorSet(m_device);
14358 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14359 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14360
14361 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14362 ASSERT_VK_SUCCESS(err);
14363
Tony Barbour552f6c02016-12-21 14:34:07 -070014364 m_commandBuffer->BeginCommandBuffer();
14365 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014366
14367 m_commandBuffer->BindPipeline(pipe);
14368 m_commandBuffer->BindDescriptorSet(descriptorSet);
14369
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014370 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014371 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014372 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014373 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14374
14375 // error produced here.
14376 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14377
14378 m_errorMonitor->VerifyFound();
14379
Tony Barbour552f6c02016-12-21 14:34:07 -070014380 m_commandBuffer->EndRenderPass();
14381 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014382}
14383
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014384#endif // SHADER_CHECKER_TESTS
14385
14386#if DEVICE_LIMITS_TESTS
Mark Youngc48c4c12016-04-11 14:26:49 -060014387TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014389
14390 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014391
14392 // Create an image
14393 VkImage image;
14394
Karl Schultz6addd812016-02-02 17:17:23 -070014395 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14396 const int32_t tex_width = 32;
14397 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014398
14399 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014400 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14401 image_create_info.pNext = NULL;
14402 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14403 image_create_info.format = tex_format;
14404 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014405 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014406 image_create_info.extent.depth = 1;
14407 image_create_info.mipLevels = 1;
14408 image_create_info.arrayLayers = 1;
14409 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14410 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14411 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14412 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014413
14414 // Introduce error by sending down a bogus width extent
14415 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014416 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014417
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014418 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014419}
14420
Mark Youngc48c4c12016-04-11 14:26:49 -060014421TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14423 "CreateImage extents is 0 for at least one required dimension");
Mark Youngc48c4c12016-04-11 14:26:49 -060014424
14425 ASSERT_NO_FATAL_FAILURE(InitState());
14426
14427 // Create an image
14428 VkImage image;
14429
14430 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14431 const int32_t tex_width = 32;
14432 const int32_t tex_height = 32;
14433
14434 VkImageCreateInfo image_create_info = {};
14435 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14436 image_create_info.pNext = NULL;
14437 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14438 image_create_info.format = tex_format;
14439 image_create_info.extent.width = tex_width;
14440 image_create_info.extent.height = tex_height;
14441 image_create_info.extent.depth = 1;
14442 image_create_info.mipLevels = 1;
14443 image_create_info.arrayLayers = 1;
14444 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14445 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14446 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14447 image_create_info.flags = 0;
14448
14449 // Introduce error by sending down a bogus width extent
14450 image_create_info.extent.width = 0;
14451 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14452
14453 m_errorMonitor->VerifyFound();
14454}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060014455#endif // DEVICE_LIMITS_TESTS
Chris Forbesa36d69e2015-05-25 11:13:44 +120014456
Tobin Ehliscde08892015-09-22 10:11:37 -060014457#if IMAGE_TESTS
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014458
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014459TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
14460 TEST_DESCRIPTION("Create a render pass with an attachment description "
14461 "format set to VK_FORMAT_UNDEFINED");
14462
14463 ASSERT_NO_FATAL_FAILURE(InitState());
14464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14465
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014467
14468 VkAttachmentReference color_attach = {};
14469 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14470 color_attach.attachment = 0;
14471 VkSubpassDescription subpass = {};
14472 subpass.colorAttachmentCount = 1;
14473 subpass.pColorAttachments = &color_attach;
14474
14475 VkRenderPassCreateInfo rpci = {};
14476 rpci.subpassCount = 1;
14477 rpci.pSubpasses = &subpass;
14478 rpci.attachmentCount = 1;
14479 VkAttachmentDescription attach_desc = {};
14480 attach_desc.format = VK_FORMAT_UNDEFINED;
14481 rpci.pAttachments = &attach_desc;
14482 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14483 VkRenderPass rp;
14484 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14485
14486 m_errorMonitor->VerifyFound();
14487
14488 if (result == VK_SUCCESS) {
14489 vkDestroyRenderPass(m_device->device(), rp, NULL);
14490 }
14491}
14492
Karl Schultz6addd812016-02-02 17:17:23 -070014493TEST_F(VkLayerTest, InvalidImageView) {
14494 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014495
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014497
Tobin Ehliscde08892015-09-22 10:11:37 -060014498 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014499
Mike Stroyana3082432015-09-25 13:39:21 -060014500 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014501 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014502
Karl Schultz6addd812016-02-02 17:17:23 -070014503 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14504 const int32_t tex_width = 32;
14505 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014506
14507 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014508 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14509 image_create_info.pNext = NULL;
14510 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14511 image_create_info.format = tex_format;
14512 image_create_info.extent.width = tex_width;
14513 image_create_info.extent.height = tex_height;
14514 image_create_info.extent.depth = 1;
14515 image_create_info.mipLevels = 1;
14516 image_create_info.arrayLayers = 1;
14517 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14518 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14519 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14520 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014521
Chia-I Wuf7458c52015-10-26 21:10:41 +080014522 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014523 ASSERT_VK_SUCCESS(err);
14524
14525 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014526 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014527 image_view_create_info.image = image;
14528 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14529 image_view_create_info.format = tex_format;
14530 image_view_create_info.subresourceRange.layerCount = 1;
14531 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
14532 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014533 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014534
14535 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014536 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014537
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014538 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060014539 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060014540}
Mike Stroyana3082432015-09-25 13:39:21 -060014541
Mark Youngd339ba32016-05-30 13:28:35 -060014542TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
14543 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060014544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060014545 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060014546
14547 ASSERT_NO_FATAL_FAILURE(InitState());
14548
14549 // Create an image and try to create a view with no memory backing the image
14550 VkImage image;
14551
14552 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14553 const int32_t tex_width = 32;
14554 const int32_t tex_height = 32;
14555
14556 VkImageCreateInfo image_create_info = {};
14557 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14558 image_create_info.pNext = NULL;
14559 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14560 image_create_info.format = tex_format;
14561 image_create_info.extent.width = tex_width;
14562 image_create_info.extent.height = tex_height;
14563 image_create_info.extent.depth = 1;
14564 image_create_info.mipLevels = 1;
14565 image_create_info.arrayLayers = 1;
14566 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14567 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14568 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14569 image_create_info.flags = 0;
14570
14571 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14572 ASSERT_VK_SUCCESS(err);
14573
14574 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014575 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060014576 image_view_create_info.image = image;
14577 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14578 image_view_create_info.format = tex_format;
14579 image_view_create_info.subresourceRange.layerCount = 1;
14580 image_view_create_info.subresourceRange.baseMipLevel = 0;
14581 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014582 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060014583
14584 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014585 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060014586
14587 m_errorMonitor->VerifyFound();
14588 vkDestroyImage(m_device->device(), image, NULL);
14589 // If last error is success, it still created the view, so delete it.
14590 if (err == VK_SUCCESS) {
14591 vkDestroyImageView(m_device->device(), view, NULL);
14592 }
Mark Youngd339ba32016-05-30 13:28:35 -060014593}
14594
Karl Schultz6addd812016-02-02 17:17:23 -070014595TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014596 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014598
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014599 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014600
Karl Schultz6addd812016-02-02 17:17:23 -070014601 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014602 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014603 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014604 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014605
14606 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014607 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014608 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070014609 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14610 image_view_create_info.format = tex_format;
14611 image_view_create_info.subresourceRange.baseMipLevel = 0;
14612 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014613 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070014614 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014615 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014616
14617 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060014618 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014619
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014620 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060014621}
14622
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014623TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070014624 VkResult err;
14625 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060014626
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014628
Mike Stroyana3082432015-09-25 13:39:21 -060014629 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060014630
14631 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070014632 VkImage srcImage;
14633 VkImage dstImage;
14634 VkDeviceMemory srcMem;
14635 VkDeviceMemory destMem;
14636 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060014637
14638 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014639 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14640 image_create_info.pNext = NULL;
14641 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14642 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
14643 image_create_info.extent.width = 32;
14644 image_create_info.extent.height = 32;
14645 image_create_info.extent.depth = 1;
14646 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014647 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070014648 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14649 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14650 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
14651 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014653 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014654 ASSERT_VK_SUCCESS(err);
14655
Mark Lobodzinski867787a2016-10-14 11:49:55 -060014656 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014657 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060014658 ASSERT_VK_SUCCESS(err);
14659
14660 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014661 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014662 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
14663 memAlloc.pNext = NULL;
14664 memAlloc.allocationSize = 0;
14665 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014666
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060014667 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014668 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014669 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060014670 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014671 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014672 ASSERT_VK_SUCCESS(err);
14673
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014674 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060014675 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014676 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014677 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014678 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060014679 ASSERT_VK_SUCCESS(err);
14680
14681 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
14682 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014683 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060014684 ASSERT_VK_SUCCESS(err);
14685
Tony Barbour552f6c02016-12-21 14:34:07 -070014686 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014687 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014688 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060014689 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060014690 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014691 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060014692 copyRegion.srcOffset.x = 0;
14693 copyRegion.srcOffset.y = 0;
14694 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080014695 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014696 copyRegion.dstSubresource.mipLevel = 0;
14697 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060014698 // Introduce failure by forcing the dst layerCount to differ from src
14699 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014700 copyRegion.dstOffset.x = 0;
14701 copyRegion.dstOffset.y = 0;
14702 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060014703 copyRegion.extent.width = 1;
14704 copyRegion.extent.height = 1;
14705 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014706 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070014707 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060014708
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014709 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060014710
Chia-I Wuf7458c52015-10-26 21:10:41 +080014711 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014712 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080014713 vkFreeMemory(m_device->device(), srcMem, NULL);
14714 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060014715}
14716
Tony Barbourd6673642016-05-05 14:46:39 -060014717TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
14718
14719 TEST_DESCRIPTION("Creating images with unsuported formats ");
14720
14721 ASSERT_NO_FATAL_FAILURE(InitState());
14722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14723 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014724 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 -060014725 VK_IMAGE_TILING_OPTIMAL, 0);
14726 ASSERT_TRUE(image.initialized());
14727
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014728 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130014729 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014730 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014731 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14732 image_create_info.format = VK_FORMAT_UNDEFINED;
14733 image_create_info.extent.width = 32;
14734 image_create_info.extent.height = 32;
14735 image_create_info.extent.depth = 1;
14736 image_create_info.mipLevels = 1;
14737 image_create_info.arrayLayers = 1;
14738 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14739 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
14740 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014741
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14743 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014744
14745 VkImage localImage;
14746 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
14747 m_errorMonitor->VerifyFound();
14748
Tony Barbourd6673642016-05-05 14:46:39 -060014749 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014750 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060014751 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
14752 VkFormat format = static_cast<VkFormat>(f);
14753 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014754 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060014755 unsupported = format;
14756 break;
14757 }
14758 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014759
Tony Barbourd6673642016-05-05 14:46:39 -060014760 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060014761 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060014763
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060014764 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060014765 m_errorMonitor->VerifyFound();
14766 }
14767}
14768
14769TEST_F(VkLayerTest, ImageLayerViewTests) {
14770 VkResult ret;
14771 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
14772
14773 ASSERT_NO_FATAL_FAILURE(InitState());
14774
14775 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014776 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 -060014777 VK_IMAGE_TILING_OPTIMAL, 0);
14778 ASSERT_TRUE(image.initialized());
14779
14780 VkImageView imgView;
14781 VkImageViewCreateInfo imgViewInfo = {};
14782 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
14783 imgViewInfo.image = image.handle();
14784 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
14785 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14786 imgViewInfo.subresourceRange.layerCount = 1;
14787 imgViewInfo.subresourceRange.baseMipLevel = 0;
14788 imgViewInfo.subresourceRange.levelCount = 1;
14789 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14790
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060014792 // View can't have baseMipLevel >= image's mipLevels - Expect
14793 // VIEW_CREATE_ERROR
14794 imgViewInfo.subresourceRange.baseMipLevel = 1;
14795 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14796 m_errorMonitor->VerifyFound();
14797 imgViewInfo.subresourceRange.baseMipLevel = 0;
14798
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060014800 // View can't have baseArrayLayer >= image's arraySize - Expect
14801 // VIEW_CREATE_ERROR
14802 imgViewInfo.subresourceRange.baseArrayLayer = 1;
14803 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14804 m_errorMonitor->VerifyFound();
14805 imgViewInfo.subresourceRange.baseArrayLayer = 0;
14806
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
14808 "pCreateInfo->subresourceRange."
14809 "levelCount");
Tony Barbourd6673642016-05-05 14:46:39 -060014810 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
14811 imgViewInfo.subresourceRange.levelCount = 0;
14812 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14813 m_errorMonitor->VerifyFound();
14814 imgViewInfo.subresourceRange.levelCount = 1;
14815
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014816 m_errorMonitor->SetDesiredFailureMsg(
14817 VK_DEBUG_REPORT_ERROR_BIT_EXT,
14818 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060014819 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
14820 imgViewInfo.subresourceRange.layerCount = 0;
14821 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14822 m_errorMonitor->VerifyFound();
14823 imgViewInfo.subresourceRange.layerCount = 1;
14824
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
14826 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
14827 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060014828 // Can't use depth format for view into color image - Expect INVALID_FORMAT
14829 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
14830 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14831 m_errorMonitor->VerifyFound();
14832 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14833
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060014835 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
14836 // VIEW_CREATE_ERROR
14837 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
14838 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14839 m_errorMonitor->VerifyFound();
14840 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
14841
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060014843 // TODO: Update framework to easily passing mutable flag into ImageObj init
14844 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070014845 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
14846 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14847 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060014848 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
14849 // VIEW_CREATE_ERROR
14850 VkImageCreateInfo mutImgInfo = image.create_info();
14851 VkImage mutImage;
14852 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014853 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060014854 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
14855 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
14856 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
14857 ASSERT_VK_SUCCESS(ret);
14858 imgViewInfo.image = mutImage;
14859 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
14860 m_errorMonitor->VerifyFound();
14861 imgViewInfo.image = image.handle();
14862 vkDestroyImage(m_device->handle(), mutImage, NULL);
14863}
14864
14865TEST_F(VkLayerTest, MiscImageLayerTests) {
14866
14867 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
14868
14869 ASSERT_NO_FATAL_FAILURE(InitState());
14870
Rene Lindsay135204f2016-12-22 17:11:09 -070014871 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060014872 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070014873 image.init(128, 128, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14874 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060014875 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060014876 vk_testing::Buffer buffer;
14877 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070014878 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060014879 VkBufferImageCopy region = {};
14880 region.bufferRowLength = 128;
14881 region.bufferImageHeight = 128;
14882 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14883 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070014884 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014885 region.imageExtent.height = 4;
14886 region.imageExtent.width = 4;
14887 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070014888
14889 VkImageObj image2(m_device);
14890 image2.init(128, 128, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14891 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
14892 ASSERT_TRUE(image2.initialized());
14893 vk_testing::Buffer buffer2;
14894 VkMemoryPropertyFlags reqs2 = 0;
14895 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
14896 VkBufferImageCopy region2 = {};
14897 region2.bufferRowLength = 128;
14898 region2.bufferImageHeight = 128;
14899 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14900 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
14901 region2.imageSubresource.layerCount = 1;
14902 region2.imageExtent.height = 4;
14903 region2.imageExtent.width = 4;
14904 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060014905 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060014906
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070014907 // Image must have offset.z of 0 and extent.depth of 1
14908 // Introduce failure by setting imageExtent.depth to 0
14909 region.imageExtent.depth = 0;
14910 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14911 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14912 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14913 m_errorMonitor->VerifyFound();
14914
14915 region.imageExtent.depth = 1;
14916
14917 // Image must have offset.z of 0 and extent.depth of 1
14918 // Introduce failure by setting imageOffset.z to 4
14919 region.imageOffset.z = 4;
14920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
14921 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14922 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
14923 m_errorMonitor->VerifyFound();
14924
14925 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014926 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
14927 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070014928 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014930 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14931 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014932 m_errorMonitor->VerifyFound();
14933
14934 // BufferOffset must be a multiple of 4
14935 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070014936 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070014938 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
14939 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014940 m_errorMonitor->VerifyFound();
14941
14942 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
14943 region.bufferOffset = 0;
14944 region.imageExtent.height = 128;
14945 region.imageExtent.width = 128;
14946 // Introduce failure by setting bufferRowLength > 0 but less than width
14947 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014949 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14950 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014951 m_errorMonitor->VerifyFound();
14952
14953 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
14954 region.bufferRowLength = 128;
14955 // Introduce failure by setting bufferRowHeight > 0 but less than height
14956 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070014957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014958 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
14959 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060014960 m_errorMonitor->VerifyFound();
14961
14962 region.bufferImageHeight = 128;
Dave Houlton34df4cb2016-12-01 16:43:06 -070014963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "If the format of srcImage is an "
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014964 "integer-based format then filter must be VK_FILTER_NEAREST");
Tony Barbourd6673642016-05-05 14:46:39 -060014965 // Expect INVALID_FILTER
14966 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014967 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
14968 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014969 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014970 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
14971 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060014972 VkImageBlit blitRegion = {};
14973 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14974 blitRegion.srcSubresource.baseArrayLayer = 0;
14975 blitRegion.srcSubresource.layerCount = 1;
14976 blitRegion.srcSubresource.mipLevel = 0;
14977 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
14978 blitRegion.dstSubresource.baseArrayLayer = 0;
14979 blitRegion.dstSubresource.layerCount = 1;
14980 blitRegion.dstSubresource.mipLevel = 0;
14981
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014982 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070014983 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Tony Barbourd6673642016-05-05 14:46:39 -060014984 m_errorMonitor->VerifyFound();
14985
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014986 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
14988 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
14989 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060014990 m_errorMonitor->VerifyFound();
14991
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with 0 in ppMemoryBarriers");
Tony Barbourd6673642016-05-05 14:46:39 -060014993 VkImageMemoryBarrier img_barrier;
14994 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
14995 img_barrier.pNext = NULL;
14996 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
14997 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
14998 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
14999 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15000 img_barrier.image = image.handle();
15001 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15002 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15003 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15004 img_barrier.subresourceRange.baseArrayLayer = 0;
15005 img_barrier.subresourceRange.baseMipLevel = 0;
15006 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15007 img_barrier.subresourceRange.layerCount = 0;
15008 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015009 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15010 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015011 m_errorMonitor->VerifyFound();
15012 img_barrier.subresourceRange.layerCount = 1;
15013}
15014
15015TEST_F(VkLayerTest, ImageFormatLimits) {
15016
15017 TEST_DESCRIPTION("Exceed the limits of image format ");
15018
Cody Northropc31a84f2016-08-22 10:41:47 -060015019 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015020 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015021 VkImageCreateInfo image_create_info = {};
15022 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15023 image_create_info.pNext = NULL;
15024 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15025 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15026 image_create_info.extent.width = 32;
15027 image_create_info.extent.height = 32;
15028 image_create_info.extent.depth = 1;
15029 image_create_info.mipLevels = 1;
15030 image_create_info.arrayLayers = 1;
15031 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15032 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15033 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15034 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15035 image_create_info.flags = 0;
15036
15037 VkImage nullImg;
15038 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015039 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15040 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015041 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015042 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15043 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15044 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015045 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015048 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15049 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15050 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15051 m_errorMonitor->VerifyFound();
15052 image_create_info.mipLevels = 1;
15053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015055 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15056 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15057 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15058 m_errorMonitor->VerifyFound();
15059 image_create_info.arrayLayers = 1;
15060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015062 int samples = imgFmtProps.sampleCounts >> 1;
15063 image_create_info.samples = (VkSampleCountFlagBits)samples;
15064 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15065 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15066 m_errorMonitor->VerifyFound();
15067 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15068
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015069 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pCreateInfo->initialLayout, must be "
15070 "VK_IMAGE_LAYOUT_UNDEFINED or "
15071 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015072 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15073 // Expect INVALID_LAYOUT
15074 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15075 m_errorMonitor->VerifyFound();
15076 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15077}
15078
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015079TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
15080
15081 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015083
15084 ASSERT_NO_FATAL_FAILURE(InitState());
15085
15086 VkImageObj src_image(m_device);
15087 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15088 VkImageObj dst_image(m_device);
15089 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15090
Tony Barbour552f6c02016-12-21 14:34:07 -070015091 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015092 VkImageCopy copy_region;
15093 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15094 copy_region.srcSubresource.mipLevel = 0;
15095 copy_region.srcSubresource.baseArrayLayer = 0;
15096 copy_region.srcSubresource.layerCount = 0;
15097 copy_region.srcOffset.x = 0;
15098 copy_region.srcOffset.y = 0;
15099 copy_region.srcOffset.z = 0;
15100 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15101 copy_region.dstSubresource.mipLevel = 0;
15102 copy_region.dstSubresource.baseArrayLayer = 0;
15103 copy_region.dstSubresource.layerCount = 0;
15104 copy_region.dstOffset.x = 0;
15105 copy_region.dstOffset.y = 0;
15106 copy_region.dstOffset.z = 0;
15107 copy_region.extent.width = 64;
15108 copy_region.extent.height = 64;
15109 copy_region.extent.depth = 1;
15110 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15111 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015112 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015113
15114 m_errorMonitor->VerifyFound();
15115}
15116
15117TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
15118
15119 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015121
15122 ASSERT_NO_FATAL_FAILURE(InitState());
15123
15124 VkImageObj src_image(m_device);
15125 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15126 VkImageObj dst_image(m_device);
15127 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15128
Tony Barbour552f6c02016-12-21 14:34:07 -070015129 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015130 VkImageCopy copy_region;
15131 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15132 copy_region.srcSubresource.mipLevel = 0;
15133 copy_region.srcSubresource.baseArrayLayer = 0;
15134 copy_region.srcSubresource.layerCount = 0;
15135 copy_region.srcOffset.x = 0;
15136 copy_region.srcOffset.y = 0;
15137 copy_region.srcOffset.z = 0;
15138 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15139 copy_region.dstSubresource.mipLevel = 0;
15140 copy_region.dstSubresource.baseArrayLayer = 0;
15141 copy_region.dstSubresource.layerCount = 0;
15142 copy_region.dstOffset.x = 0;
15143 copy_region.dstOffset.y = 0;
15144 copy_region.dstOffset.z = 0;
15145 copy_region.extent.width = 64;
15146 copy_region.extent.height = 64;
15147 copy_region.extent.depth = 1;
15148 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15149 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015150 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015151
15152 m_errorMonitor->VerifyFound();
15153}
15154
Karl Schultz6addd812016-02-02 17:17:23 -070015155TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015156 VkResult err;
15157 bool pass;
15158
15159 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015161
15162 ASSERT_NO_FATAL_FAILURE(InitState());
15163
15164 // Create two images of different types and try to copy between them
15165 VkImage srcImage;
15166 VkImage dstImage;
15167 VkDeviceMemory srcMem;
15168 VkDeviceMemory destMem;
15169 VkMemoryRequirements memReqs;
15170
15171 VkImageCreateInfo image_create_info = {};
15172 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15173 image_create_info.pNext = NULL;
15174 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15175 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15176 image_create_info.extent.width = 32;
15177 image_create_info.extent.height = 32;
15178 image_create_info.extent.depth = 1;
15179 image_create_info.mipLevels = 1;
15180 image_create_info.arrayLayers = 1;
15181 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15182 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15183 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15184 image_create_info.flags = 0;
15185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015186 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015187 ASSERT_VK_SUCCESS(err);
15188
15189 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15190 // Introduce failure by creating second image with a different-sized format.
15191 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015193 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015194 ASSERT_VK_SUCCESS(err);
15195
15196 // Allocate memory
15197 VkMemoryAllocateInfo memAlloc = {};
15198 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15199 memAlloc.pNext = NULL;
15200 memAlloc.allocationSize = 0;
15201 memAlloc.memoryTypeIndex = 0;
15202
15203 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15204 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015205 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015206 ASSERT_TRUE(pass);
15207 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15208 ASSERT_VK_SUCCESS(err);
15209
15210 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15211 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015212 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015213 ASSERT_TRUE(pass);
15214 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15215 ASSERT_VK_SUCCESS(err);
15216
15217 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15218 ASSERT_VK_SUCCESS(err);
15219 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15220 ASSERT_VK_SUCCESS(err);
15221
Tony Barbour552f6c02016-12-21 14:34:07 -070015222 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015223 VkImageCopy copyRegion;
15224 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15225 copyRegion.srcSubresource.mipLevel = 0;
15226 copyRegion.srcSubresource.baseArrayLayer = 0;
15227 copyRegion.srcSubresource.layerCount = 0;
15228 copyRegion.srcOffset.x = 0;
15229 copyRegion.srcOffset.y = 0;
15230 copyRegion.srcOffset.z = 0;
15231 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15232 copyRegion.dstSubresource.mipLevel = 0;
15233 copyRegion.dstSubresource.baseArrayLayer = 0;
15234 copyRegion.dstSubresource.layerCount = 0;
15235 copyRegion.dstOffset.x = 0;
15236 copyRegion.dstOffset.y = 0;
15237 copyRegion.dstOffset.z = 0;
15238 copyRegion.extent.width = 1;
15239 copyRegion.extent.height = 1;
15240 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015241 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015242 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015243
15244 m_errorMonitor->VerifyFound();
15245
15246 vkDestroyImage(m_device->device(), srcImage, NULL);
15247 vkDestroyImage(m_device->device(), dstImage, NULL);
15248 vkFreeMemory(m_device->device(), srcMem, NULL);
15249 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015250}
15251
Karl Schultz6addd812016-02-02 17:17:23 -070015252TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15253 VkResult err;
15254 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015255
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015256 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15258 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015259
Mike Stroyana3082432015-09-25 13:39:21 -060015260 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015261
15262 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015263 VkImage srcImage;
15264 VkImage dstImage;
15265 VkDeviceMemory srcMem;
15266 VkDeviceMemory destMem;
15267 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015268
15269 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015270 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15271 image_create_info.pNext = NULL;
15272 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15273 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15274 image_create_info.extent.width = 32;
15275 image_create_info.extent.height = 32;
15276 image_create_info.extent.depth = 1;
15277 image_create_info.mipLevels = 1;
15278 image_create_info.arrayLayers = 1;
15279 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15280 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15281 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15282 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015283
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015284 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015285 ASSERT_VK_SUCCESS(err);
15286
Karl Schultzbdb75952016-04-19 11:36:49 -060015287 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15288
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015289 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015290 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015291 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015292 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015294 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015295 ASSERT_VK_SUCCESS(err);
15296
15297 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015298 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015299 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15300 memAlloc.pNext = NULL;
15301 memAlloc.allocationSize = 0;
15302 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015303
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015304 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015305 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015306 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015307 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015308 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015309 ASSERT_VK_SUCCESS(err);
15310
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015311 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015312 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015313 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015314 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015315 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015316 ASSERT_VK_SUCCESS(err);
15317
15318 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15319 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015320 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015321 ASSERT_VK_SUCCESS(err);
15322
Tony Barbour552f6c02016-12-21 14:34:07 -070015323 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015324 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015325 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015326 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015327 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015328 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015329 copyRegion.srcOffset.x = 0;
15330 copyRegion.srcOffset.y = 0;
15331 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015332 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015333 copyRegion.dstSubresource.mipLevel = 0;
15334 copyRegion.dstSubresource.baseArrayLayer = 0;
15335 copyRegion.dstSubresource.layerCount = 0;
15336 copyRegion.dstOffset.x = 0;
15337 copyRegion.dstOffset.y = 0;
15338 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015339 copyRegion.extent.width = 1;
15340 copyRegion.extent.height = 1;
15341 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015342 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015343 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015344
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015345 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015346
Chia-I Wuf7458c52015-10-26 21:10:41 +080015347 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015348 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015349 vkFreeMemory(m_device->device(), srcMem, NULL);
15350 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015351}
15352
Karl Schultz6addd812016-02-02 17:17:23 -070015353TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15354 VkResult err;
15355 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15358 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015359
Mike Stroyana3082432015-09-25 13:39:21 -060015360 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015361
15362 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015363 VkImage srcImage;
15364 VkImage dstImage;
15365 VkDeviceMemory srcMem;
15366 VkDeviceMemory destMem;
15367 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015368
15369 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15371 image_create_info.pNext = NULL;
15372 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15373 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15374 image_create_info.extent.width = 32;
15375 image_create_info.extent.height = 1;
15376 image_create_info.extent.depth = 1;
15377 image_create_info.mipLevels = 1;
15378 image_create_info.arrayLayers = 1;
15379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15380 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15381 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15382 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015383
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015384 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015385 ASSERT_VK_SUCCESS(err);
15386
Karl Schultz6addd812016-02-02 17:17:23 -070015387 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015389 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015390 ASSERT_VK_SUCCESS(err);
15391
15392 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015393 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015394 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15395 memAlloc.pNext = NULL;
15396 memAlloc.allocationSize = 0;
15397 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015398
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015399 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015400 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015401 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015402 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015403 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015404 ASSERT_VK_SUCCESS(err);
15405
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015406 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015407 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015408 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015409 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015410 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015411 ASSERT_VK_SUCCESS(err);
15412
15413 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15414 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015415 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015416 ASSERT_VK_SUCCESS(err);
15417
Tony Barbour552f6c02016-12-21 14:34:07 -070015418 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015419 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015420 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15421 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015422 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015423 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015424 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015425 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015426 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015427 resolveRegion.srcOffset.x = 0;
15428 resolveRegion.srcOffset.y = 0;
15429 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015430 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015431 resolveRegion.dstSubresource.mipLevel = 0;
15432 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015433 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015434 resolveRegion.dstOffset.x = 0;
15435 resolveRegion.dstOffset.y = 0;
15436 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015437 resolveRegion.extent.width = 1;
15438 resolveRegion.extent.height = 1;
15439 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015440 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015441 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015442
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015443 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015444
Chia-I Wuf7458c52015-10-26 21:10:41 +080015445 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015446 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015447 vkFreeMemory(m_device->device(), srcMem, NULL);
15448 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015449}
15450
Karl Schultz6addd812016-02-02 17:17:23 -070015451TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15452 VkResult err;
15453 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015454
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15456 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015457
Mike Stroyana3082432015-09-25 13:39:21 -060015458 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015459
Chris Forbesa7530692016-05-08 12:35:39 +120015460 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015461 VkImage srcImage;
15462 VkImage dstImage;
15463 VkDeviceMemory srcMem;
15464 VkDeviceMemory destMem;
15465 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015466
15467 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015468 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15469 image_create_info.pNext = NULL;
15470 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15471 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15472 image_create_info.extent.width = 32;
15473 image_create_info.extent.height = 1;
15474 image_create_info.extent.depth = 1;
15475 image_create_info.mipLevels = 1;
15476 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015477 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015478 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15479 // Note: Some implementations expect color attachment usage for any
15480 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015481 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015482 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015483
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015484 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015485 ASSERT_VK_SUCCESS(err);
15486
Karl Schultz6addd812016-02-02 17:17:23 -070015487 // Note: Some implementations expect color attachment usage for any
15488 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015489 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015490
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015491 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015492 ASSERT_VK_SUCCESS(err);
15493
15494 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015495 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015496 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15497 memAlloc.pNext = NULL;
15498 memAlloc.allocationSize = 0;
15499 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015500
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015501 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015502 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015503 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015504 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015505 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015506 ASSERT_VK_SUCCESS(err);
15507
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015508 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015509 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015510 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015511 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015512 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015513 ASSERT_VK_SUCCESS(err);
15514
15515 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15516 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015517 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015518 ASSERT_VK_SUCCESS(err);
15519
Tony Barbour552f6c02016-12-21 14:34:07 -070015520 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015521 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015522 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15523 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015524 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015525 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015526 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015527 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015528 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015529 resolveRegion.srcOffset.x = 0;
15530 resolveRegion.srcOffset.y = 0;
15531 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015532 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015533 resolveRegion.dstSubresource.mipLevel = 0;
15534 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015535 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015536 resolveRegion.dstOffset.x = 0;
15537 resolveRegion.dstOffset.y = 0;
15538 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015539 resolveRegion.extent.width = 1;
15540 resolveRegion.extent.height = 1;
15541 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015542 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015543 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015544
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015545 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015546
Chia-I Wuf7458c52015-10-26 21:10:41 +080015547 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015548 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015549 vkFreeMemory(m_device->device(), srcMem, NULL);
15550 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015551}
15552
Karl Schultz6addd812016-02-02 17:17:23 -070015553TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
15554 VkResult err;
15555 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015556
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15558 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015559
Mike Stroyana3082432015-09-25 13:39:21 -060015560 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015561
15562 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015563 VkImage srcImage;
15564 VkImage dstImage;
15565 VkDeviceMemory srcMem;
15566 VkDeviceMemory destMem;
15567 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015568
15569 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015570 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15571 image_create_info.pNext = NULL;
15572 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15573 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15574 image_create_info.extent.width = 32;
15575 image_create_info.extent.height = 1;
15576 image_create_info.extent.depth = 1;
15577 image_create_info.mipLevels = 1;
15578 image_create_info.arrayLayers = 1;
15579 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15580 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15581 // Note: Some implementations expect color attachment usage for any
15582 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015583 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015584 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015585
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015586 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015587 ASSERT_VK_SUCCESS(err);
15588
Karl Schultz6addd812016-02-02 17:17:23 -070015589 // Set format to something other than source image
15590 image_create_info.format = VK_FORMAT_R32_SFLOAT;
15591 // Note: Some implementations expect color attachment usage for any
15592 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015593 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015594 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015595
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015596 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015597 ASSERT_VK_SUCCESS(err);
15598
15599 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015600 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015601 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15602 memAlloc.pNext = NULL;
15603 memAlloc.allocationSize = 0;
15604 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015605
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015606 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015607 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015608 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015609 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015610 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015611 ASSERT_VK_SUCCESS(err);
15612
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015613 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015614 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015615 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015616 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015617 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015618 ASSERT_VK_SUCCESS(err);
15619
15620 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15621 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015622 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015623 ASSERT_VK_SUCCESS(err);
15624
Tony Barbour552f6c02016-12-21 14:34:07 -070015625 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015626 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015627 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15628 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015629 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015630 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015631 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015632 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015633 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015634 resolveRegion.srcOffset.x = 0;
15635 resolveRegion.srcOffset.y = 0;
15636 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015637 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015638 resolveRegion.dstSubresource.mipLevel = 0;
15639 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015640 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015641 resolveRegion.dstOffset.x = 0;
15642 resolveRegion.dstOffset.y = 0;
15643 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015644 resolveRegion.extent.width = 1;
15645 resolveRegion.extent.height = 1;
15646 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015647 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015648 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015649
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015650 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015651
Chia-I Wuf7458c52015-10-26 21:10:41 +080015652 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015653 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015654 vkFreeMemory(m_device->device(), srcMem, NULL);
15655 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015656}
15657
Karl Schultz6addd812016-02-02 17:17:23 -070015658TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
15659 VkResult err;
15660 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015661
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15663 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015664
Mike Stroyana3082432015-09-25 13:39:21 -060015665 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015666
15667 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015668 VkImage srcImage;
15669 VkImage dstImage;
15670 VkDeviceMemory srcMem;
15671 VkDeviceMemory destMem;
15672 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015673
15674 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015675 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15676 image_create_info.pNext = NULL;
15677 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15678 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15679 image_create_info.extent.width = 32;
15680 image_create_info.extent.height = 1;
15681 image_create_info.extent.depth = 1;
15682 image_create_info.mipLevels = 1;
15683 image_create_info.arrayLayers = 1;
15684 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
15685 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15686 // Note: Some implementations expect color attachment usage for any
15687 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015688 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015689 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015690
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015691 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015692 ASSERT_VK_SUCCESS(err);
15693
Karl Schultz6addd812016-02-02 17:17:23 -070015694 image_create_info.imageType = VK_IMAGE_TYPE_1D;
15695 // Note: Some implementations expect color attachment usage for any
15696 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015697 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015698 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015700 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015701 ASSERT_VK_SUCCESS(err);
15702
15703 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015704 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015705 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15706 memAlloc.pNext = NULL;
15707 memAlloc.allocationSize = 0;
15708 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015709
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015710 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015711 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015712 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015713 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015714 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015715 ASSERT_VK_SUCCESS(err);
15716
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015717 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015718 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015719 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015720 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015721 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015722 ASSERT_VK_SUCCESS(err);
15723
15724 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15725 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015726 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015727 ASSERT_VK_SUCCESS(err);
15728
Tony Barbour552f6c02016-12-21 14:34:07 -070015729 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015730 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015731 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15732 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015733 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015734 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015735 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015736 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015737 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015738 resolveRegion.srcOffset.x = 0;
15739 resolveRegion.srcOffset.y = 0;
15740 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015741 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015742 resolveRegion.dstSubresource.mipLevel = 0;
15743 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015744 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015745 resolveRegion.dstOffset.x = 0;
15746 resolveRegion.dstOffset.y = 0;
15747 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015748 resolveRegion.extent.width = 1;
15749 resolveRegion.extent.height = 1;
15750 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015751 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015752 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015753
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015754 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015755
Chia-I Wuf7458c52015-10-26 21:10:41 +080015756 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015757 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015758 vkFreeMemory(m_device->device(), srcMem, NULL);
15759 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015760}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015761
Karl Schultz6addd812016-02-02 17:17:23 -070015762TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015763 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070015764 // to using a DS format, then cause it to hit error due to COLOR_BIT not
15765 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015766 // The image format check comes 2nd in validation so we trigger it first,
15767 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070015768 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15771 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015772
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015773 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015774
Chia-I Wu1b99bb22015-10-27 19:25:11 +080015775 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015776 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15777 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015778
15779 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015780 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
15781 ds_pool_ci.pNext = NULL;
15782 ds_pool_ci.maxSets = 1;
15783 ds_pool_ci.poolSizeCount = 1;
15784 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015785
15786 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015787 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015788 ASSERT_VK_SUCCESS(err);
15789
15790 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015791 dsl_binding.binding = 0;
15792 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
15793 dsl_binding.descriptorCount = 1;
15794 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
15795 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015796
15797 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015798 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
15799 ds_layout_ci.pNext = NULL;
15800 ds_layout_ci.bindingCount = 1;
15801 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015802 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015803 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015804 ASSERT_VK_SUCCESS(err);
15805
15806 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015807 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080015808 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070015809 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015810 alloc_info.descriptorPool = ds_pool;
15811 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015812 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015813 ASSERT_VK_SUCCESS(err);
15814
Karl Schultz6addd812016-02-02 17:17:23 -070015815 VkImage image_bad;
15816 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015817 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060015818 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015819 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070015820 const int32_t tex_width = 32;
15821 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015822
15823 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015824 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15825 image_create_info.pNext = NULL;
15826 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15827 image_create_info.format = tex_format_bad;
15828 image_create_info.extent.width = tex_width;
15829 image_create_info.extent.height = tex_height;
15830 image_create_info.extent.depth = 1;
15831 image_create_info.mipLevels = 1;
15832 image_create_info.arrayLayers = 1;
15833 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15834 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015835 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015836 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015838 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015839 ASSERT_VK_SUCCESS(err);
15840 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015841 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15842 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015843 ASSERT_VK_SUCCESS(err);
15844
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015845 // ---Bind image memory---
15846 VkMemoryRequirements img_mem_reqs;
15847 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
15848 VkMemoryAllocateInfo image_alloc_info = {};
15849 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15850 image_alloc_info.pNext = NULL;
15851 image_alloc_info.memoryTypeIndex = 0;
15852 image_alloc_info.allocationSize = img_mem_reqs.size;
15853 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &image_alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
15854 ASSERT_TRUE(pass);
15855 VkDeviceMemory mem;
15856 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
15857 ASSERT_VK_SUCCESS(err);
15858 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
15859 ASSERT_VK_SUCCESS(err);
15860 // -----------------------
15861
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015862 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015863 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015864 image_view_create_info.image = image_bad;
15865 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15866 image_view_create_info.format = tex_format_bad;
15867 image_view_create_info.subresourceRange.baseArrayLayer = 0;
15868 image_view_create_info.subresourceRange.baseMipLevel = 0;
15869 image_view_create_info.subresourceRange.layerCount = 1;
15870 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015871 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015872
15873 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015874 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015875
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015876 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015877
Chia-I Wuf7458c52015-10-26 21:10:41 +080015878 vkDestroyImage(m_device->device(), image_bad, NULL);
15879 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015880 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
15881 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070015882
15883 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060015884}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015885
15886TEST_F(VkLayerTest, ClearImageErrors) {
15887 TEST_DESCRIPTION("Call ClearColorImage w/ a depth|stencil image and "
15888 "ClearDepthStencilImage with a color image.");
15889
15890 ASSERT_NO_FATAL_FAILURE(InitState());
15891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15892
Tony Barbour552f6c02016-12-21 14:34:07 -070015893 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015894
15895 // Color image
15896 VkClearColorValue clear_color;
15897 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
15898 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
15899 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
15900 const int32_t img_width = 32;
15901 const int32_t img_height = 32;
15902 VkImageCreateInfo image_create_info = {};
15903 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15904 image_create_info.pNext = NULL;
15905 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15906 image_create_info.format = color_format;
15907 image_create_info.extent.width = img_width;
15908 image_create_info.extent.height = img_height;
15909 image_create_info.extent.depth = 1;
15910 image_create_info.mipLevels = 1;
15911 image_create_info.arrayLayers = 1;
15912 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15913 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15914 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15915
15916 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015917 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015919 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015920
15921 // Depth/Stencil image
15922 VkClearDepthStencilValue clear_value = {0};
15923 reqs = 0; // don't need HOST_VISIBLE DS image
15924 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
15925 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
15926 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
15927 ds_image_create_info.extent.width = 64;
15928 ds_image_create_info.extent.height = 64;
15929 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015930 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 -060015931
15932 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015933 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015935 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 -060015936
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015938
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015939 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015940 &color_range);
15941
15942 m_errorMonitor->VerifyFound();
15943
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with "
15945 "image created without "
15946 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060015947
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015948 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060015949 &color_range);
15950
15951 m_errorMonitor->VerifyFound();
15952
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015953 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15955 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015956
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015957 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(),
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070015958 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060015959
15960 m_errorMonitor->VerifyFound();
15961}
Tobin Ehliscde08892015-09-22 10:11:37 -060015962#endif // IMAGE_TESTS
15963
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015964
15965// WSI Enabled Tests
15966//
Chris Forbes09368e42016-10-13 11:59:22 +130015967#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060015968TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
15969
15970#if defined(VK_USE_PLATFORM_XCB_KHR)
15971 VkSurfaceKHR surface = VK_NULL_HANDLE;
15972
15973 VkResult err;
15974 bool pass;
15975 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
15976 VkSwapchainCreateInfoKHR swapchain_create_info = {};
15977 // uint32_t swapchain_image_count = 0;
15978 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
15979 // uint32_t image_index = 0;
15980 // VkPresentInfoKHR present_info = {};
15981
15982 ASSERT_NO_FATAL_FAILURE(InitState());
15983
15984 // Use the create function from one of the VK_KHR_*_surface extension in
15985 // order to create a surface, testing all known errors in the process,
15986 // before successfully creating a surface:
15987 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
15988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
15989 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
15990 pass = (err != VK_SUCCESS);
15991 ASSERT_TRUE(pass);
15992 m_errorMonitor->VerifyFound();
15993
15994 // Next, try to create a surface with the wrong
15995 // VkXcbSurfaceCreateInfoKHR::sType:
15996 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
15997 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
15998 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
15999 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16000 pass = (err != VK_SUCCESS);
16001 ASSERT_TRUE(pass);
16002 m_errorMonitor->VerifyFound();
16003
16004 // Create a native window, and then correctly create a surface:
16005 xcb_connection_t *connection;
16006 xcb_screen_t *screen;
16007 xcb_window_t xcb_window;
16008 xcb_intern_atom_reply_t *atom_wm_delete_window;
16009
16010 const xcb_setup_t *setup;
16011 xcb_screen_iterator_t iter;
16012 int scr;
16013 uint32_t value_mask, value_list[32];
16014 int width = 1;
16015 int height = 1;
16016
16017 connection = xcb_connect(NULL, &scr);
16018 ASSERT_TRUE(connection != NULL);
16019 setup = xcb_get_setup(connection);
16020 iter = xcb_setup_roots_iterator(setup);
16021 while (scr-- > 0)
16022 xcb_screen_next(&iter);
16023 screen = iter.data;
16024
16025 xcb_window = xcb_generate_id(connection);
16026
16027 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16028 value_list[0] = screen->black_pixel;
16029 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16030
16031 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16032 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16033
16034 /* Magic code that will send notification when window is destroyed */
16035 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16036 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16037
16038 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16039 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16040 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16041 free(reply);
16042
16043 xcb_map_window(connection, xcb_window);
16044
16045 // Force the x/y coordinates to 100,100 results are identical in consecutive
16046 // runs
16047 const uint32_t coords[] = { 100, 100 };
16048 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16049
16050 // Finally, try to correctly create a surface:
16051 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16052 xcb_create_info.pNext = NULL;
16053 xcb_create_info.flags = 0;
16054 xcb_create_info.connection = connection;
16055 xcb_create_info.window = xcb_window;
16056 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16057 pass = (err == VK_SUCCESS);
16058 ASSERT_TRUE(pass);
16059
16060 // Check if surface supports presentation:
16061
16062 // 1st, do so without having queried the queue families:
16063 VkBool32 supported = false;
16064 // TODO: Get the following error to come out:
16065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16066 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16067 "function");
16068 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16069 pass = (err != VK_SUCCESS);
16070 // ASSERT_TRUE(pass);
16071 // m_errorMonitor->VerifyFound();
16072
16073 // Next, query a queue family index that's too large:
16074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16075 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16076 pass = (err != VK_SUCCESS);
16077 ASSERT_TRUE(pass);
16078 m_errorMonitor->VerifyFound();
16079
16080 // Finally, do so correctly:
16081 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16082 // SUPPORTED
16083 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16084 pass = (err == VK_SUCCESS);
16085 ASSERT_TRUE(pass);
16086
16087 // Before proceeding, try to create a swapchain without having called
16088 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16089 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16090 swapchain_create_info.pNext = NULL;
16091 swapchain_create_info.flags = 0;
16092 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16093 swapchain_create_info.surface = surface;
16094 swapchain_create_info.imageArrayLayers = 1;
16095 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16096 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16098 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16099 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16100 pass = (err != VK_SUCCESS);
16101 ASSERT_TRUE(pass);
16102 m_errorMonitor->VerifyFound();
16103
16104 // Get the surface capabilities:
16105 VkSurfaceCapabilitiesKHR surface_capabilities;
16106
16107 // Do so correctly (only error logged by this entrypoint is if the
16108 // extension isn't enabled):
16109 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16110 pass = (err == VK_SUCCESS);
16111 ASSERT_TRUE(pass);
16112
16113 // Get the surface formats:
16114 uint32_t surface_format_count;
16115
16116 // First, try without a pointer to surface_format_count:
16117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16118 "specified as NULL");
16119 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16120 pass = (err == VK_SUCCESS);
16121 ASSERT_TRUE(pass);
16122 m_errorMonitor->VerifyFound();
16123
16124 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16125 // correctly done a 1st try (to get the count):
16126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16127 surface_format_count = 0;
16128 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16129 pass = (err == VK_SUCCESS);
16130 ASSERT_TRUE(pass);
16131 m_errorMonitor->VerifyFound();
16132
16133 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16134 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16135 pass = (err == VK_SUCCESS);
16136 ASSERT_TRUE(pass);
16137
16138 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16139 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16140
16141 // Next, do a 2nd try with surface_format_count being set too high:
16142 surface_format_count += 5;
16143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16144 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16145 pass = (err == VK_SUCCESS);
16146 ASSERT_TRUE(pass);
16147 m_errorMonitor->VerifyFound();
16148
16149 // Finally, do a correct 1st and 2nd try:
16150 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16151 pass = (err == VK_SUCCESS);
16152 ASSERT_TRUE(pass);
16153 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16154 pass = (err == VK_SUCCESS);
16155 ASSERT_TRUE(pass);
16156
16157 // Get the surface present modes:
16158 uint32_t surface_present_mode_count;
16159
16160 // First, try without a pointer to surface_format_count:
16161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16162 "specified as NULL");
16163
16164 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16165 pass = (err == VK_SUCCESS);
16166 ASSERT_TRUE(pass);
16167 m_errorMonitor->VerifyFound();
16168
16169 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16170 // correctly done a 1st try (to get the count):
16171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16172 surface_present_mode_count = 0;
16173 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16174 (VkPresentModeKHR *)&surface_present_mode_count);
16175 pass = (err == VK_SUCCESS);
16176 ASSERT_TRUE(pass);
16177 m_errorMonitor->VerifyFound();
16178
16179 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16180 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16181 pass = (err == VK_SUCCESS);
16182 ASSERT_TRUE(pass);
16183
16184 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16185 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16186
16187 // Next, do a 2nd try with surface_format_count being set too high:
16188 surface_present_mode_count += 5;
16189 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16190 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16191 pass = (err == VK_SUCCESS);
16192 ASSERT_TRUE(pass);
16193 m_errorMonitor->VerifyFound();
16194
16195 // Finally, do a correct 1st and 2nd try:
16196 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16197 pass = (err == VK_SUCCESS);
16198 ASSERT_TRUE(pass);
16199 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16200 pass = (err == VK_SUCCESS);
16201 ASSERT_TRUE(pass);
16202
16203 // Create a swapchain:
16204
16205 // First, try without a pointer to swapchain_create_info:
16206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16207 "specified as NULL");
16208
16209 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16210 pass = (err != VK_SUCCESS);
16211 ASSERT_TRUE(pass);
16212 m_errorMonitor->VerifyFound();
16213
16214 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16215 // sType:
16216 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16218
16219 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16220 pass = (err != VK_SUCCESS);
16221 ASSERT_TRUE(pass);
16222 m_errorMonitor->VerifyFound();
16223
16224 // Next, call with a NULL swapchain pointer:
16225 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16226 swapchain_create_info.pNext = NULL;
16227 swapchain_create_info.flags = 0;
16228 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16229 "specified as NULL");
16230
16231 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16232 pass = (err != VK_SUCCESS);
16233 ASSERT_TRUE(pass);
16234 m_errorMonitor->VerifyFound();
16235
16236 // TODO: Enhance swapchain layer so that
16237 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16238
16239 // Next, call with a queue family index that's too large:
16240 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16241 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16242 swapchain_create_info.queueFamilyIndexCount = 2;
16243 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16245 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16246 pass = (err != VK_SUCCESS);
16247 ASSERT_TRUE(pass);
16248 m_errorMonitor->VerifyFound();
16249
16250 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16251 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16252 swapchain_create_info.queueFamilyIndexCount = 1;
16253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16254 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16255 "pCreateInfo->pQueueFamilyIndices).");
16256 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16257 pass = (err != VK_SUCCESS);
16258 ASSERT_TRUE(pass);
16259 m_errorMonitor->VerifyFound();
16260
16261 // Next, call with an invalid imageSharingMode:
16262 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16263 swapchain_create_info.queueFamilyIndexCount = 1;
16264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16265 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16266 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16267 pass = (err != VK_SUCCESS);
16268 ASSERT_TRUE(pass);
16269 m_errorMonitor->VerifyFound();
16270 // Fix for the future:
16271 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16272 // SUPPORTED
16273 swapchain_create_info.queueFamilyIndexCount = 0;
16274 queueFamilyIndex[0] = 0;
16275 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16276
16277 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16278 // Get the images from a swapchain:
16279 // Acquire an image from a swapchain:
16280 // Present an image to a swapchain:
16281 // Destroy the swapchain:
16282
16283 // TODOs:
16284 //
16285 // - Try destroying the device without first destroying the swapchain
16286 //
16287 // - Try destroying the device without first destroying the surface
16288 //
16289 // - Try destroying the surface without first destroying the swapchain
16290
16291 // Destroy the surface:
16292 vkDestroySurfaceKHR(instance(), surface, NULL);
16293
16294 // Tear down the window:
16295 xcb_destroy_window(connection, xcb_window);
16296 xcb_disconnect(connection);
16297
16298#else // VK_USE_PLATFORM_XCB_KHR
16299 return;
16300#endif // VK_USE_PLATFORM_XCB_KHR
16301}
Chris Forbes09368e42016-10-13 11:59:22 +130016302#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016303
16304//
16305// POSITIVE VALIDATION TESTS
16306//
16307// These tests do not expect to encounter ANY validation errors pass only if this is true
16308
Tobin Ehlise0006882016-11-03 10:14:28 -060016309TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
16310 TEST_DESCRIPTION("Perform an image layout transition in a secondary command buffer followed "
16311 "by a transition in the primary.");
16312 VkResult err;
16313 m_errorMonitor->ExpectSuccess();
16314 ASSERT_NO_FATAL_FAILURE(InitState());
16315 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16316 // Allocate a secondary and primary cmd buffer
16317 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16318 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16319 command_buffer_allocate_info.commandPool = m_commandPool;
16320 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16321 command_buffer_allocate_info.commandBufferCount = 1;
16322
16323 VkCommandBuffer secondary_command_buffer;
16324 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16325 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16326 VkCommandBuffer primary_command_buffer;
16327 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16328 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16329 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16330 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16331 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16332 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16333 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16334
16335 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16336 ASSERT_VK_SUCCESS(err);
16337 VkImageObj image(m_device);
16338 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16339 ASSERT_TRUE(image.initialized());
16340 VkImageMemoryBarrier img_barrier = {};
16341 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16342 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16343 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16344 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16345 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16346 img_barrier.image = image.handle();
16347 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16348 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16349 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16350 img_barrier.subresourceRange.baseArrayLayer = 0;
16351 img_barrier.subresourceRange.baseMipLevel = 0;
16352 img_barrier.subresourceRange.layerCount = 1;
16353 img_barrier.subresourceRange.levelCount = 1;
16354 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16355 0, nullptr, 1, &img_barrier);
16356 err = vkEndCommandBuffer(secondary_command_buffer);
16357 ASSERT_VK_SUCCESS(err);
16358
16359 // Now update primary cmd buffer to execute secondary and transitions image
16360 command_buffer_begin_info.pInheritanceInfo = nullptr;
16361 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16362 ASSERT_VK_SUCCESS(err);
16363 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16364 VkImageMemoryBarrier img_barrier2 = {};
16365 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16366 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16367 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16368 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16369 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16370 img_barrier2.image = image.handle();
16371 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16372 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16373 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16374 img_barrier2.subresourceRange.baseArrayLayer = 0;
16375 img_barrier2.subresourceRange.baseMipLevel = 0;
16376 img_barrier2.subresourceRange.layerCount = 1;
16377 img_barrier2.subresourceRange.levelCount = 1;
16378 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16379 nullptr, 1, &img_barrier2);
16380 err = vkEndCommandBuffer(primary_command_buffer);
16381 ASSERT_VK_SUCCESS(err);
16382 VkSubmitInfo submit_info = {};
16383 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16384 submit_info.commandBufferCount = 1;
16385 submit_info.pCommandBuffers = &primary_command_buffer;
16386 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16387 ASSERT_VK_SUCCESS(err);
16388 m_errorMonitor->VerifyNotFound();
16389 err = vkDeviceWaitIdle(m_device->device());
16390 ASSERT_VK_SUCCESS(err);
16391 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16392 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16393}
16394
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016395// This is a positive test. No failures are expected.
16396TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
16397 TEST_DESCRIPTION("Ensure that the vkUpdateDescriptorSets validation code "
16398 "is ignoring VkWriteDescriptorSet members that are not "
16399 "related to the descriptor type specified by "
16400 "VkWriteDescriptorSet::descriptorType. Correct "
16401 "validation behavior will result in the test running to "
16402 "completion without validation errors.");
16403
16404 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16405
16406 ASSERT_NO_FATAL_FAILURE(InitState());
16407
16408 // Image Case
16409 {
16410 m_errorMonitor->ExpectSuccess();
16411
16412 VkImage image;
16413 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16414 const int32_t tex_width = 32;
16415 const int32_t tex_height = 32;
16416 VkImageCreateInfo image_create_info = {};
16417 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16418 image_create_info.pNext = NULL;
16419 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16420 image_create_info.format = tex_format;
16421 image_create_info.extent.width = tex_width;
16422 image_create_info.extent.height = tex_height;
16423 image_create_info.extent.depth = 1;
16424 image_create_info.mipLevels = 1;
16425 image_create_info.arrayLayers = 1;
16426 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16427 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16428 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16429 image_create_info.flags = 0;
16430 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16431 ASSERT_VK_SUCCESS(err);
16432
16433 VkMemoryRequirements memory_reqs;
16434 VkDeviceMemory image_memory;
16435 bool pass;
16436 VkMemoryAllocateInfo memory_info = {};
16437 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16438 memory_info.pNext = NULL;
16439 memory_info.allocationSize = 0;
16440 memory_info.memoryTypeIndex = 0;
16441 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16442 memory_info.allocationSize = memory_reqs.size;
16443 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16444 ASSERT_TRUE(pass);
16445 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16446 ASSERT_VK_SUCCESS(err);
16447 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16448 ASSERT_VK_SUCCESS(err);
16449
16450 VkImageViewCreateInfo image_view_create_info = {};
16451 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16452 image_view_create_info.image = image;
16453 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16454 image_view_create_info.format = tex_format;
16455 image_view_create_info.subresourceRange.layerCount = 1;
16456 image_view_create_info.subresourceRange.baseMipLevel = 0;
16457 image_view_create_info.subresourceRange.levelCount = 1;
16458 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16459
16460 VkImageView view;
16461 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16462 ASSERT_VK_SUCCESS(err);
16463
16464 VkDescriptorPoolSize ds_type_count = {};
16465 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16466 ds_type_count.descriptorCount = 1;
16467
16468 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16469 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16470 ds_pool_ci.pNext = NULL;
16471 ds_pool_ci.maxSets = 1;
16472 ds_pool_ci.poolSizeCount = 1;
16473 ds_pool_ci.pPoolSizes = &ds_type_count;
16474
16475 VkDescriptorPool ds_pool;
16476 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16477 ASSERT_VK_SUCCESS(err);
16478
16479 VkDescriptorSetLayoutBinding dsl_binding = {};
16480 dsl_binding.binding = 0;
16481 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16482 dsl_binding.descriptorCount = 1;
16483 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16484 dsl_binding.pImmutableSamplers = NULL;
16485
16486 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16487 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16488 ds_layout_ci.pNext = NULL;
16489 ds_layout_ci.bindingCount = 1;
16490 ds_layout_ci.pBindings = &dsl_binding;
16491 VkDescriptorSetLayout ds_layout;
16492 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16493 ASSERT_VK_SUCCESS(err);
16494
16495 VkDescriptorSet descriptor_set;
16496 VkDescriptorSetAllocateInfo alloc_info = {};
16497 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16498 alloc_info.descriptorSetCount = 1;
16499 alloc_info.descriptorPool = ds_pool;
16500 alloc_info.pSetLayouts = &ds_layout;
16501 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16502 ASSERT_VK_SUCCESS(err);
16503
16504 VkDescriptorImageInfo image_info = {};
16505 image_info.imageView = view;
16506 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16507
16508 VkWriteDescriptorSet descriptor_write;
16509 memset(&descriptor_write, 0, sizeof(descriptor_write));
16510 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16511 descriptor_write.dstSet = descriptor_set;
16512 descriptor_write.dstBinding = 0;
16513 descriptor_write.descriptorCount = 1;
16514 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16515 descriptor_write.pImageInfo = &image_info;
16516
16517 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16518 // be
16519 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16520 // This will most likely produce a crash if the parameter_validation
16521 // layer
16522 // does not correctly ignore pBufferInfo.
16523 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16524 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16525
16526 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16527
16528 m_errorMonitor->VerifyNotFound();
16529
16530 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16532 vkDestroyImageView(m_device->device(), view, NULL);
16533 vkDestroyImage(m_device->device(), image, NULL);
16534 vkFreeMemory(m_device->device(), image_memory, NULL);
16535 }
16536
16537 // Buffer Case
16538 {
16539 m_errorMonitor->ExpectSuccess();
16540
16541 VkBuffer buffer;
16542 uint32_t queue_family_index = 0;
16543 VkBufferCreateInfo buffer_create_info = {};
16544 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16545 buffer_create_info.size = 1024;
16546 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16547 buffer_create_info.queueFamilyIndexCount = 1;
16548 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16549
16550 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16551 ASSERT_VK_SUCCESS(err);
16552
16553 VkMemoryRequirements memory_reqs;
16554 VkDeviceMemory buffer_memory;
16555 bool pass;
16556 VkMemoryAllocateInfo memory_info = {};
16557 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16558 memory_info.pNext = NULL;
16559 memory_info.allocationSize = 0;
16560 memory_info.memoryTypeIndex = 0;
16561
16562 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16563 memory_info.allocationSize = memory_reqs.size;
16564 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16565 ASSERT_TRUE(pass);
16566
16567 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16568 ASSERT_VK_SUCCESS(err);
16569 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16570 ASSERT_VK_SUCCESS(err);
16571
16572 VkDescriptorPoolSize ds_type_count = {};
16573 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16574 ds_type_count.descriptorCount = 1;
16575
16576 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16577 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16578 ds_pool_ci.pNext = NULL;
16579 ds_pool_ci.maxSets = 1;
16580 ds_pool_ci.poolSizeCount = 1;
16581 ds_pool_ci.pPoolSizes = &ds_type_count;
16582
16583 VkDescriptorPool ds_pool;
16584 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16585 ASSERT_VK_SUCCESS(err);
16586
16587 VkDescriptorSetLayoutBinding dsl_binding = {};
16588 dsl_binding.binding = 0;
16589 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16590 dsl_binding.descriptorCount = 1;
16591 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16592 dsl_binding.pImmutableSamplers = NULL;
16593
16594 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16595 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16596 ds_layout_ci.pNext = NULL;
16597 ds_layout_ci.bindingCount = 1;
16598 ds_layout_ci.pBindings = &dsl_binding;
16599 VkDescriptorSetLayout ds_layout;
16600 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16601 ASSERT_VK_SUCCESS(err);
16602
16603 VkDescriptorSet descriptor_set;
16604 VkDescriptorSetAllocateInfo alloc_info = {};
16605 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16606 alloc_info.descriptorSetCount = 1;
16607 alloc_info.descriptorPool = ds_pool;
16608 alloc_info.pSetLayouts = &ds_layout;
16609 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16610 ASSERT_VK_SUCCESS(err);
16611
16612 VkDescriptorBufferInfo buffer_info = {};
16613 buffer_info.buffer = buffer;
16614 buffer_info.offset = 0;
16615 buffer_info.range = 1024;
16616
16617 VkWriteDescriptorSet descriptor_write;
16618 memset(&descriptor_write, 0, sizeof(descriptor_write));
16619 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16620 descriptor_write.dstSet = descriptor_set;
16621 descriptor_write.dstBinding = 0;
16622 descriptor_write.descriptorCount = 1;
16623 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16624 descriptor_write.pBufferInfo = &buffer_info;
16625
16626 // Set pImageInfo and pTexelBufferView to invalid values, which should
16627 // be
16628 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
16629 // This will most likely produce a crash if the parameter_validation
16630 // layer
16631 // does not correctly ignore pImageInfo.
16632 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16633 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16634
16635 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16636
16637 m_errorMonitor->VerifyNotFound();
16638
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016639 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16640 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16641 vkDestroyBuffer(m_device->device(), buffer, NULL);
16642 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16643 }
16644
16645 // Texel Buffer Case
16646 {
16647 m_errorMonitor->ExpectSuccess();
16648
16649 VkBuffer buffer;
16650 uint32_t queue_family_index = 0;
16651 VkBufferCreateInfo buffer_create_info = {};
16652 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16653 buffer_create_info.size = 1024;
16654 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
16655 buffer_create_info.queueFamilyIndexCount = 1;
16656 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
16657
16658 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
16659 ASSERT_VK_SUCCESS(err);
16660
16661 VkMemoryRequirements memory_reqs;
16662 VkDeviceMemory buffer_memory;
16663 bool pass;
16664 VkMemoryAllocateInfo memory_info = {};
16665 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16666 memory_info.pNext = NULL;
16667 memory_info.allocationSize = 0;
16668 memory_info.memoryTypeIndex = 0;
16669
16670 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
16671 memory_info.allocationSize = memory_reqs.size;
16672 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16673 ASSERT_TRUE(pass);
16674
16675 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
16676 ASSERT_VK_SUCCESS(err);
16677 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
16678 ASSERT_VK_SUCCESS(err);
16679
16680 VkBufferViewCreateInfo buff_view_ci = {};
16681 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
16682 buff_view_ci.buffer = buffer;
16683 buff_view_ci.format = VK_FORMAT_R8_UNORM;
16684 buff_view_ci.range = VK_WHOLE_SIZE;
16685 VkBufferView buffer_view;
16686 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
16687
16688 VkDescriptorPoolSize ds_type_count = {};
16689 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16690 ds_type_count.descriptorCount = 1;
16691
16692 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16693 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16694 ds_pool_ci.pNext = NULL;
16695 ds_pool_ci.maxSets = 1;
16696 ds_pool_ci.poolSizeCount = 1;
16697 ds_pool_ci.pPoolSizes = &ds_type_count;
16698
16699 VkDescriptorPool ds_pool;
16700 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16701 ASSERT_VK_SUCCESS(err);
16702
16703 VkDescriptorSetLayoutBinding dsl_binding = {};
16704 dsl_binding.binding = 0;
16705 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16706 dsl_binding.descriptorCount = 1;
16707 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16708 dsl_binding.pImmutableSamplers = NULL;
16709
16710 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16711 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16712 ds_layout_ci.pNext = NULL;
16713 ds_layout_ci.bindingCount = 1;
16714 ds_layout_ci.pBindings = &dsl_binding;
16715 VkDescriptorSetLayout ds_layout;
16716 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16717 ASSERT_VK_SUCCESS(err);
16718
16719 VkDescriptorSet descriptor_set;
16720 VkDescriptorSetAllocateInfo alloc_info = {};
16721 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16722 alloc_info.descriptorSetCount = 1;
16723 alloc_info.descriptorPool = ds_pool;
16724 alloc_info.pSetLayouts = &ds_layout;
16725 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16726 ASSERT_VK_SUCCESS(err);
16727
16728 VkWriteDescriptorSet descriptor_write;
16729 memset(&descriptor_write, 0, sizeof(descriptor_write));
16730 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16731 descriptor_write.dstSet = descriptor_set;
16732 descriptor_write.dstBinding = 0;
16733 descriptor_write.descriptorCount = 1;
16734 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
16735 descriptor_write.pTexelBufferView = &buffer_view;
16736
16737 // Set pImageInfo and pBufferInfo to invalid values, which should be
16738 // ignored for descriptorType ==
16739 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
16740 // This will most likely produce a crash if the parameter_validation
16741 // layer
16742 // does not correctly ignore pImageInfo and pBufferInfo.
16743 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
16744 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16745
16746 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16747
16748 m_errorMonitor->VerifyNotFound();
16749
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016750 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16751 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16752 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
16753 vkDestroyBuffer(m_device->device(), buffer, NULL);
16754 vkFreeMemory(m_device->device(), buffer_memory, NULL);
16755 }
16756}
16757
Tobin Ehlisf7428442016-10-25 07:58:24 -060016758TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
16759 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
16760
16761 ASSERT_NO_FATAL_FAILURE(InitState());
16762 // Create layout where two binding #s are "1"
16763 static const uint32_t NUM_BINDINGS = 3;
16764 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16765 dsl_binding[0].binding = 1;
16766 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16767 dsl_binding[0].descriptorCount = 1;
16768 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16769 dsl_binding[0].pImmutableSamplers = NULL;
16770 dsl_binding[1].binding = 0;
16771 dsl_binding[1].descriptorCount = 1;
16772 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16773 dsl_binding[1].descriptorCount = 1;
16774 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16775 dsl_binding[1].pImmutableSamplers = NULL;
16776 dsl_binding[2].binding = 1; // Duplicate binding should cause error
16777 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16778 dsl_binding[2].descriptorCount = 1;
16779 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
16780 dsl_binding[2].pImmutableSamplers = NULL;
16781
16782 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16783 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16784 ds_layout_ci.pNext = NULL;
16785 ds_layout_ci.bindingCount = NUM_BINDINGS;
16786 ds_layout_ci.pBindings = dsl_binding;
16787 VkDescriptorSetLayout ds_layout;
16788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
16789 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16790 m_errorMonitor->VerifyFound();
16791}
16792
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016793TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016794 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
16795
16796 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016797
Tony Barbour552f6c02016-12-21 14:34:07 -070016798 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016799
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060016800 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
16801
16802 {
16803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
16804 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
16805 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16806 m_errorMonitor->VerifyFound();
16807 }
16808
16809 {
16810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
16811 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
16812 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16813 m_errorMonitor->VerifyFound();
16814 }
16815
16816 {
16817 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16818 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
16819 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16820 m_errorMonitor->VerifyFound();
16821 }
16822
16823 {
16824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
16825 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
16826 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16827 m_errorMonitor->VerifyFound();
16828 }
16829
16830 {
16831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
16832 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
16833 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16834 m_errorMonitor->VerifyFound();
16835 }
16836
16837 {
16838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
16839 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
16840 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
16841 m_errorMonitor->VerifyFound();
16842 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016843
16844 {
16845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16846 VkRect2D scissor = {{-1, 0}, {16, 16}};
16847 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16848 m_errorMonitor->VerifyFound();
16849 }
16850
16851 {
16852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
16853 VkRect2D scissor = {{0, -2}, {16, 16}};
16854 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16855 m_errorMonitor->VerifyFound();
16856 }
16857
16858 {
16859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
16860 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
16861 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16862 m_errorMonitor->VerifyFound();
16863 }
16864
16865 {
16866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
16867 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
16868 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
16869 m_errorMonitor->VerifyFound();
16870 }
16871
Tony Barbour552f6c02016-12-21 14:34:07 -070016872 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060016873}
16874
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016875// This is a positive test. No failures are expected.
16876TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
16877 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
16878 VkResult err;
16879
16880 ASSERT_NO_FATAL_FAILURE(InitState());
16881 m_errorMonitor->ExpectSuccess();
16882 VkDescriptorPoolSize ds_type_count = {};
16883 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16884 ds_type_count.descriptorCount = 2;
16885
16886 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16887 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16888 ds_pool_ci.pNext = NULL;
16889 ds_pool_ci.maxSets = 1;
16890 ds_pool_ci.poolSizeCount = 1;
16891 ds_pool_ci.pPoolSizes = &ds_type_count;
16892
16893 VkDescriptorPool ds_pool;
16894 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16895 ASSERT_VK_SUCCESS(err);
16896
16897 // Create layout with two uniform buffer descriptors w/ empty binding between them
16898 static const uint32_t NUM_BINDINGS = 3;
16899 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
16900 dsl_binding[0].binding = 0;
16901 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16902 dsl_binding[0].descriptorCount = 1;
16903 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
16904 dsl_binding[0].pImmutableSamplers = NULL;
16905 dsl_binding[1].binding = 1;
16906 dsl_binding[1].descriptorCount = 0; // empty binding
16907 dsl_binding[2].binding = 2;
16908 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16909 dsl_binding[2].descriptorCount = 1;
16910 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
16911 dsl_binding[2].pImmutableSamplers = NULL;
16912
16913 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16914 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16915 ds_layout_ci.pNext = NULL;
16916 ds_layout_ci.bindingCount = NUM_BINDINGS;
16917 ds_layout_ci.pBindings = dsl_binding;
16918 VkDescriptorSetLayout ds_layout;
16919 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16920 ASSERT_VK_SUCCESS(err);
16921
16922 VkDescriptorSet descriptor_set = {};
16923 VkDescriptorSetAllocateInfo alloc_info = {};
16924 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16925 alloc_info.descriptorSetCount = 1;
16926 alloc_info.descriptorPool = ds_pool;
16927 alloc_info.pSetLayouts = &ds_layout;
16928 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16929 ASSERT_VK_SUCCESS(err);
16930
16931 // Create a buffer to be used for update
16932 VkBufferCreateInfo buff_ci = {};
16933 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16934 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
16935 buff_ci.size = 256;
16936 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16937 VkBuffer buffer;
16938 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
16939 ASSERT_VK_SUCCESS(err);
16940 // Have to bind memory to buffer before descriptor update
16941 VkMemoryAllocateInfo mem_alloc = {};
16942 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16943 mem_alloc.pNext = NULL;
16944 mem_alloc.allocationSize = 512; // one allocation for both buffers
16945 mem_alloc.memoryTypeIndex = 0;
16946
16947 VkMemoryRequirements mem_reqs;
16948 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
16949 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
16950 if (!pass) {
16951 vkDestroyBuffer(m_device->device(), buffer, NULL);
16952 return;
16953 }
16954
16955 VkDeviceMemory mem;
16956 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
16957 ASSERT_VK_SUCCESS(err);
16958 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
16959 ASSERT_VK_SUCCESS(err);
16960
16961 // Only update the descriptor at binding 2
16962 VkDescriptorBufferInfo buff_info = {};
16963 buff_info.buffer = buffer;
16964 buff_info.offset = 0;
16965 buff_info.range = VK_WHOLE_SIZE;
16966 VkWriteDescriptorSet descriptor_write = {};
16967 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16968 descriptor_write.dstBinding = 2;
16969 descriptor_write.descriptorCount = 1;
16970 descriptor_write.pTexelBufferView = nullptr;
16971 descriptor_write.pBufferInfo = &buff_info;
16972 descriptor_write.pImageInfo = nullptr;
16973 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
16974 descriptor_write.dstSet = descriptor_set;
16975
16976 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16977
16978 m_errorMonitor->VerifyNotFound();
16979 // Cleanup
16980 vkFreeMemory(m_device->device(), mem, NULL);
16981 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16982 vkDestroyBuffer(m_device->device(), buffer, NULL);
16983 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16984}
16985
16986// This is a positive test. No failures are expected.
16987TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
16988 VkResult err;
16989 bool pass;
16990
16991 TEST_DESCRIPTION("Create a buffer, allocate memory, bind memory, destroy "
16992 "the buffer, create an image, and bind the same memory to "
16993 "it");
16994
16995 m_errorMonitor->ExpectSuccess();
16996
16997 ASSERT_NO_FATAL_FAILURE(InitState());
16998
16999 VkBuffer buffer;
17000 VkImage image;
17001 VkDeviceMemory mem;
17002 VkMemoryRequirements mem_reqs;
17003
17004 VkBufferCreateInfo buf_info = {};
17005 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17006 buf_info.pNext = NULL;
17007 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17008 buf_info.size = 256;
17009 buf_info.queueFamilyIndexCount = 0;
17010 buf_info.pQueueFamilyIndices = NULL;
17011 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17012 buf_info.flags = 0;
17013 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17014 ASSERT_VK_SUCCESS(err);
17015
17016 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17017
17018 VkMemoryAllocateInfo alloc_info = {};
17019 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17020 alloc_info.pNext = NULL;
17021 alloc_info.memoryTypeIndex = 0;
17022
17023 // Ensure memory is big enough for both bindings
17024 alloc_info.allocationSize = 0x10000;
17025
17026 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17027 if (!pass) {
17028 vkDestroyBuffer(m_device->device(), buffer, NULL);
17029 return;
17030 }
17031
17032 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17033 ASSERT_VK_SUCCESS(err);
17034
17035 uint8_t *pData;
17036 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17037 ASSERT_VK_SUCCESS(err);
17038
17039 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17040
17041 vkUnmapMemory(m_device->device(), mem);
17042
17043 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17044 ASSERT_VK_SUCCESS(err);
17045
17046 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17047 // memory. In fact, it was never used by the GPU.
17048 // Just be be sure, wait for idle.
17049 vkDestroyBuffer(m_device->device(), buffer, NULL);
17050 vkDeviceWaitIdle(m_device->device());
17051
Tobin Ehlis6a005702016-12-28 15:25:56 -070017052 // Use optimal as some platforms report linear support but then fail image creation
17053 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17054 VkImageFormatProperties image_format_properties;
17055 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17056 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17057 if (image_format_properties.maxExtent.width == 0) {
17058 printf("Image format not supported; skipped.\n");
17059 vkFreeMemory(m_device->device(), mem, NULL);
17060 return;
17061 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017062 VkImageCreateInfo image_create_info = {};
17063 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17064 image_create_info.pNext = NULL;
17065 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17066 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17067 image_create_info.extent.width = 64;
17068 image_create_info.extent.height = 64;
17069 image_create_info.extent.depth = 1;
17070 image_create_info.mipLevels = 1;
17071 image_create_info.arrayLayers = 1;
17072 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017073 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017074 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17075 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17076 image_create_info.queueFamilyIndexCount = 0;
17077 image_create_info.pQueueFamilyIndices = NULL;
17078 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17079 image_create_info.flags = 0;
17080
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017081 /* Create a mappable image. It will be the texture if linear images are ok
17082 * to be textures or it will be the staging image if they are not.
17083 */
17084 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17085 ASSERT_VK_SUCCESS(err);
17086
17087 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17088
Tobin Ehlis6a005702016-12-28 15:25:56 -070017089 VkMemoryAllocateInfo mem_alloc = {};
17090 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17091 mem_alloc.pNext = NULL;
17092 mem_alloc.allocationSize = 0;
17093 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017094 mem_alloc.allocationSize = mem_reqs.size;
17095
17096 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17097 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017098 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017099 vkDestroyImage(m_device->device(), image, NULL);
17100 return;
17101 }
17102
17103 // VALIDATION FAILURE:
17104 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17105 ASSERT_VK_SUCCESS(err);
17106
17107 m_errorMonitor->VerifyNotFound();
17108
17109 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017110 vkDestroyImage(m_device->device(), image, NULL);
17111}
17112
Tobin Ehlis953e8392016-11-17 10:54:13 -070017113TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17114 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17115 // We previously had a bug where dynamic offset of inactive bindings was still being used
17116 VkResult err;
17117 m_errorMonitor->ExpectSuccess();
17118
17119 ASSERT_NO_FATAL_FAILURE(InitState());
17120 ASSERT_NO_FATAL_FAILURE(InitViewport());
17121 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17122
17123 VkDescriptorPoolSize ds_type_count = {};
17124 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17125 ds_type_count.descriptorCount = 3;
17126
17127 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17128 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17129 ds_pool_ci.pNext = NULL;
17130 ds_pool_ci.maxSets = 1;
17131 ds_pool_ci.poolSizeCount = 1;
17132 ds_pool_ci.pPoolSizes = &ds_type_count;
17133
17134 VkDescriptorPool ds_pool;
17135 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17136 ASSERT_VK_SUCCESS(err);
17137
17138 const uint32_t BINDING_COUNT = 3;
17139 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017140 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017141 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17142 dsl_binding[0].descriptorCount = 1;
17143 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17144 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017145 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017146 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17147 dsl_binding[1].descriptorCount = 1;
17148 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17149 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017150 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017151 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17152 dsl_binding[2].descriptorCount = 1;
17153 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17154 dsl_binding[2].pImmutableSamplers = NULL;
17155
17156 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17157 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17158 ds_layout_ci.pNext = NULL;
17159 ds_layout_ci.bindingCount = BINDING_COUNT;
17160 ds_layout_ci.pBindings = dsl_binding;
17161 VkDescriptorSetLayout ds_layout;
17162 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17163 ASSERT_VK_SUCCESS(err);
17164
17165 VkDescriptorSet descriptor_set;
17166 VkDescriptorSetAllocateInfo alloc_info = {};
17167 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17168 alloc_info.descriptorSetCount = 1;
17169 alloc_info.descriptorPool = ds_pool;
17170 alloc_info.pSetLayouts = &ds_layout;
17171 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17172 ASSERT_VK_SUCCESS(err);
17173
17174 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17175 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17176 pipeline_layout_ci.pNext = NULL;
17177 pipeline_layout_ci.setLayoutCount = 1;
17178 pipeline_layout_ci.pSetLayouts = &ds_layout;
17179
17180 VkPipelineLayout pipeline_layout;
17181 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17182 ASSERT_VK_SUCCESS(err);
17183
17184 // Create two buffers to update the descriptors with
17185 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17186 uint32_t qfi = 0;
17187 VkBufferCreateInfo buffCI = {};
17188 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17189 buffCI.size = 2048;
17190 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17191 buffCI.queueFamilyIndexCount = 1;
17192 buffCI.pQueueFamilyIndices = &qfi;
17193
17194 VkBuffer dyub1;
17195 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17196 ASSERT_VK_SUCCESS(err);
17197 // buffer2
17198 buffCI.size = 1024;
17199 VkBuffer dyub2;
17200 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17201 ASSERT_VK_SUCCESS(err);
17202 // Allocate memory and bind to buffers
17203 VkMemoryAllocateInfo mem_alloc[2] = {};
17204 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17205 mem_alloc[0].pNext = NULL;
17206 mem_alloc[0].memoryTypeIndex = 0;
17207 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17208 mem_alloc[1].pNext = NULL;
17209 mem_alloc[1].memoryTypeIndex = 0;
17210
17211 VkMemoryRequirements mem_reqs1;
17212 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17213 VkMemoryRequirements mem_reqs2;
17214 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17215 mem_alloc[0].allocationSize = mem_reqs1.size;
17216 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17217 mem_alloc[1].allocationSize = mem_reqs2.size;
17218 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17219 if (!pass) {
17220 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17221 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17222 return;
17223 }
17224
17225 VkDeviceMemory mem1;
17226 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17227 ASSERT_VK_SUCCESS(err);
17228 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17229 ASSERT_VK_SUCCESS(err);
17230 VkDeviceMemory mem2;
17231 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17232 ASSERT_VK_SUCCESS(err);
17233 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17234 ASSERT_VK_SUCCESS(err);
17235 // Update descriptors
17236 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17237 buff_info[0].buffer = dyub1;
17238 buff_info[0].offset = 0;
17239 buff_info[0].range = 256;
17240 buff_info[1].buffer = dyub1;
17241 buff_info[1].offset = 256;
17242 buff_info[1].range = 512;
17243 buff_info[2].buffer = dyub2;
17244 buff_info[2].offset = 0;
17245 buff_info[2].range = 512;
17246
17247 VkWriteDescriptorSet descriptor_write;
17248 memset(&descriptor_write, 0, sizeof(descriptor_write));
17249 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17250 descriptor_write.dstSet = descriptor_set;
17251 descriptor_write.dstBinding = 0;
17252 descriptor_write.descriptorCount = BINDING_COUNT;
17253 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17254 descriptor_write.pBufferInfo = buff_info;
17255
17256 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17257
Tony Barbour552f6c02016-12-21 14:34:07 -070017258 m_commandBuffer->BeginCommandBuffer();
17259 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017260
17261 // Create PSO to be used for draw-time errors below
17262 char const *vsSource = "#version 450\n"
17263 "\n"
17264 "out gl_PerVertex { \n"
17265 " vec4 gl_Position;\n"
17266 "};\n"
17267 "void main(){\n"
17268 " gl_Position = vec4(1);\n"
17269 "}\n";
17270 char const *fsSource = "#version 450\n"
17271 "\n"
17272 "layout(location=0) out vec4 x;\n"
17273 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17274 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17275 "void main(){\n"
17276 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17277 "}\n";
17278 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17279 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17280 VkPipelineObj pipe(m_device);
17281 pipe.SetViewport(m_viewports);
17282 pipe.SetScissor(m_scissors);
17283 pipe.AddShader(&vs);
17284 pipe.AddShader(&fs);
17285 pipe.AddColorAttachment();
17286 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17287
17288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17289 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17290 // we used to have a bug in this case.
17291 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17292 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17293 &descriptor_set, BINDING_COUNT, dyn_off);
17294 Draw(1, 0, 0, 0);
17295 m_errorMonitor->VerifyNotFound();
17296
17297 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17298 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17299 vkFreeMemory(m_device->device(), mem1, NULL);
17300 vkFreeMemory(m_device->device(), mem2, NULL);
17301
17302 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17303 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17304 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17305}
17306
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017307TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
17308
17309 TEST_DESCRIPTION("Ensure that validations handling of non-coherent memory "
17310 "mapping while using VK_WHOLE_SIZE does not cause access "
17311 "violations");
17312 VkResult err;
17313 uint8_t *pData;
17314 ASSERT_NO_FATAL_FAILURE(InitState());
17315
17316 VkDeviceMemory mem;
17317 VkMemoryRequirements mem_reqs;
17318 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017319 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017320 VkMemoryAllocateInfo alloc_info = {};
17321 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17322 alloc_info.pNext = NULL;
17323 alloc_info.memoryTypeIndex = 0;
17324
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017325 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017326 alloc_info.allocationSize = allocation_size;
17327
17328 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17329 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
17330 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17331 if (!pass) {
17332 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17333 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17334 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17335 if (!pass) {
17336 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
17337 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
17338 VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17339 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
17340 if (!pass) {
17341 return;
17342 }
17343 }
17344 }
17345
17346 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17347 ASSERT_VK_SUCCESS(err);
17348
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017349 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017350 m_errorMonitor->ExpectSuccess();
17351 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17352 ASSERT_VK_SUCCESS(err);
17353 VkMappedMemoryRange mmr = {};
17354 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17355 mmr.memory = mem;
17356 mmr.offset = 0;
17357 mmr.size = VK_WHOLE_SIZE;
17358 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17359 ASSERT_VK_SUCCESS(err);
17360 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17361 ASSERT_VK_SUCCESS(err);
17362 m_errorMonitor->VerifyNotFound();
17363 vkUnmapMemory(m_device->device(), mem);
17364
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017365 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017366 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017367 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017368 ASSERT_VK_SUCCESS(err);
17369 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17370 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017371 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017372 mmr.size = VK_WHOLE_SIZE;
17373 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17374 ASSERT_VK_SUCCESS(err);
17375 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17376 ASSERT_VK_SUCCESS(err);
17377 m_errorMonitor->VerifyNotFound();
17378 vkUnmapMemory(m_device->device(), mem);
17379
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017380 // Map with offset and size
17381 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017382 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017383 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017384 ASSERT_VK_SUCCESS(err);
17385 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17386 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017387 mmr.offset = 4 * atom_size;
17388 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017389 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17390 ASSERT_VK_SUCCESS(err);
17391 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17392 ASSERT_VK_SUCCESS(err);
17393 m_errorMonitor->VerifyNotFound();
17394 vkUnmapMemory(m_device->device(), mem);
17395
17396 // Map without offset and flush WHOLE_SIZE with two separate offsets
17397 m_errorMonitor->ExpectSuccess();
17398 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17399 ASSERT_VK_SUCCESS(err);
17400 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17401 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017402 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017403 mmr.size = VK_WHOLE_SIZE;
17404 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17405 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017406 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017407 mmr.size = VK_WHOLE_SIZE;
17408 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17409 ASSERT_VK_SUCCESS(err);
17410 m_errorMonitor->VerifyNotFound();
17411 vkUnmapMemory(m_device->device(), mem);
17412
17413 vkFreeMemory(m_device->device(), mem, NULL);
17414}
17415
17416// This is a positive test. We used to expect error in this case but spec now allows it
17417TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17418 m_errorMonitor->ExpectSuccess();
17419 vk_testing::Fence testFence;
17420 VkFenceCreateInfo fenceInfo = {};
17421 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17422 fenceInfo.pNext = NULL;
17423
17424 ASSERT_NO_FATAL_FAILURE(InitState());
17425 testFence.init(*m_device, fenceInfo);
17426 VkFence fences[1] = { testFence.handle() };
17427 VkResult result = vkResetFences(m_device->device(), 1, fences);
17428 ASSERT_VK_SUCCESS(result);
17429
17430 m_errorMonitor->VerifyNotFound();
17431}
17432
17433TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17434 m_errorMonitor->ExpectSuccess();
17435
17436 ASSERT_NO_FATAL_FAILURE(InitState());
17437 VkResult err;
17438
17439 // Record (empty!) command buffer that can be submitted multiple times
17440 // simultaneously.
17441 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17442 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr };
17443 m_commandBuffer->BeginCommandBuffer(&cbbi);
17444 m_commandBuffer->EndCommandBuffer();
17445
17446 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17447 VkFence fence;
17448 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
17449 ASSERT_VK_SUCCESS(err);
17450
17451 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
17452 VkSemaphore s1, s2;
17453 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
17454 ASSERT_VK_SUCCESS(err);
17455 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
17456 ASSERT_VK_SUCCESS(err);
17457
17458 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
17459 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1 };
17460 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
17461 ASSERT_VK_SUCCESS(err);
17462
17463 // Submit CB again, signaling s2.
17464 si.pSignalSemaphores = &s2;
17465 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
17466 ASSERT_VK_SUCCESS(err);
17467
17468 // Wait for fence.
17469 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
17470 ASSERT_VK_SUCCESS(err);
17471
17472 // CB is still in flight from second submission, but semaphore s1 is no
17473 // longer in flight. delete it.
17474 vkDestroySemaphore(m_device->device(), s1, nullptr);
17475
17476 m_errorMonitor->VerifyNotFound();
17477
17478 // Force device idle and clean up remaining objects
17479 vkDeviceWaitIdle(m_device->device());
17480 vkDestroySemaphore(m_device->device(), s2, nullptr);
17481 vkDestroyFence(m_device->device(), fence, nullptr);
17482}
17483
17484TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
17485 m_errorMonitor->ExpectSuccess();
17486
17487 ASSERT_NO_FATAL_FAILURE(InitState());
17488 VkResult err;
17489
17490 // A fence created signaled
17491 VkFenceCreateInfo fci1 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT };
17492 VkFence f1;
17493 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
17494 ASSERT_VK_SUCCESS(err);
17495
17496 // A fence created not
17497 VkFenceCreateInfo fci2 = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
17498 VkFence f2;
17499 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
17500 ASSERT_VK_SUCCESS(err);
17501
17502 // Submit the unsignaled fence
17503 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr };
17504 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
17505
17506 // Wait on both fences, with signaled first.
17507 VkFence fences[] = { f1, f2 };
17508 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
17509
17510 // Should have both retired!
17511 vkDestroyFence(m_device->device(), f1, nullptr);
17512 vkDestroyFence(m_device->device(), f2, nullptr);
17513
17514 m_errorMonitor->VerifyNotFound();
17515}
17516
17517TEST_F(VkPositiveLayerTest, ValidUsage) {
17518 TEST_DESCRIPTION("Verify that creating an image view from an image with valid usage "
17519 "doesn't generate validation errors");
17520
17521 ASSERT_NO_FATAL_FAILURE(InitState());
17522
17523 m_errorMonitor->ExpectSuccess();
17524 // Verify that we can create a view with usage INPUT_ATTACHMENT
17525 VkImageObj image(m_device);
17526 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17527 ASSERT_TRUE(image.initialized());
17528 VkImageView imageView;
17529 VkImageViewCreateInfo ivci = {};
17530 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17531 ivci.image = image.handle();
17532 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
17533 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
17534 ivci.subresourceRange.layerCount = 1;
17535 ivci.subresourceRange.baseMipLevel = 0;
17536 ivci.subresourceRange.levelCount = 1;
17537 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17538
17539 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
17540 m_errorMonitor->VerifyNotFound();
17541 vkDestroyImageView(m_device->device(), imageView, NULL);
17542}
17543
17544// This is a positive test. No failures are expected.
17545TEST_F(VkPositiveLayerTest, BindSparse) {
17546 TEST_DESCRIPTION("Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
17547 "and then free the memory");
17548
17549 ASSERT_NO_FATAL_FAILURE(InitState());
17550
17551 auto index = m_device->graphics_queue_node_index_;
17552 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT))
17553 return;
17554
17555 m_errorMonitor->ExpectSuccess();
17556
17557 VkImage image;
17558 VkImageCreateInfo image_create_info = {};
17559 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17560 image_create_info.pNext = NULL;
17561 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17562 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17563 image_create_info.extent.width = 64;
17564 image_create_info.extent.height = 64;
17565 image_create_info.extent.depth = 1;
17566 image_create_info.mipLevels = 1;
17567 image_create_info.arrayLayers = 1;
17568 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17569 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17570 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
17571 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
17572 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17573 ASSERT_VK_SUCCESS(err);
17574
17575 VkMemoryRequirements memory_reqs;
17576 VkDeviceMemory memory_one, memory_two;
17577 bool pass;
17578 VkMemoryAllocateInfo memory_info = {};
17579 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17580 memory_info.pNext = NULL;
17581 memory_info.allocationSize = 0;
17582 memory_info.memoryTypeIndex = 0;
17583 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17584 // Find an image big enough to allow sparse mapping of 2 memory regions
17585 // Increase the image size until it is at least twice the
17586 // size of the required alignment, to ensure we can bind both
17587 // allocated memory blocks to the image on aligned offsets.
17588 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
17589 vkDestroyImage(m_device->device(), image, nullptr);
17590 image_create_info.extent.width *= 2;
17591 image_create_info.extent.height *= 2;
17592 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
17593 ASSERT_VK_SUCCESS(err);
17594 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17595 }
17596 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
17597 // at the end of the first
17598 memory_info.allocationSize = memory_reqs.alignment;
17599 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17600 ASSERT_TRUE(pass);
17601 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
17602 ASSERT_VK_SUCCESS(err);
17603 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
17604 ASSERT_VK_SUCCESS(err);
17605 VkSparseMemoryBind binds[2];
17606 binds[0].flags = 0;
17607 binds[0].memory = memory_one;
17608 binds[0].memoryOffset = 0;
17609 binds[0].resourceOffset = 0;
17610 binds[0].size = memory_info.allocationSize;
17611 binds[1].flags = 0;
17612 binds[1].memory = memory_two;
17613 binds[1].memoryOffset = 0;
17614 binds[1].resourceOffset = memory_info.allocationSize;
17615 binds[1].size = memory_info.allocationSize;
17616
17617 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
17618 opaqueBindInfo.image = image;
17619 opaqueBindInfo.bindCount = 2;
17620 opaqueBindInfo.pBinds = binds;
17621
17622 VkFence fence = VK_NULL_HANDLE;
17623 VkBindSparseInfo bindSparseInfo = {};
17624 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
17625 bindSparseInfo.imageOpaqueBindCount = 1;
17626 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
17627
17628 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
17629 vkQueueWaitIdle(m_device->m_queue);
17630 vkDestroyImage(m_device->device(), image, NULL);
17631 vkFreeMemory(m_device->device(), memory_one, NULL);
17632 vkFreeMemory(m_device->device(), memory_two, NULL);
17633 m_errorMonitor->VerifyNotFound();
17634}
17635
17636TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
17637 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass with an attachment's "
17638 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
17639 "the command buffer has prior knowledge of that "
17640 "attachment's layout.");
17641
17642 m_errorMonitor->ExpectSuccess();
17643
17644 ASSERT_NO_FATAL_FAILURE(InitState());
17645
17646 // A renderpass with one color attachment.
17647 VkAttachmentDescription attachment = { 0,
17648 VK_FORMAT_R8G8B8A8_UNORM,
17649 VK_SAMPLE_COUNT_1_BIT,
17650 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17651 VK_ATTACHMENT_STORE_OP_STORE,
17652 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17653 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17654 VK_IMAGE_LAYOUT_UNDEFINED,
17655 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17656
17657 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17658
17659 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17660
17661 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17662
17663 VkRenderPass rp;
17664 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17665 ASSERT_VK_SUCCESS(err);
17666
17667 // A compatible framebuffer.
17668 VkImageObj image(m_device);
17669 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17670 ASSERT_TRUE(image.initialized());
17671
17672 VkImageViewCreateInfo ivci = {
17673 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17674 nullptr,
17675 0,
17676 image.handle(),
17677 VK_IMAGE_VIEW_TYPE_2D,
17678 VK_FORMAT_R8G8B8A8_UNORM,
17679 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17680 VK_COMPONENT_SWIZZLE_IDENTITY },
17681 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17682 };
17683 VkImageView view;
17684 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17685 ASSERT_VK_SUCCESS(err);
17686
17687 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17688 VkFramebuffer fb;
17689 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17690 ASSERT_VK_SUCCESS(err);
17691
17692 // Record a single command buffer which uses this renderpass twice. The
17693 // bug is triggered at the beginning of the second renderpass, when the
17694 // command buffer already has a layout recorded for the attachment.
17695 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 -070017696 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017697 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17698 vkCmdEndRenderPass(m_commandBuffer->handle());
17699 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17700
17701 m_errorMonitor->VerifyNotFound();
17702
17703 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017704 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017705
17706 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17707 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17708 vkDestroyImageView(m_device->device(), view, nullptr);
17709}
17710
17711TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
17712 TEST_DESCRIPTION("This test should pass. Create a Framebuffer and "
17713 "command buffer, bind them together, then destroy "
17714 "command pool and framebuffer and verify there are no "
17715 "errors.");
17716
17717 m_errorMonitor->ExpectSuccess();
17718
17719 ASSERT_NO_FATAL_FAILURE(InitState());
17720
17721 // A renderpass with one color attachment.
17722 VkAttachmentDescription attachment = { 0,
17723 VK_FORMAT_R8G8B8A8_UNORM,
17724 VK_SAMPLE_COUNT_1_BIT,
17725 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17726 VK_ATTACHMENT_STORE_OP_STORE,
17727 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17728 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17729 VK_IMAGE_LAYOUT_UNDEFINED,
17730 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17731
17732 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17733
17734 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17735
17736 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr };
17737
17738 VkRenderPass rp;
17739 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17740 ASSERT_VK_SUCCESS(err);
17741
17742 // A compatible framebuffer.
17743 VkImageObj image(m_device);
17744 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17745 ASSERT_TRUE(image.initialized());
17746
17747 VkImageViewCreateInfo ivci = {
17748 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17749 nullptr,
17750 0,
17751 image.handle(),
17752 VK_IMAGE_VIEW_TYPE_2D,
17753 VK_FORMAT_R8G8B8A8_UNORM,
17754 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17755 VK_COMPONENT_SWIZZLE_IDENTITY },
17756 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17757 };
17758 VkImageView view;
17759 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17760 ASSERT_VK_SUCCESS(err);
17761
17762 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17763 VkFramebuffer fb;
17764 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17765 ASSERT_VK_SUCCESS(err);
17766
17767 // Explicitly create a command buffer to bind the FB to so that we can then
17768 // destroy the command pool in order to implicitly free command buffer
17769 VkCommandPool command_pool;
17770 VkCommandPoolCreateInfo pool_create_info{};
17771 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17772 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17773 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17774 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17775
17776 VkCommandBuffer command_buffer;
17777 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17778 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17779 command_buffer_allocate_info.commandPool = command_pool;
17780 command_buffer_allocate_info.commandBufferCount = 1;
17781 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17782 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
17783
17784 // Begin our cmd buffer with renderpass using our framebuffer
17785 VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb,{ { 0, 0 },{ 32, 32 } }, 0, nullptr };
17786 VkCommandBufferBeginInfo begin_info{};
17787 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17788 vkBeginCommandBuffer(command_buffer, &begin_info);
17789
17790 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17791 vkCmdEndRenderPass(command_buffer);
17792 vkEndCommandBuffer(command_buffer);
17793 vkDestroyImageView(m_device->device(), view, nullptr);
17794 // Destroy command pool to implicitly free command buffer
17795 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17796 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17797 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17798 m_errorMonitor->VerifyNotFound();
17799}
17800
17801TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
17802 TEST_DESCRIPTION("Ensure that CmdBeginRenderPass applies the layout "
17803 "transitions for the first subpass");
17804
17805 m_errorMonitor->ExpectSuccess();
17806
17807 ASSERT_NO_FATAL_FAILURE(InitState());
17808
17809 // A renderpass with one color attachment.
17810 VkAttachmentDescription attachment = { 0,
17811 VK_FORMAT_R8G8B8A8_UNORM,
17812 VK_SAMPLE_COUNT_1_BIT,
17813 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17814 VK_ATTACHMENT_STORE_OP_STORE,
17815 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17816 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17817 VK_IMAGE_LAYOUT_UNDEFINED,
17818 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17819
17820 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
17821
17822 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
17823
17824 VkSubpassDependency dep = { 0,
17825 0,
17826 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17827 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17828 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17829 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17830 VK_DEPENDENCY_BY_REGION_BIT };
17831
17832 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17833
17834 VkResult err;
17835 VkRenderPass rp;
17836 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17837 ASSERT_VK_SUCCESS(err);
17838
17839 // A compatible framebuffer.
17840 VkImageObj image(m_device);
17841 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17842 ASSERT_TRUE(image.initialized());
17843
17844 VkImageViewCreateInfo ivci = {
17845 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17846 nullptr,
17847 0,
17848 image.handle(),
17849 VK_IMAGE_VIEW_TYPE_2D,
17850 VK_FORMAT_R8G8B8A8_UNORM,
17851 { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
17852 VK_COMPONENT_SWIZZLE_IDENTITY },
17853 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 },
17854 };
17855 VkImageView view;
17856 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17857 ASSERT_VK_SUCCESS(err);
17858
17859 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17860 VkFramebuffer fb;
17861 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17862 ASSERT_VK_SUCCESS(err);
17863
17864 // Record a single command buffer which issues a pipeline barrier w/
17865 // image memory barrier for the attachment. This detects the previously
17866 // missing tracking of the subpass layout by throwing a validation error
17867 // if it doesn't occur.
17868 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 -070017869 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017870 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17871
17872 VkImageMemoryBarrier imb = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
17873 nullptr,
17874 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17875 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17876 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17877 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
17878 VK_QUEUE_FAMILY_IGNORED,
17879 VK_QUEUE_FAMILY_IGNORED,
17880 image.handle(),
17881 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
17882 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17883 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17884 &imb);
17885
17886 vkCmdEndRenderPass(m_commandBuffer->handle());
17887 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070017888 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017889
17890 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17891 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17892 vkDestroyImageView(m_device->device(), view, nullptr);
17893}
17894
17895TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
17896 TEST_DESCRIPTION("Validate that when an imageView of a depth/stencil image "
17897 "is used as a depth/stencil framebuffer attachment, the "
17898 "aspectMask is ignored and both depth and stencil image "
17899 "subresources are used.");
17900
17901 VkFormatProperties format_properties;
17902 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
17903 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
17904 return;
17905 }
17906
17907 m_errorMonitor->ExpectSuccess();
17908
17909 ASSERT_NO_FATAL_FAILURE(InitState());
17910
17911 VkAttachmentDescription attachment = { 0,
17912 VK_FORMAT_D32_SFLOAT_S8_UINT,
17913 VK_SAMPLE_COUNT_1_BIT,
17914 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17915 VK_ATTACHMENT_STORE_OP_STORE,
17916 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
17917 VK_ATTACHMENT_STORE_OP_DONT_CARE,
17918 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
17919 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17920
17921 VkAttachmentReference att_ref = { 0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
17922
17923 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr };
17924
17925 VkSubpassDependency dep = { 0,
17926 0,
17927 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17928 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17929 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17930 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
17931 VK_DEPENDENCY_BY_REGION_BIT};
17932
17933 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep };
17934
17935 VkResult err;
17936 VkRenderPass rp;
17937 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
17938 ASSERT_VK_SUCCESS(err);
17939
17940 VkImageObj image(m_device);
17941 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
17942 0x26, // usage
17943 VK_IMAGE_TILING_OPTIMAL, 0);
17944 ASSERT_TRUE(image.initialized());
17945 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
17946
17947 VkImageViewCreateInfo ivci = {
17948 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
17949 nullptr,
17950 0,
17951 image.handle(),
17952 VK_IMAGE_VIEW_TYPE_2D,
17953 VK_FORMAT_D32_SFLOAT_S8_UINT,
17954 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A },
17955 { 0x2, 0, 1, 0, 1 },
17956 };
17957 VkImageView view;
17958 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
17959 ASSERT_VK_SUCCESS(err);
17960
17961 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1 };
17962 VkFramebuffer fb;
17963 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
17964 ASSERT_VK_SUCCESS(err);
17965
17966 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 -070017967 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017968 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
17969
17970 VkImageMemoryBarrier imb = {};
17971 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17972 imb.pNext = nullptr;
17973 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
17974 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17975 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17976 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17977 imb.srcQueueFamilyIndex = 0;
17978 imb.dstQueueFamilyIndex = 0;
17979 imb.image = image.handle();
17980 imb.subresourceRange.aspectMask = 0x6;
17981 imb.subresourceRange.baseMipLevel = 0;
17982 imb.subresourceRange.levelCount = 0x1;
17983 imb.subresourceRange.baseArrayLayer = 0;
17984 imb.subresourceRange.layerCount = 0x1;
17985
17986 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
17987 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
17988 &imb);
17989
17990 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070017991 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017992 QueueCommandBuffer(false);
17993 m_errorMonitor->VerifyNotFound();
17994
17995 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
17996 vkDestroyRenderPass(m_device->device(), rp, nullptr);
17997 vkDestroyImageView(m_device->device(), view, nullptr);
17998}
17999
18000TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
18001 TEST_DESCRIPTION("Ensure that layout transitions work correctly without "
18002 "errors, when an attachment reference is "
18003 "VK_ATTACHMENT_UNUSED");
18004
18005 m_errorMonitor->ExpectSuccess();
18006
18007 ASSERT_NO_FATAL_FAILURE(InitState());
18008
18009 // A renderpass with no attachments
18010 VkAttachmentReference att_ref = { VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
18011
18012 VkSubpassDescription subpass = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr };
18013
18014 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr };
18015
18016 VkRenderPass rp;
18017 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18018 ASSERT_VK_SUCCESS(err);
18019
18020 // A compatible framebuffer.
18021 VkFramebufferCreateInfo fci = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1 };
18022 VkFramebuffer fb;
18023 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18024 ASSERT_VK_SUCCESS(err);
18025
18026 // Record a command buffer which just begins and ends the renderpass. The
18027 // bug manifests in BeginRenderPass.
18028 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 -070018029 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018030 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18031 vkCmdEndRenderPass(m_commandBuffer->handle());
18032 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018033 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018034
18035 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18036 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18037}
18038
18039// This is a positive test. No errors are expected.
18040TEST_F(VkPositiveLayerTest, StencilLoadOp) {
18041 TEST_DESCRIPTION("Create a stencil-only attachment with a LOAD_OP set to "
18042 "CLEAR. stencil[Load|Store]Op used to be ignored.");
18043 VkResult result = VK_SUCCESS;
18044 VkImageFormatProperties formatProps;
18045 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
18046 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18047 &formatProps);
18048 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18049 return;
18050 }
18051
18052 ASSERT_NO_FATAL_FAILURE(InitState());
18053 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18054 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
18055 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
18056 VkAttachmentDescription att = {};
18057 VkAttachmentReference ref = {};
18058 att.format = depth_stencil_fmt;
18059 att.samples = VK_SAMPLE_COUNT_1_BIT;
18060 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18061 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18062 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18063 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18064 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18065 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18066
18067 VkClearValue clear;
18068 clear.depthStencil.depth = 1.0;
18069 clear.depthStencil.stencil = 0;
18070 ref.attachment = 0;
18071 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18072
18073 VkSubpassDescription subpass = {};
18074 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18075 subpass.flags = 0;
18076 subpass.inputAttachmentCount = 0;
18077 subpass.pInputAttachments = NULL;
18078 subpass.colorAttachmentCount = 0;
18079 subpass.pColorAttachments = NULL;
18080 subpass.pResolveAttachments = NULL;
18081 subpass.pDepthStencilAttachment = &ref;
18082 subpass.preserveAttachmentCount = 0;
18083 subpass.pPreserveAttachments = NULL;
18084
18085 VkRenderPass rp;
18086 VkRenderPassCreateInfo rp_info = {};
18087 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18088 rp_info.attachmentCount = 1;
18089 rp_info.pAttachments = &att;
18090 rp_info.subpassCount = 1;
18091 rp_info.pSubpasses = &subpass;
18092 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18093 ASSERT_VK_SUCCESS(result);
18094
18095 VkImageView *depthView = m_depthStencil->BindInfo();
18096 VkFramebufferCreateInfo fb_info = {};
18097 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18098 fb_info.pNext = NULL;
18099 fb_info.renderPass = rp;
18100 fb_info.attachmentCount = 1;
18101 fb_info.pAttachments = depthView;
18102 fb_info.width = 100;
18103 fb_info.height = 100;
18104 fb_info.layers = 1;
18105 VkFramebuffer fb;
18106 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18107 ASSERT_VK_SUCCESS(result);
18108
18109 VkRenderPassBeginInfo rpbinfo = {};
18110 rpbinfo.clearValueCount = 1;
18111 rpbinfo.pClearValues = &clear;
18112 rpbinfo.pNext = NULL;
18113 rpbinfo.renderPass = rp;
18114 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18115 rpbinfo.renderArea.extent.width = 100;
18116 rpbinfo.renderArea.extent.height = 100;
18117 rpbinfo.renderArea.offset.x = 0;
18118 rpbinfo.renderArea.offset.y = 0;
18119 rpbinfo.framebuffer = fb;
18120
18121 VkFence fence = {};
18122 VkFenceCreateInfo fence_ci = {};
18123 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18124 fence_ci.pNext = nullptr;
18125 fence_ci.flags = 0;
18126 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18127 ASSERT_VK_SUCCESS(result);
18128
18129 m_commandBuffer->BeginCommandBuffer();
18130 m_commandBuffer->BeginRenderPass(rpbinfo);
18131 m_commandBuffer->EndRenderPass();
18132 m_commandBuffer->EndCommandBuffer();
18133 m_commandBuffer->QueueCommandBuffer(fence);
18134
18135 VkImageObj destImage(m_device);
18136 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
18137 VK_IMAGE_TILING_OPTIMAL, 0);
18138 VkImageMemoryBarrier barrier = {};
18139 VkImageSubresourceRange range;
18140 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18141 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18142 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18143 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18144 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18145 barrier.image = m_depthStencil->handle();
18146 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18147 range.baseMipLevel = 0;
18148 range.levelCount = 1;
18149 range.baseArrayLayer = 0;
18150 range.layerCount = 1;
18151 barrier.subresourceRange = range;
18152 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18153 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18154 cmdbuf.BeginCommandBuffer();
18155 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18156 &barrier);
18157 barrier.srcAccessMask = 0;
18158 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18159 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18160 barrier.image = destImage.handle();
18161 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18162 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
18163 &barrier);
18164 VkImageCopy cregion;
18165 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18166 cregion.srcSubresource.mipLevel = 0;
18167 cregion.srcSubresource.baseArrayLayer = 0;
18168 cregion.srcSubresource.layerCount = 1;
18169 cregion.srcOffset.x = 0;
18170 cregion.srcOffset.y = 0;
18171 cregion.srcOffset.z = 0;
18172 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18173 cregion.dstSubresource.mipLevel = 0;
18174 cregion.dstSubresource.baseArrayLayer = 0;
18175 cregion.dstSubresource.layerCount = 1;
18176 cregion.dstOffset.x = 0;
18177 cregion.dstOffset.y = 0;
18178 cregion.dstOffset.z = 0;
18179 cregion.extent.width = 100;
18180 cregion.extent.height = 100;
18181 cregion.extent.depth = 1;
18182 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
18183 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
18184 cmdbuf.EndCommandBuffer();
18185
18186 VkSubmitInfo submit_info;
18187 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18188 submit_info.pNext = NULL;
18189 submit_info.waitSemaphoreCount = 0;
18190 submit_info.pWaitSemaphores = NULL;
18191 submit_info.pWaitDstStageMask = NULL;
18192 submit_info.commandBufferCount = 1;
18193 submit_info.pCommandBuffers = &cmdbuf.handle();
18194 submit_info.signalSemaphoreCount = 0;
18195 submit_info.pSignalSemaphores = NULL;
18196
18197 m_errorMonitor->ExpectSuccess();
18198 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18199 m_errorMonitor->VerifyNotFound();
18200
18201 vkQueueWaitIdle(m_device->m_queue);
18202 vkDestroyFence(m_device->device(), fence, nullptr);
18203 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18204 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18205}
18206
18207// This is a positive test. No errors should be generated.
18208TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18209 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18210
18211 m_errorMonitor->ExpectSuccess();
18212 ASSERT_NO_FATAL_FAILURE(InitState());
18213
18214 VkEvent event;
18215 VkEventCreateInfo event_create_info{};
18216 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18217 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18218
18219 VkCommandPool command_pool;
18220 VkCommandPoolCreateInfo pool_create_info{};
18221 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18222 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18223 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18224 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18225
18226 VkCommandBuffer command_buffer;
18227 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18228 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18229 command_buffer_allocate_info.commandPool = command_pool;
18230 command_buffer_allocate_info.commandBufferCount = 1;
18231 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18232 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18233
18234 VkQueue queue = VK_NULL_HANDLE;
18235 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18236
18237 {
18238 VkCommandBufferBeginInfo begin_info{};
18239 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18240 vkBeginCommandBuffer(command_buffer, &begin_info);
18241
18242 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
18243 nullptr, 0, nullptr);
18244 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18245 vkEndCommandBuffer(command_buffer);
18246 }
18247 {
18248 VkSubmitInfo submit_info{};
18249 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18250 submit_info.commandBufferCount = 1;
18251 submit_info.pCommandBuffers = &command_buffer;
18252 submit_info.signalSemaphoreCount = 0;
18253 submit_info.pSignalSemaphores = nullptr;
18254 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18255 }
18256 { vkSetEvent(m_device->device(), event); }
18257
18258 vkQueueWaitIdle(queue);
18259
18260 vkDestroyEvent(m_device->device(), event, nullptr);
18261 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18262 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18263
18264 m_errorMonitor->VerifyNotFound();
18265}
18266// This is a positive test. No errors should be generated.
18267TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18268 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18269
18270 ASSERT_NO_FATAL_FAILURE(InitState());
18271 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18272 return;
18273
18274 m_errorMonitor->ExpectSuccess();
18275
18276 VkQueryPool query_pool;
18277 VkQueryPoolCreateInfo query_pool_create_info{};
18278 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18279 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18280 query_pool_create_info.queryCount = 1;
18281 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18282
18283 VkCommandPool command_pool;
18284 VkCommandPoolCreateInfo pool_create_info{};
18285 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18286 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18287 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18288 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18289
18290 VkCommandBuffer command_buffer;
18291 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18292 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18293 command_buffer_allocate_info.commandPool = command_pool;
18294 command_buffer_allocate_info.commandBufferCount = 1;
18295 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18296 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18297
18298 VkCommandBuffer secondary_command_buffer;
18299 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18300 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18301
18302 VkQueue queue = VK_NULL_HANDLE;
18303 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18304
18305 uint32_t qfi = 0;
18306 VkBufferCreateInfo buff_create_info = {};
18307 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18308 buff_create_info.size = 1024;
18309 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18310 buff_create_info.queueFamilyIndexCount = 1;
18311 buff_create_info.pQueueFamilyIndices = &qfi;
18312
18313 VkResult err;
18314 VkBuffer buffer;
18315 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18316 ASSERT_VK_SUCCESS(err);
18317 VkMemoryAllocateInfo mem_alloc = {};
18318 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18319 mem_alloc.pNext = NULL;
18320 mem_alloc.allocationSize = 1024;
18321 mem_alloc.memoryTypeIndex = 0;
18322
18323 VkMemoryRequirements memReqs;
18324 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18325 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18326 if (!pass) {
18327 vkDestroyBuffer(m_device->device(), buffer, NULL);
18328 return;
18329 }
18330
18331 VkDeviceMemory mem;
18332 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18333 ASSERT_VK_SUCCESS(err);
18334 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18335 ASSERT_VK_SUCCESS(err);
18336
18337 VkCommandBufferInheritanceInfo hinfo = {};
18338 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18339 hinfo.renderPass = VK_NULL_HANDLE;
18340 hinfo.subpass = 0;
18341 hinfo.framebuffer = VK_NULL_HANDLE;
18342 hinfo.occlusionQueryEnable = VK_FALSE;
18343 hinfo.queryFlags = 0;
18344 hinfo.pipelineStatistics = 0;
18345
18346 {
18347 VkCommandBufferBeginInfo begin_info{};
18348 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18349 begin_info.pInheritanceInfo = &hinfo;
18350 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18351
18352 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18353 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18354
18355 vkEndCommandBuffer(secondary_command_buffer);
18356
18357 begin_info.pInheritanceInfo = nullptr;
18358 vkBeginCommandBuffer(command_buffer, &begin_info);
18359
18360 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18361 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18362
18363 vkEndCommandBuffer(command_buffer);
18364 }
18365 {
18366 VkSubmitInfo submit_info{};
18367 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18368 submit_info.commandBufferCount = 1;
18369 submit_info.pCommandBuffers = &command_buffer;
18370 submit_info.signalSemaphoreCount = 0;
18371 submit_info.pSignalSemaphores = nullptr;
18372 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18373 }
18374
18375 vkQueueWaitIdle(queue);
18376
18377 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18378 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18379 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18380 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18381 vkDestroyBuffer(m_device->device(), buffer, NULL);
18382 vkFreeMemory(m_device->device(), mem, NULL);
18383
18384 m_errorMonitor->VerifyNotFound();
18385}
18386
18387// This is a positive test. No errors should be generated.
18388TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18389 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18390
18391 ASSERT_NO_FATAL_FAILURE(InitState());
18392 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18393 return;
18394
18395 m_errorMonitor->ExpectSuccess();
18396
18397 VkQueryPool query_pool;
18398 VkQueryPoolCreateInfo query_pool_create_info{};
18399 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18400 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18401 query_pool_create_info.queryCount = 1;
18402 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18403
18404 VkCommandPool command_pool;
18405 VkCommandPoolCreateInfo pool_create_info{};
18406 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18407 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18408 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18409 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18410
18411 VkCommandBuffer command_buffer[2];
18412 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18413 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18414 command_buffer_allocate_info.commandPool = command_pool;
18415 command_buffer_allocate_info.commandBufferCount = 2;
18416 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18417 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18418
18419 VkQueue queue = VK_NULL_HANDLE;
18420 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18421
18422 uint32_t qfi = 0;
18423 VkBufferCreateInfo buff_create_info = {};
18424 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18425 buff_create_info.size = 1024;
18426 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18427 buff_create_info.queueFamilyIndexCount = 1;
18428 buff_create_info.pQueueFamilyIndices = &qfi;
18429
18430 VkResult err;
18431 VkBuffer buffer;
18432 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18433 ASSERT_VK_SUCCESS(err);
18434 VkMemoryAllocateInfo mem_alloc = {};
18435 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18436 mem_alloc.pNext = NULL;
18437 mem_alloc.allocationSize = 1024;
18438 mem_alloc.memoryTypeIndex = 0;
18439
18440 VkMemoryRequirements memReqs;
18441 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18442 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18443 if (!pass) {
18444 vkDestroyBuffer(m_device->device(), buffer, NULL);
18445 return;
18446 }
18447
18448 VkDeviceMemory mem;
18449 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18450 ASSERT_VK_SUCCESS(err);
18451 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18452 ASSERT_VK_SUCCESS(err);
18453
18454 {
18455 VkCommandBufferBeginInfo begin_info{};
18456 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18457 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18458
18459 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
18460 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18461
18462 vkEndCommandBuffer(command_buffer[0]);
18463
18464 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18465
18466 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
18467
18468 vkEndCommandBuffer(command_buffer[1]);
18469 }
18470 {
18471 VkSubmitInfo submit_info{};
18472 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18473 submit_info.commandBufferCount = 2;
18474 submit_info.pCommandBuffers = command_buffer;
18475 submit_info.signalSemaphoreCount = 0;
18476 submit_info.pSignalSemaphores = nullptr;
18477 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18478 }
18479
18480 vkQueueWaitIdle(queue);
18481
18482 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18483 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
18484 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18485 vkDestroyBuffer(m_device->device(), buffer, NULL);
18486 vkFreeMemory(m_device->device(), mem, NULL);
18487
18488 m_errorMonitor->VerifyNotFound();
18489}
18490
Tony Barbourc46924f2016-11-04 11:49:52 -060018491TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018492 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
18493
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018494 ASSERT_NO_FATAL_FAILURE(InitState());
18495 VkEvent event;
18496 VkEventCreateInfo event_create_info{};
18497 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18498 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18499
18500 VkCommandPool command_pool;
18501 VkCommandPoolCreateInfo pool_create_info{};
18502 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18503 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18504 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18505 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18506
18507 VkCommandBuffer command_buffer;
18508 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18509 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18510 command_buffer_allocate_info.commandPool = command_pool;
18511 command_buffer_allocate_info.commandBufferCount = 1;
18512 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18513 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18514
18515 VkQueue queue = VK_NULL_HANDLE;
18516 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18517
18518 {
18519 VkCommandBufferBeginInfo begin_info{};
18520 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18521 vkBeginCommandBuffer(command_buffer, &begin_info);
18522
18523 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018524 vkEndCommandBuffer(command_buffer);
18525 }
18526 {
18527 VkSubmitInfo submit_info{};
18528 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18529 submit_info.commandBufferCount = 1;
18530 submit_info.pCommandBuffers = &command_buffer;
18531 submit_info.signalSemaphoreCount = 0;
18532 submit_info.pSignalSemaphores = nullptr;
18533 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18534 }
18535 {
18536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is already in use by a "
18537 "command buffer.");
18538 vkSetEvent(m_device->device(), event);
18539 m_errorMonitor->VerifyFound();
18540 }
18541
18542 vkQueueWaitIdle(queue);
18543
18544 vkDestroyEvent(m_device->device(), event, nullptr);
18545 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18546 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18547}
18548
18549// This is a positive test. No errors should be generated.
18550TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
18551 TEST_DESCRIPTION("Two command buffers with two separate fences are each "
18552 "run through a Submit & WaitForFences cycle 3 times. This "
18553 "previously revealed a bug so running this positive test "
18554 "to prevent a regression.");
18555 m_errorMonitor->ExpectSuccess();
18556
18557 ASSERT_NO_FATAL_FAILURE(InitState());
18558 VkQueue queue = VK_NULL_HANDLE;
18559 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18560
18561 static const uint32_t NUM_OBJECTS = 2;
18562 static const uint32_t NUM_FRAMES = 3;
18563 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
18564 VkFence fences[NUM_OBJECTS] = {};
18565
18566 VkCommandPool cmd_pool;
18567 VkCommandPoolCreateInfo cmd_pool_ci = {};
18568 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18569 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
18570 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18571 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
18572 ASSERT_VK_SUCCESS(err);
18573
18574 VkCommandBufferAllocateInfo cmd_buf_info = {};
18575 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18576 cmd_buf_info.commandPool = cmd_pool;
18577 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18578 cmd_buf_info.commandBufferCount = 1;
18579
18580 VkFenceCreateInfo fence_ci = {};
18581 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18582 fence_ci.pNext = nullptr;
18583 fence_ci.flags = 0;
18584
18585 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18586 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
18587 ASSERT_VK_SUCCESS(err);
18588 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
18589 ASSERT_VK_SUCCESS(err);
18590 }
18591
18592 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
18593 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
18594 // Create empty cmd buffer
18595 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
18596 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18597
18598 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
18599 ASSERT_VK_SUCCESS(err);
18600 err = vkEndCommandBuffer(cmd_buffers[obj]);
18601 ASSERT_VK_SUCCESS(err);
18602
18603 VkSubmitInfo submit_info = {};
18604 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18605 submit_info.commandBufferCount = 1;
18606 submit_info.pCommandBuffers = &cmd_buffers[obj];
18607 // Submit cmd buffer and wait for fence
18608 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
18609 ASSERT_VK_SUCCESS(err);
18610 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
18611 ASSERT_VK_SUCCESS(err);
18612 err = vkResetFences(m_device->device(), 1, &fences[obj]);
18613 ASSERT_VK_SUCCESS(err);
18614 }
18615 }
18616 m_errorMonitor->VerifyNotFound();
18617 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
18618 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
18619 vkDestroyFence(m_device->device(), fences[i], nullptr);
18620 }
18621}
18622// This is a positive test. No errors should be generated.
18623TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
18624
18625 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18626 "submitted on separate queues followed by a QueueWaitIdle.");
18627
18628 ASSERT_NO_FATAL_FAILURE(InitState());
18629 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18630 return;
18631
18632 m_errorMonitor->ExpectSuccess();
18633
18634 VkSemaphore semaphore;
18635 VkSemaphoreCreateInfo semaphore_create_info{};
18636 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18637 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18638
18639 VkCommandPool command_pool;
18640 VkCommandPoolCreateInfo pool_create_info{};
18641 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18642 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18643 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18644 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18645
18646 VkCommandBuffer command_buffer[2];
18647 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18648 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18649 command_buffer_allocate_info.commandPool = command_pool;
18650 command_buffer_allocate_info.commandBufferCount = 2;
18651 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18652 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18653
18654 VkQueue queue = VK_NULL_HANDLE;
18655 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18656
18657 {
18658 VkCommandBufferBeginInfo begin_info{};
18659 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18660 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18661
18662 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18663 nullptr, 0, nullptr, 0, nullptr);
18664
18665 VkViewport viewport{};
18666 viewport.maxDepth = 1.0f;
18667 viewport.minDepth = 0.0f;
18668 viewport.width = 512;
18669 viewport.height = 512;
18670 viewport.x = 0;
18671 viewport.y = 0;
18672 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18673 vkEndCommandBuffer(command_buffer[0]);
18674 }
18675 {
18676 VkCommandBufferBeginInfo begin_info{};
18677 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18678 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18679
18680 VkViewport viewport{};
18681 viewport.maxDepth = 1.0f;
18682 viewport.minDepth = 0.0f;
18683 viewport.width = 512;
18684 viewport.height = 512;
18685 viewport.x = 0;
18686 viewport.y = 0;
18687 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18688 vkEndCommandBuffer(command_buffer[1]);
18689 }
18690 {
18691 VkSubmitInfo submit_info{};
18692 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18693 submit_info.commandBufferCount = 1;
18694 submit_info.pCommandBuffers = &command_buffer[0];
18695 submit_info.signalSemaphoreCount = 1;
18696 submit_info.pSignalSemaphores = &semaphore;
18697 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18698 }
18699 {
18700 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18701 VkSubmitInfo submit_info{};
18702 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18703 submit_info.commandBufferCount = 1;
18704 submit_info.pCommandBuffers = &command_buffer[1];
18705 submit_info.waitSemaphoreCount = 1;
18706 submit_info.pWaitSemaphores = &semaphore;
18707 submit_info.pWaitDstStageMask = flags;
18708 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18709 }
18710
18711 vkQueueWaitIdle(m_device->m_queue);
18712
18713 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18714 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18715 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18716
18717 m_errorMonitor->VerifyNotFound();
18718}
18719
18720// This is a positive test. No errors should be generated.
18721TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
18722
18723 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18724 "submitted on separate queues, the second having a fence"
18725 "followed by a QueueWaitIdle.");
18726
18727 ASSERT_NO_FATAL_FAILURE(InitState());
18728 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18729 return;
18730
18731 m_errorMonitor->ExpectSuccess();
18732
18733 VkFence fence;
18734 VkFenceCreateInfo fence_create_info{};
18735 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18736 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18737
18738 VkSemaphore semaphore;
18739 VkSemaphoreCreateInfo semaphore_create_info{};
18740 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18741 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18742
18743 VkCommandPool command_pool;
18744 VkCommandPoolCreateInfo pool_create_info{};
18745 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18746 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18747 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18748 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18749
18750 VkCommandBuffer command_buffer[2];
18751 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18752 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18753 command_buffer_allocate_info.commandPool = command_pool;
18754 command_buffer_allocate_info.commandBufferCount = 2;
18755 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18756 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18757
18758 VkQueue queue = VK_NULL_HANDLE;
18759 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18760
18761 {
18762 VkCommandBufferBeginInfo begin_info{};
18763 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18764 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18765
18766 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18767 nullptr, 0, nullptr, 0, nullptr);
18768
18769 VkViewport viewport{};
18770 viewport.maxDepth = 1.0f;
18771 viewport.minDepth = 0.0f;
18772 viewport.width = 512;
18773 viewport.height = 512;
18774 viewport.x = 0;
18775 viewport.y = 0;
18776 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18777 vkEndCommandBuffer(command_buffer[0]);
18778 }
18779 {
18780 VkCommandBufferBeginInfo begin_info{};
18781 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18782 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18783
18784 VkViewport viewport{};
18785 viewport.maxDepth = 1.0f;
18786 viewport.minDepth = 0.0f;
18787 viewport.width = 512;
18788 viewport.height = 512;
18789 viewport.x = 0;
18790 viewport.y = 0;
18791 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18792 vkEndCommandBuffer(command_buffer[1]);
18793 }
18794 {
18795 VkSubmitInfo submit_info{};
18796 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18797 submit_info.commandBufferCount = 1;
18798 submit_info.pCommandBuffers = &command_buffer[0];
18799 submit_info.signalSemaphoreCount = 1;
18800 submit_info.pSignalSemaphores = &semaphore;
18801 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18802 }
18803 {
18804 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18805 VkSubmitInfo submit_info{};
18806 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18807 submit_info.commandBufferCount = 1;
18808 submit_info.pCommandBuffers = &command_buffer[1];
18809 submit_info.waitSemaphoreCount = 1;
18810 submit_info.pWaitSemaphores = &semaphore;
18811 submit_info.pWaitDstStageMask = flags;
18812 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18813 }
18814
18815 vkQueueWaitIdle(m_device->m_queue);
18816
18817 vkDestroyFence(m_device->device(), fence, nullptr);
18818 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18819 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18820 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18821
18822 m_errorMonitor->VerifyNotFound();
18823}
18824
18825// This is a positive test. No errors should be generated.
18826TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
18827
18828 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
18829 "submitted on separate queues, the second having a fence"
18830 "followed by two consecutive WaitForFences calls on the same fence.");
18831
18832 ASSERT_NO_FATAL_FAILURE(InitState());
18833 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
18834 return;
18835
18836 m_errorMonitor->ExpectSuccess();
18837
18838 VkFence fence;
18839 VkFenceCreateInfo fence_create_info{};
18840 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18841 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
18842
18843 VkSemaphore semaphore;
18844 VkSemaphoreCreateInfo semaphore_create_info{};
18845 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18846 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
18847
18848 VkCommandPool command_pool;
18849 VkCommandPoolCreateInfo pool_create_info{};
18850 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18851 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18852 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18853 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18854
18855 VkCommandBuffer command_buffer[2];
18856 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18857 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18858 command_buffer_allocate_info.commandPool = command_pool;
18859 command_buffer_allocate_info.commandBufferCount = 2;
18860 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18861 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18862
18863 VkQueue queue = VK_NULL_HANDLE;
18864 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18865
18866 {
18867 VkCommandBufferBeginInfo begin_info{};
18868 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18869 vkBeginCommandBuffer(command_buffer[0], &begin_info);
18870
18871 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
18872 nullptr, 0, nullptr, 0, nullptr);
18873
18874 VkViewport viewport{};
18875 viewport.maxDepth = 1.0f;
18876 viewport.minDepth = 0.0f;
18877 viewport.width = 512;
18878 viewport.height = 512;
18879 viewport.x = 0;
18880 viewport.y = 0;
18881 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
18882 vkEndCommandBuffer(command_buffer[0]);
18883 }
18884 {
18885 VkCommandBufferBeginInfo begin_info{};
18886 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18887 vkBeginCommandBuffer(command_buffer[1], &begin_info);
18888
18889 VkViewport viewport{};
18890 viewport.maxDepth = 1.0f;
18891 viewport.minDepth = 0.0f;
18892 viewport.width = 512;
18893 viewport.height = 512;
18894 viewport.x = 0;
18895 viewport.y = 0;
18896 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
18897 vkEndCommandBuffer(command_buffer[1]);
18898 }
18899 {
18900 VkSubmitInfo submit_info{};
18901 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18902 submit_info.commandBufferCount = 1;
18903 submit_info.pCommandBuffers = &command_buffer[0];
18904 submit_info.signalSemaphoreCount = 1;
18905 submit_info.pSignalSemaphores = &semaphore;
18906 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18907 }
18908 {
18909 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
18910 VkSubmitInfo submit_info{};
18911 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18912 submit_info.commandBufferCount = 1;
18913 submit_info.pCommandBuffers = &command_buffer[1];
18914 submit_info.waitSemaphoreCount = 1;
18915 submit_info.pWaitSemaphores = &semaphore;
18916 submit_info.pWaitDstStageMask = flags;
18917 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
18918 }
18919
18920 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18921 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18922
18923 vkDestroyFence(m_device->device(), fence, nullptr);
18924 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
18925 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
18926 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18927
18928 m_errorMonitor->VerifyNotFound();
18929}
18930
18931TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
18932
18933 ASSERT_NO_FATAL_FAILURE(InitState());
18934 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
18935 printf("Test requires two queues, skipping\n");
18936 return;
18937 }
18938
18939 VkResult err;
18940
18941 m_errorMonitor->ExpectSuccess();
18942
18943 VkQueue q0 = m_device->m_queue;
18944 VkQueue q1 = nullptr;
18945 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
18946 ASSERT_NE(q1, nullptr);
18947
18948 // An (empty) command buffer. We must have work in the first submission --
18949 // the layer treats unfenced work differently from fenced work.
18950 VkCommandPoolCreateInfo cpci = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0 };
18951 VkCommandPool pool;
18952 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
18953 ASSERT_VK_SUCCESS(err);
18954 VkCommandBufferAllocateInfo cbai = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
18955 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 };
18956 VkCommandBuffer cb;
18957 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
18958 ASSERT_VK_SUCCESS(err);
18959 VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr };
18960 err = vkBeginCommandBuffer(cb, &cbbi);
18961 ASSERT_VK_SUCCESS(err);
18962 err = vkEndCommandBuffer(cb);
18963 ASSERT_VK_SUCCESS(err);
18964
18965 // A semaphore
18966 VkSemaphoreCreateInfo sci = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0 };
18967 VkSemaphore s;
18968 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
18969 ASSERT_VK_SUCCESS(err);
18970
18971 // First submission, to q0
18972 VkSubmitInfo s0 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s };
18973
18974 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
18975 ASSERT_VK_SUCCESS(err);
18976
18977 // Second submission, to q1, waiting on s
18978 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
18979 VkSubmitInfo s1 = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr };
18980
18981 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
18982 ASSERT_VK_SUCCESS(err);
18983
18984 // Wait for q0 idle
18985 err = vkQueueWaitIdle(q0);
18986 ASSERT_VK_SUCCESS(err);
18987
18988 // Command buffer should have been completed (it was on q0); reset the pool.
18989 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
18990
18991 m_errorMonitor->VerifyNotFound();
18992
18993 // Force device completely idle and clean up resources
18994 vkDeviceWaitIdle(m_device->device());
18995 vkDestroyCommandPool(m_device->device(), pool, nullptr);
18996 vkDestroySemaphore(m_device->device(), s, nullptr);
18997}
18998
18999// This is a positive test. No errors should be generated.
19000TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
19001
19002 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19003 "submitted on separate queues, the second having a fence, "
19004 "followed by a WaitForFences call.");
19005
19006 ASSERT_NO_FATAL_FAILURE(InitState());
19007 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2))
19008 return;
19009
19010 m_errorMonitor->ExpectSuccess();
19011
19012 ASSERT_NO_FATAL_FAILURE(InitState());
19013 VkFence fence;
19014 VkFenceCreateInfo fence_create_info{};
19015 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19016 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19017
19018 VkSemaphore semaphore;
19019 VkSemaphoreCreateInfo semaphore_create_info{};
19020 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19021 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19022
19023 VkCommandPool command_pool;
19024 VkCommandPoolCreateInfo pool_create_info{};
19025 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19026 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19027 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19028 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19029
19030 VkCommandBuffer command_buffer[2];
19031 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19032 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19033 command_buffer_allocate_info.commandPool = command_pool;
19034 command_buffer_allocate_info.commandBufferCount = 2;
19035 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19036 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19037
19038 VkQueue queue = VK_NULL_HANDLE;
19039 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19040
19041 {
19042 VkCommandBufferBeginInfo begin_info{};
19043 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19044 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19045
19046 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19047 nullptr, 0, nullptr, 0, nullptr);
19048
19049 VkViewport viewport{};
19050 viewport.maxDepth = 1.0f;
19051 viewport.minDepth = 0.0f;
19052 viewport.width = 512;
19053 viewport.height = 512;
19054 viewport.x = 0;
19055 viewport.y = 0;
19056 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19057 vkEndCommandBuffer(command_buffer[0]);
19058 }
19059 {
19060 VkCommandBufferBeginInfo begin_info{};
19061 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19062 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19063
19064 VkViewport viewport{};
19065 viewport.maxDepth = 1.0f;
19066 viewport.minDepth = 0.0f;
19067 viewport.width = 512;
19068 viewport.height = 512;
19069 viewport.x = 0;
19070 viewport.y = 0;
19071 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19072 vkEndCommandBuffer(command_buffer[1]);
19073 }
19074 {
19075 VkSubmitInfo submit_info{};
19076 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19077 submit_info.commandBufferCount = 1;
19078 submit_info.pCommandBuffers = &command_buffer[0];
19079 submit_info.signalSemaphoreCount = 1;
19080 submit_info.pSignalSemaphores = &semaphore;
19081 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19082 }
19083 {
19084 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19085 VkSubmitInfo submit_info{};
19086 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19087 submit_info.commandBufferCount = 1;
19088 submit_info.pCommandBuffers = &command_buffer[1];
19089 submit_info.waitSemaphoreCount = 1;
19090 submit_info.pWaitSemaphores = &semaphore;
19091 submit_info.pWaitDstStageMask = flags;
19092 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19093 }
19094
19095 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19096
19097 vkDestroyFence(m_device->device(), fence, nullptr);
19098 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19099 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19100 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19101
19102 m_errorMonitor->VerifyNotFound();
19103}
19104
19105// This is a positive test. No errors should be generated.
19106TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
19107
19108 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19109 "on the same queue, sharing a signal/wait semaphore, the "
19110 "second having a fence, "
19111 "followed by a WaitForFences call.");
19112
19113 m_errorMonitor->ExpectSuccess();
19114
19115 ASSERT_NO_FATAL_FAILURE(InitState());
19116 VkFence fence;
19117 VkFenceCreateInfo fence_create_info{};
19118 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19119 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19120
19121 VkSemaphore semaphore;
19122 VkSemaphoreCreateInfo semaphore_create_info{};
19123 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19124 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19125
19126 VkCommandPool command_pool;
19127 VkCommandPoolCreateInfo pool_create_info{};
19128 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19129 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19130 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19131 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19132
19133 VkCommandBuffer command_buffer[2];
19134 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19135 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19136 command_buffer_allocate_info.commandPool = command_pool;
19137 command_buffer_allocate_info.commandBufferCount = 2;
19138 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19139 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19140
19141 {
19142 VkCommandBufferBeginInfo begin_info{};
19143 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19144 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19145
19146 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19147 nullptr, 0, nullptr, 0, nullptr);
19148
19149 VkViewport viewport{};
19150 viewport.maxDepth = 1.0f;
19151 viewport.minDepth = 0.0f;
19152 viewport.width = 512;
19153 viewport.height = 512;
19154 viewport.x = 0;
19155 viewport.y = 0;
19156 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19157 vkEndCommandBuffer(command_buffer[0]);
19158 }
19159 {
19160 VkCommandBufferBeginInfo begin_info{};
19161 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19162 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19163
19164 VkViewport viewport{};
19165 viewport.maxDepth = 1.0f;
19166 viewport.minDepth = 0.0f;
19167 viewport.width = 512;
19168 viewport.height = 512;
19169 viewport.x = 0;
19170 viewport.y = 0;
19171 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19172 vkEndCommandBuffer(command_buffer[1]);
19173 }
19174 {
19175 VkSubmitInfo submit_info{};
19176 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19177 submit_info.commandBufferCount = 1;
19178 submit_info.pCommandBuffers = &command_buffer[0];
19179 submit_info.signalSemaphoreCount = 1;
19180 submit_info.pSignalSemaphores = &semaphore;
19181 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19182 }
19183 {
19184 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19185 VkSubmitInfo submit_info{};
19186 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19187 submit_info.commandBufferCount = 1;
19188 submit_info.pCommandBuffers = &command_buffer[1];
19189 submit_info.waitSemaphoreCount = 1;
19190 submit_info.pWaitSemaphores = &semaphore;
19191 submit_info.pWaitDstStageMask = flags;
19192 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19193 }
19194
19195 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19196
19197 vkDestroyFence(m_device->device(), fence, nullptr);
19198 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19199 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19200 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19201
19202 m_errorMonitor->VerifyNotFound();
19203}
19204
19205// This is a positive test. No errors should be generated.
19206TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
19207
19208 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19209 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19210 "SubmitInfos but with a fence, followed by a WaitForFences call.");
19211
19212 m_errorMonitor->ExpectSuccess();
19213
19214 ASSERT_NO_FATAL_FAILURE(InitState());
19215 VkFence fence;
19216 VkFenceCreateInfo fence_create_info{};
19217 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19218 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19219
19220 VkCommandPool command_pool;
19221 VkCommandPoolCreateInfo pool_create_info{};
19222 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19223 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19224 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19225 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19226
19227 VkCommandBuffer command_buffer[2];
19228 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19229 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19230 command_buffer_allocate_info.commandPool = command_pool;
19231 command_buffer_allocate_info.commandBufferCount = 2;
19232 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19233 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19234
19235 {
19236 VkCommandBufferBeginInfo begin_info{};
19237 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19238 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19239
19240 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19241 nullptr, 0, nullptr, 0, nullptr);
19242
19243 VkViewport viewport{};
19244 viewport.maxDepth = 1.0f;
19245 viewport.minDepth = 0.0f;
19246 viewport.width = 512;
19247 viewport.height = 512;
19248 viewport.x = 0;
19249 viewport.y = 0;
19250 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19251 vkEndCommandBuffer(command_buffer[0]);
19252 }
19253 {
19254 VkCommandBufferBeginInfo begin_info{};
19255 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19256 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19257
19258 VkViewport viewport{};
19259 viewport.maxDepth = 1.0f;
19260 viewport.minDepth = 0.0f;
19261 viewport.width = 512;
19262 viewport.height = 512;
19263 viewport.x = 0;
19264 viewport.y = 0;
19265 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19266 vkEndCommandBuffer(command_buffer[1]);
19267 }
19268 {
19269 VkSubmitInfo submit_info{};
19270 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19271 submit_info.commandBufferCount = 1;
19272 submit_info.pCommandBuffers = &command_buffer[0];
19273 submit_info.signalSemaphoreCount = 0;
19274 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19275 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19276 }
19277 {
19278 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19279 VkSubmitInfo submit_info{};
19280 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19281 submit_info.commandBufferCount = 1;
19282 submit_info.pCommandBuffers = &command_buffer[1];
19283 submit_info.waitSemaphoreCount = 0;
19284 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19285 submit_info.pWaitDstStageMask = flags;
19286 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19287 }
19288
19289 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19290
19291 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19292 ASSERT_VK_SUCCESS(err);
19293
19294 vkDestroyFence(m_device->device(), fence, nullptr);
19295 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19296 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19297
19298 m_errorMonitor->VerifyNotFound();
19299}
19300
19301// This is a positive test. No errors should be generated.
19302TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
19303
19304 TEST_DESCRIPTION("Two command buffers, each in a separate QueueSubmit call "
19305 "on the same queue, the second having a fence, followed "
19306 "by a WaitForFences call.");
19307
19308 m_errorMonitor->ExpectSuccess();
19309
19310 ASSERT_NO_FATAL_FAILURE(InitState());
19311 VkFence fence;
19312 VkFenceCreateInfo fence_create_info{};
19313 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19314 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19315
19316 VkCommandPool command_pool;
19317 VkCommandPoolCreateInfo pool_create_info{};
19318 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19319 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19320 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19321 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19322
19323 VkCommandBuffer command_buffer[2];
19324 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19325 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19326 command_buffer_allocate_info.commandPool = command_pool;
19327 command_buffer_allocate_info.commandBufferCount = 2;
19328 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19329 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19330
19331 {
19332 VkCommandBufferBeginInfo begin_info{};
19333 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19334 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19335
19336 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19337 nullptr, 0, nullptr, 0, nullptr);
19338
19339 VkViewport viewport{};
19340 viewport.maxDepth = 1.0f;
19341 viewport.minDepth = 0.0f;
19342 viewport.width = 512;
19343 viewport.height = 512;
19344 viewport.x = 0;
19345 viewport.y = 0;
19346 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19347 vkEndCommandBuffer(command_buffer[0]);
19348 }
19349 {
19350 VkCommandBufferBeginInfo begin_info{};
19351 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19352 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19353
19354 VkViewport viewport{};
19355 viewport.maxDepth = 1.0f;
19356 viewport.minDepth = 0.0f;
19357 viewport.width = 512;
19358 viewport.height = 512;
19359 viewport.x = 0;
19360 viewport.y = 0;
19361 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19362 vkEndCommandBuffer(command_buffer[1]);
19363 }
19364 {
19365 VkSubmitInfo submit_info{};
19366 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19367 submit_info.commandBufferCount = 1;
19368 submit_info.pCommandBuffers = &command_buffer[0];
19369 submit_info.signalSemaphoreCount = 0;
19370 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19371 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19372 }
19373 {
19374 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19375 VkSubmitInfo submit_info{};
19376 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19377 submit_info.commandBufferCount = 1;
19378 submit_info.pCommandBuffers = &command_buffer[1];
19379 submit_info.waitSemaphoreCount = 0;
19380 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19381 submit_info.pWaitDstStageMask = flags;
19382 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19383 }
19384
19385 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19386
19387 vkDestroyFence(m_device->device(), fence, nullptr);
19388 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19389 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19390
19391 m_errorMonitor->VerifyNotFound();
19392}
19393
19394// This is a positive test. No errors should be generated.
19395TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
19396
19397 TEST_DESCRIPTION("Two command buffers each in a separate SubmitInfo sent in a single "
19398 "QueueSubmit call followed by a WaitForFences call.");
19399 ASSERT_NO_FATAL_FAILURE(InitState());
19400
19401 m_errorMonitor->ExpectSuccess();
19402
19403 VkFence fence;
19404 VkFenceCreateInfo fence_create_info{};
19405 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19406 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19407
19408 VkSemaphore semaphore;
19409 VkSemaphoreCreateInfo semaphore_create_info{};
19410 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19411 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19412
19413 VkCommandPool command_pool;
19414 VkCommandPoolCreateInfo pool_create_info{};
19415 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19416 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19417 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19418 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19419
19420 VkCommandBuffer command_buffer[2];
19421 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19422 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19423 command_buffer_allocate_info.commandPool = command_pool;
19424 command_buffer_allocate_info.commandBufferCount = 2;
19425 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19426 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19427
19428 {
19429 VkCommandBufferBeginInfo begin_info{};
19430 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19431 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19432
19433 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
19434 nullptr, 0, nullptr, 0, nullptr);
19435
19436 VkViewport viewport{};
19437 viewport.maxDepth = 1.0f;
19438 viewport.minDepth = 0.0f;
19439 viewport.width = 512;
19440 viewport.height = 512;
19441 viewport.x = 0;
19442 viewport.y = 0;
19443 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19444 vkEndCommandBuffer(command_buffer[0]);
19445 }
19446 {
19447 VkCommandBufferBeginInfo begin_info{};
19448 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19449 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19450
19451 VkViewport viewport{};
19452 viewport.maxDepth = 1.0f;
19453 viewport.minDepth = 0.0f;
19454 viewport.width = 512;
19455 viewport.height = 512;
19456 viewport.x = 0;
19457 viewport.y = 0;
19458 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19459 vkEndCommandBuffer(command_buffer[1]);
19460 }
19461 {
19462 VkSubmitInfo submit_info[2];
19463 VkPipelineStageFlags flags[]{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT };
19464
19465 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19466 submit_info[0].pNext = NULL;
19467 submit_info[0].commandBufferCount = 1;
19468 submit_info[0].pCommandBuffers = &command_buffer[0];
19469 submit_info[0].signalSemaphoreCount = 1;
19470 submit_info[0].pSignalSemaphores = &semaphore;
19471 submit_info[0].waitSemaphoreCount = 0;
19472 submit_info[0].pWaitSemaphores = NULL;
19473 submit_info[0].pWaitDstStageMask = 0;
19474
19475 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19476 submit_info[1].pNext = NULL;
19477 submit_info[1].commandBufferCount = 1;
19478 submit_info[1].pCommandBuffers = &command_buffer[1];
19479 submit_info[1].waitSemaphoreCount = 1;
19480 submit_info[1].pWaitSemaphores = &semaphore;
19481 submit_info[1].pWaitDstStageMask = flags;
19482 submit_info[1].signalSemaphoreCount = 0;
19483 submit_info[1].pSignalSemaphores = NULL;
19484 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
19485 }
19486
19487 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19488
19489 vkDestroyFence(m_device->device(), fence, nullptr);
19490 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19491 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19492 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19493
19494 m_errorMonitor->VerifyNotFound();
19495}
19496
19497TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
19498 m_errorMonitor->ExpectSuccess();
19499
19500 ASSERT_NO_FATAL_FAILURE(InitState());
19501 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19502
Tony Barbour552f6c02016-12-21 14:34:07 -070019503 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019504
19505 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
19506 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19507 m_errorMonitor->VerifyNotFound();
19508 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
19509 m_errorMonitor->VerifyNotFound();
19510 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
19511 m_errorMonitor->VerifyNotFound();
19512
19513 m_commandBuffer->EndCommandBuffer();
19514 m_errorMonitor->VerifyNotFound();
19515}
19516
19517TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
19518 TEST_DESCRIPTION("Positive test where we create a renderpass with an "
19519 "attachment that uses LOAD_OP_CLEAR, the first subpass "
19520 "has a valid layout, and a second subpass then uses a "
19521 "valid *READ_ONLY* layout.");
19522 m_errorMonitor->ExpectSuccess();
19523 ASSERT_NO_FATAL_FAILURE(InitState());
19524
19525 VkAttachmentReference attach[2] = {};
19526 attach[0].attachment = 0;
19527 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19528 attach[1].attachment = 0;
19529 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19530 VkSubpassDescription subpasses[2] = {};
19531 // First subpass clears DS attach on load
19532 subpasses[0].pDepthStencilAttachment = &attach[0];
19533 // 2nd subpass reads in DS as input attachment
19534 subpasses[1].inputAttachmentCount = 1;
19535 subpasses[1].pInputAttachments = &attach[1];
19536 VkAttachmentDescription attach_desc = {};
19537 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
19538 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
19539 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
19540 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19541 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19542 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19543 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19544 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
19545 VkRenderPassCreateInfo rpci = {};
19546 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19547 rpci.attachmentCount = 1;
19548 rpci.pAttachments = &attach_desc;
19549 rpci.subpassCount = 2;
19550 rpci.pSubpasses = subpasses;
19551
19552 // Now create RenderPass and verify no errors
19553 VkRenderPass rp;
19554 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
19555 m_errorMonitor->VerifyNotFound();
19556
19557 vkDestroyRenderPass(m_device->device(), rp, NULL);
19558}
19559
19560TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
19561 TEST_DESCRIPTION("Test that pipeline validation accepts matrices passed "
19562 "as vertex attributes");
19563 m_errorMonitor->ExpectSuccess();
19564
19565 ASSERT_NO_FATAL_FAILURE(InitState());
19566 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19567
19568 VkVertexInputBindingDescription input_binding;
19569 memset(&input_binding, 0, sizeof(input_binding));
19570
19571 VkVertexInputAttributeDescription input_attribs[2];
19572 memset(input_attribs, 0, sizeof(input_attribs));
19573
19574 for (int i = 0; i < 2; i++) {
19575 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19576 input_attribs[i].location = i;
19577 }
19578
19579 char const *vsSource = "#version 450\n"
19580 "\n"
19581 "layout(location=0) in mat2x4 x;\n"
19582 "out gl_PerVertex {\n"
19583 " vec4 gl_Position;\n"
19584 "};\n"
19585 "void main(){\n"
19586 " gl_Position = x[0] + x[1];\n"
19587 "}\n";
19588 char const *fsSource = "#version 450\n"
19589 "\n"
19590 "layout(location=0) out vec4 color;\n"
19591 "void main(){\n"
19592 " color = vec4(1);\n"
19593 "}\n";
19594
19595 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19596 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19597
19598 VkPipelineObj pipe(m_device);
19599 pipe.AddColorAttachment();
19600 pipe.AddShader(&vs);
19601 pipe.AddShader(&fs);
19602
19603 pipe.AddVertexInputBindings(&input_binding, 1);
19604 pipe.AddVertexInputAttribs(input_attribs, 2);
19605
19606 VkDescriptorSetObj descriptorSet(m_device);
19607 descriptorSet.AppendDummy();
19608 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19609
19610 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19611
19612 /* expect success */
19613 m_errorMonitor->VerifyNotFound();
19614}
19615
19616TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
19617 m_errorMonitor->ExpectSuccess();
19618
19619 ASSERT_NO_FATAL_FAILURE(InitState());
19620 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19621
19622 VkVertexInputBindingDescription input_binding;
19623 memset(&input_binding, 0, sizeof(input_binding));
19624
19625 VkVertexInputAttributeDescription input_attribs[2];
19626 memset(input_attribs, 0, sizeof(input_attribs));
19627
19628 for (int i = 0; i < 2; i++) {
19629 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19630 input_attribs[i].location = i;
19631 }
19632
19633 char const *vsSource = "#version 450\n"
19634 "\n"
19635 "layout(location=0) in vec4 x[2];\n"
19636 "out gl_PerVertex {\n"
19637 " vec4 gl_Position;\n"
19638 "};\n"
19639 "void main(){\n"
19640 " gl_Position = x[0] + x[1];\n"
19641 "}\n";
19642 char const *fsSource = "#version 450\n"
19643 "\n"
19644 "layout(location=0) out vec4 color;\n"
19645 "void main(){\n"
19646 " color = vec4(1);\n"
19647 "}\n";
19648
19649 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19650 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19651
19652 VkPipelineObj pipe(m_device);
19653 pipe.AddColorAttachment();
19654 pipe.AddShader(&vs);
19655 pipe.AddShader(&fs);
19656
19657 pipe.AddVertexInputBindings(&input_binding, 1);
19658 pipe.AddVertexInputAttribs(input_attribs, 2);
19659
19660 VkDescriptorSetObj descriptorSet(m_device);
19661 descriptorSet.AppendDummy();
19662 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19663
19664 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19665
19666 m_errorMonitor->VerifyNotFound();
19667}
19668
19669TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
19670 TEST_DESCRIPTION("Test that pipeline validation accepts consuming a vertex attribute "
19671 "through multiple vertex shader inputs, each consuming a different "
19672 "subset of the components.");
19673 m_errorMonitor->ExpectSuccess();
19674
19675 ASSERT_NO_FATAL_FAILURE(InitState());
19676 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19677
19678 VkVertexInputBindingDescription input_binding;
19679 memset(&input_binding, 0, sizeof(input_binding));
19680
19681 VkVertexInputAttributeDescription input_attribs[3];
19682 memset(input_attribs, 0, sizeof(input_attribs));
19683
19684 for (int i = 0; i < 3; i++) {
19685 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
19686 input_attribs[i].location = i;
19687 }
19688
19689 char const *vsSource = "#version 450\n"
19690 "\n"
19691 "layout(location=0) in vec4 x;\n"
19692 "layout(location=1) in vec3 y1;\n"
19693 "layout(location=1, component=3) in float y2;\n"
19694 "layout(location=2) in vec4 z;\n"
19695 "out gl_PerVertex {\n"
19696 " vec4 gl_Position;\n"
19697 "};\n"
19698 "void main(){\n"
19699 " gl_Position = x + vec4(y1, y2) + z;\n"
19700 "}\n";
19701 char const *fsSource = "#version 450\n"
19702 "\n"
19703 "layout(location=0) out vec4 color;\n"
19704 "void main(){\n"
19705 " color = vec4(1);\n"
19706 "}\n";
19707
19708 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19709 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19710
19711 VkPipelineObj pipe(m_device);
19712 pipe.AddColorAttachment();
19713 pipe.AddShader(&vs);
19714 pipe.AddShader(&fs);
19715
19716 pipe.AddVertexInputBindings(&input_binding, 1);
19717 pipe.AddVertexInputAttribs(input_attribs, 3);
19718
19719 VkDescriptorSetObj descriptorSet(m_device);
19720 descriptorSet.AppendDummy();
19721 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19722
19723 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19724
19725 m_errorMonitor->VerifyNotFound();
19726}
19727
19728TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
19729 m_errorMonitor->ExpectSuccess();
19730
19731 ASSERT_NO_FATAL_FAILURE(InitState());
19732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19733
19734 char const *vsSource = "#version 450\n"
19735 "out gl_PerVertex {\n"
19736 " vec4 gl_Position;\n"
19737 "};\n"
19738 "void main(){\n"
19739 " gl_Position = vec4(0);\n"
19740 "}\n";
19741 char const *fsSource = "#version 450\n"
19742 "\n"
19743 "layout(location=0) out vec4 color;\n"
19744 "void main(){\n"
19745 " color = vec4(1);\n"
19746 "}\n";
19747
19748 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19749 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19750
19751 VkPipelineObj pipe(m_device);
19752 pipe.AddColorAttachment();
19753 pipe.AddShader(&vs);
19754 pipe.AddShader(&fs);
19755
19756 VkDescriptorSetObj descriptorSet(m_device);
19757 descriptorSet.AppendDummy();
19758 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19759
19760 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19761
19762 m_errorMonitor->VerifyNotFound();
19763}
19764
19765TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
19766 TEST_DESCRIPTION("Test that pipeline validation accepts the relaxed type matching rules "
19767 "set out in 14.1.3: fundamental type must match, and producer side must "
19768 "have at least as many components");
19769 m_errorMonitor->ExpectSuccess();
19770
19771 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
19772
19773 ASSERT_NO_FATAL_FAILURE(InitState());
19774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19775
19776 char const *vsSource = "#version 450\n"
19777 "out gl_PerVertex {\n"
19778 " vec4 gl_Position;\n"
19779 "};\n"
19780 "layout(location=0) out vec3 x;\n"
19781 "layout(location=1) out ivec3 y;\n"
19782 "layout(location=2) out vec3 z;\n"
19783 "void main(){\n"
19784 " gl_Position = vec4(0);\n"
19785 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
19786 "}\n";
19787 char const *fsSource = "#version 450\n"
19788 "\n"
19789 "layout(location=0) out vec4 color;\n"
19790 "layout(location=0) in float x;\n"
19791 "layout(location=1) flat in int y;\n"
19792 "layout(location=2) in vec2 z;\n"
19793 "void main(){\n"
19794 " color = vec4(1 + x + y + z.x);\n"
19795 "}\n";
19796
19797 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19798 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19799
19800 VkPipelineObj pipe(m_device);
19801 pipe.AddColorAttachment();
19802 pipe.AddShader(&vs);
19803 pipe.AddShader(&fs);
19804
19805 VkDescriptorSetObj descriptorSet(m_device);
19806 descriptorSet.AppendDummy();
19807 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19808
19809 VkResult err = VK_SUCCESS;
19810 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19811 ASSERT_VK_SUCCESS(err);
19812
19813 m_errorMonitor->VerifyNotFound();
19814}
19815
19816TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
19817 TEST_DESCRIPTION("Test that pipeline validation accepts per-vertex variables "
19818 "passed between the TCS and TES stages");
19819 m_errorMonitor->ExpectSuccess();
19820
19821 ASSERT_NO_FATAL_FAILURE(InitState());
19822 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19823
19824 if (!m_device->phy().features().tessellationShader) {
19825 printf("Device does not support tessellation shaders; skipped.\n");
19826 return;
19827 }
19828
19829 char const *vsSource = "#version 450\n"
19830 "void main(){}\n";
19831 char const *tcsSource = "#version 450\n"
19832 "layout(location=0) out int x[];\n"
19833 "layout(vertices=3) out;\n"
19834 "void main(){\n"
19835 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
19836 " gl_TessLevelInner[0] = 1;\n"
19837 " x[gl_InvocationID] = gl_InvocationID;\n"
19838 "}\n";
19839 char const *tesSource = "#version 450\n"
19840 "layout(triangles, equal_spacing, cw) in;\n"
19841 "layout(location=0) in int x[];\n"
19842 "out gl_PerVertex { vec4 gl_Position; };\n"
19843 "void main(){\n"
19844 " gl_Position.xyz = gl_TessCoord;\n"
19845 " gl_Position.w = x[0] + x[1] + x[2];\n"
19846 "}\n";
19847 char const *fsSource = "#version 450\n"
19848 "layout(location=0) out vec4 color;\n"
19849 "void main(){\n"
19850 " color = vec4(1);\n"
19851 "}\n";
19852
19853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19854 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
19855 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
19856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19857
19858 VkPipelineInputAssemblyStateCreateInfo iasci{ VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
19859 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE };
19860
19861 VkPipelineTessellationStateCreateInfo tsci{ VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3 };
19862
19863 VkPipelineObj pipe(m_device);
19864 pipe.SetInputAssembly(&iasci);
19865 pipe.SetTessellation(&tsci);
19866 pipe.AddColorAttachment();
19867 pipe.AddShader(&vs);
19868 pipe.AddShader(&tcs);
19869 pipe.AddShader(&tes);
19870 pipe.AddShader(&fs);
19871
19872 VkDescriptorSetObj descriptorSet(m_device);
19873 descriptorSet.AppendDummy();
19874 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19875
19876 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19877
19878 m_errorMonitor->VerifyNotFound();
19879}
19880
19881TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
19882 TEST_DESCRIPTION("Test that pipeline validation accepts a user-defined "
19883 "interface block passed into the geometry shader. This "
19884 "is interesting because the 'extra' array level is not "
19885 "present on the member type, but on the block instance.");
19886 m_errorMonitor->ExpectSuccess();
19887
19888 ASSERT_NO_FATAL_FAILURE(InitState());
19889 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19890
19891 if (!m_device->phy().features().geometryShader) {
19892 printf("Device does not support geometry shaders; skipped.\n");
19893 return;
19894 }
19895
19896 char const *vsSource = "#version 450\n"
19897 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
19898 "void main(){\n"
19899 " vs_out.x = vec4(1);\n"
19900 "}\n";
19901 char const *gsSource = "#version 450\n"
19902 "layout(triangles) in;\n"
19903 "layout(triangle_strip, max_vertices=3) out;\n"
19904 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
19905 "out gl_PerVertex { vec4 gl_Position; };\n"
19906 "void main() {\n"
19907 " gl_Position = gs_in[0].x;\n"
19908 " EmitVertex();\n"
19909 "}\n";
19910 char const *fsSource = "#version 450\n"
19911 "layout(location=0) out vec4 color;\n"
19912 "void main(){\n"
19913 " color = vec4(1);\n"
19914 "}\n";
19915
19916 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19917 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
19918 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19919
19920 VkPipelineObj pipe(m_device);
19921 pipe.AddColorAttachment();
19922 pipe.AddShader(&vs);
19923 pipe.AddShader(&gs);
19924 pipe.AddShader(&fs);
19925
19926 VkDescriptorSetObj descriptorSet(m_device);
19927 descriptorSet.AppendDummy();
19928 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19929
19930 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19931
19932 m_errorMonitor->VerifyNotFound();
19933}
19934
19935TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
19936 TEST_DESCRIPTION("Test that pipeline validation accepts basic use of 64bit vertex "
19937 "attributes. This is interesting because they consume multiple "
19938 "locations.");
19939 m_errorMonitor->ExpectSuccess();
19940
19941 ASSERT_NO_FATAL_FAILURE(InitState());
19942 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19943
19944 if (!m_device->phy().features().shaderFloat64) {
19945 printf("Device does not support 64bit vertex attributes; skipped.\n");
19946 return;
19947 }
19948
19949 VkVertexInputBindingDescription input_bindings[1];
19950 memset(input_bindings, 0, sizeof(input_bindings));
19951
19952 VkVertexInputAttributeDescription input_attribs[4];
19953 memset(input_attribs, 0, sizeof(input_attribs));
19954 input_attribs[0].location = 0;
19955 input_attribs[0].offset = 0;
19956 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19957 input_attribs[1].location = 2;
19958 input_attribs[1].offset = 32;
19959 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19960 input_attribs[2].location = 4;
19961 input_attribs[2].offset = 64;
19962 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19963 input_attribs[3].location = 6;
19964 input_attribs[3].offset = 96;
19965 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
19966
19967 char const *vsSource = "#version 450\n"
19968 "\n"
19969 "layout(location=0) in dmat4 x;\n"
19970 "out gl_PerVertex {\n"
19971 " vec4 gl_Position;\n"
19972 "};\n"
19973 "void main(){\n"
19974 " gl_Position = vec4(x[0][0]);\n"
19975 "}\n";
19976 char const *fsSource = "#version 450\n"
19977 "\n"
19978 "layout(location=0) out vec4 color;\n"
19979 "void main(){\n"
19980 " color = vec4(1);\n"
19981 "}\n";
19982
19983 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19984 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19985
19986 VkPipelineObj pipe(m_device);
19987 pipe.AddColorAttachment();
19988 pipe.AddShader(&vs);
19989 pipe.AddShader(&fs);
19990
19991 pipe.AddVertexInputBindings(input_bindings, 1);
19992 pipe.AddVertexInputAttribs(input_attribs, 4);
19993
19994 VkDescriptorSetObj descriptorSet(m_device);
19995 descriptorSet.AppendDummy();
19996 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
19997
19998 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
19999
20000 m_errorMonitor->VerifyNotFound();
20001}
20002
20003TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20004 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20005 m_errorMonitor->ExpectSuccess();
20006
20007 ASSERT_NO_FATAL_FAILURE(InitState());
20008
20009 char const *vsSource = "#version 450\n"
20010 "\n"
20011 "out gl_PerVertex {\n"
20012 " vec4 gl_Position;\n"
20013 "};\n"
20014 "void main(){\n"
20015 " gl_Position = vec4(1);\n"
20016 "}\n";
20017 char const *fsSource = "#version 450\n"
20018 "\n"
20019 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20020 "layout(location=0) out vec4 color;\n"
20021 "void main() {\n"
20022 " color = subpassLoad(x);\n"
20023 "}\n";
20024
20025 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20026 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20027
20028 VkPipelineObj pipe(m_device);
20029 pipe.AddShader(&vs);
20030 pipe.AddShader(&fs);
20031 pipe.AddColorAttachment();
20032 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20033
20034 VkDescriptorSetLayoutBinding dslb = { 0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr };
20035 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb };
20036 VkDescriptorSetLayout dsl;
20037 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20038 ASSERT_VK_SUCCESS(err);
20039
20040 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20041 VkPipelineLayout pl;
20042 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20043 ASSERT_VK_SUCCESS(err);
20044
20045 VkAttachmentDescription descs[2] = {
20046 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20047 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20048 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL },
20049 { 0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20050 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL },
20051 };
20052 VkAttachmentReference color = {
20053 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20054 };
20055 VkAttachmentReference input = {
20056 1, VK_IMAGE_LAYOUT_GENERAL,
20057 };
20058
20059 VkSubpassDescription sd = { 0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr };
20060
20061 VkRenderPassCreateInfo rpci = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr };
20062 VkRenderPass rp;
20063 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20064 ASSERT_VK_SUCCESS(err);
20065
20066 // should be OK. would go wrong here if it's going to...
20067 pipe.CreateVKPipeline(pl, rp);
20068
20069 m_errorMonitor->VerifyNotFound();
20070
20071 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20072 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20073 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20074}
20075
20076TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
20077 TEST_DESCRIPTION("Test that pipeline validation accepts a compute pipeline which declares a "
20078 "descriptor-backed resource which is not provided, but the shader does not "
20079 "statically use it. This is interesting because it requires compute pipelines "
20080 "to have a proper descriptor use walk, which they didn't for some time.");
20081 m_errorMonitor->ExpectSuccess();
20082
20083 ASSERT_NO_FATAL_FAILURE(InitState());
20084
20085 char const *csSource = "#version 450\n"
20086 "\n"
20087 "layout(local_size_x=1) in;\n"
20088 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20089 "void main(){\n"
20090 " // x is not used.\n"
20091 "}\n";
20092
20093 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20094
20095 VkDescriptorSetObj descriptorSet(m_device);
20096 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20097
20098 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20099 nullptr,
20100 0,
20101 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20102 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20103 descriptorSet.GetPipelineLayout(),
20104 VK_NULL_HANDLE,
20105 -1 };
20106
20107 VkPipeline pipe;
20108 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20109
20110 m_errorMonitor->VerifyNotFound();
20111
20112 if (err == VK_SUCCESS) {
20113 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20114 }
20115}
20116
20117TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
20118 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20119 "sampler portion of a combined image + sampler");
20120 m_errorMonitor->ExpectSuccess();
20121
20122 ASSERT_NO_FATAL_FAILURE(InitState());
20123
20124 VkDescriptorSetLayoutBinding bindings[] = {
20125 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20126 { 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20127 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20128 };
20129 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20130 VkDescriptorSetLayout dsl;
20131 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20132 ASSERT_VK_SUCCESS(err);
20133
20134 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20135 VkPipelineLayout pl;
20136 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20137 ASSERT_VK_SUCCESS(err);
20138
20139 char const *csSource = "#version 450\n"
20140 "\n"
20141 "layout(local_size_x=1) in;\n"
20142 "layout(set=0, binding=0) uniform sampler s;\n"
20143 "layout(set=0, binding=1) uniform texture2D t;\n"
20144 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20145 "void main() {\n"
20146 " x = texture(sampler2D(t, s), vec2(0));\n"
20147 "}\n";
20148 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20149
20150 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20151 nullptr,
20152 0,
20153 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20154 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20155 pl,
20156 VK_NULL_HANDLE,
20157 -1 };
20158
20159 VkPipeline pipe;
20160 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20161
20162 m_errorMonitor->VerifyNotFound();
20163
20164 if (err == VK_SUCCESS) {
20165 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20166 }
20167
20168 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20169 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20170}
20171
20172TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
20173 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming only the "
20174 "image portion of a combined image + sampler");
20175 m_errorMonitor->ExpectSuccess();
20176
20177 ASSERT_NO_FATAL_FAILURE(InitState());
20178
20179 VkDescriptorSetLayoutBinding bindings[] = {
20180 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20181 { 1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20182 { 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20183 };
20184 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings };
20185 VkDescriptorSetLayout dsl;
20186 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20187 ASSERT_VK_SUCCESS(err);
20188
20189 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20190 VkPipelineLayout pl;
20191 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20192 ASSERT_VK_SUCCESS(err);
20193
20194 char const *csSource = "#version 450\n"
20195 "\n"
20196 "layout(local_size_x=1) in;\n"
20197 "layout(set=0, binding=0) uniform texture2D t;\n"
20198 "layout(set=0, binding=1) uniform sampler s;\n"
20199 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20200 "void main() {\n"
20201 " x = texture(sampler2D(t, s), vec2(0));\n"
20202 "}\n";
20203 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20204
20205 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20206 nullptr,
20207 0,
20208 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20209 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20210 pl,
20211 VK_NULL_HANDLE,
20212 -1 };
20213
20214 VkPipeline pipe;
20215 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20216
20217 m_errorMonitor->VerifyNotFound();
20218
20219 if (err == VK_SUCCESS) {
20220 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20221 }
20222
20223 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20224 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20225}
20226
20227TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
20228 TEST_DESCRIPTION("Test that pipeline validation accepts a shader consuming "
20229 "both the sampler and the image of a combined image+sampler "
20230 "but via separate variables");
20231 m_errorMonitor->ExpectSuccess();
20232
20233 ASSERT_NO_FATAL_FAILURE(InitState());
20234
20235 VkDescriptorSetLayoutBinding bindings[] = {
20236 { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20237 { 1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr },
20238 };
20239 VkDescriptorSetLayoutCreateInfo dslci = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings };
20240 VkDescriptorSetLayout dsl;
20241 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20242 ASSERT_VK_SUCCESS(err);
20243
20244 VkPipelineLayoutCreateInfo plci = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr };
20245 VkPipelineLayout pl;
20246 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20247 ASSERT_VK_SUCCESS(err);
20248
20249 char const *csSource = "#version 450\n"
20250 "\n"
20251 "layout(local_size_x=1) in;\n"
20252 "layout(set=0, binding=0) uniform texture2D t;\n"
20253 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20254 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20255 "void main() {\n"
20256 " x = texture(sampler2D(t, s), vec2(0));\n"
20257 "}\n";
20258 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20259
20260 VkComputePipelineCreateInfo cpci = { VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20261 nullptr,
20262 0,
20263 { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20264 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr },
20265 pl,
20266 VK_NULL_HANDLE,
20267 -1 };
20268
20269 VkPipeline pipe;
20270 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20271
20272 m_errorMonitor->VerifyNotFound();
20273
20274 if (err == VK_SUCCESS) {
20275 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20276 }
20277
20278 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20279 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20280}
20281
20282TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20283 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20284
20285 ASSERT_NO_FATAL_FAILURE(InitState());
20286
20287 // Positive test to check parameter_validation and unique_objects support
20288 // for NV_dedicated_allocation
20289 uint32_t extension_count = 0;
20290 bool supports_nv_dedicated_allocation = false;
20291 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20292 ASSERT_VK_SUCCESS(err);
20293
20294 if (extension_count > 0) {
20295 std::vector<VkExtensionProperties> available_extensions(extension_count);
20296
20297 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20298 ASSERT_VK_SUCCESS(err);
20299
20300 for (const auto &extension_props : available_extensions) {
20301 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20302 supports_nv_dedicated_allocation = true;
20303 }
20304 }
20305 }
20306
20307 if (supports_nv_dedicated_allocation) {
20308 m_errorMonitor->ExpectSuccess();
20309
20310 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20311 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20312 dedicated_buffer_create_info.pNext = nullptr;
20313 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20314
20315 uint32_t queue_family_index = 0;
20316 VkBufferCreateInfo buffer_create_info = {};
20317 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20318 buffer_create_info.pNext = &dedicated_buffer_create_info;
20319 buffer_create_info.size = 1024;
20320 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20321 buffer_create_info.queueFamilyIndexCount = 1;
20322 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20323
20324 VkBuffer buffer;
20325 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
20326 ASSERT_VK_SUCCESS(err);
20327
20328 VkMemoryRequirements memory_reqs;
20329 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20330
20331 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20332 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20333 dedicated_memory_info.pNext = nullptr;
20334 dedicated_memory_info.buffer = buffer;
20335 dedicated_memory_info.image = VK_NULL_HANDLE;
20336
20337 VkMemoryAllocateInfo memory_info = {};
20338 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20339 memory_info.pNext = &dedicated_memory_info;
20340 memory_info.allocationSize = memory_reqs.size;
20341
20342 bool pass;
20343 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20344 ASSERT_TRUE(pass);
20345
20346 VkDeviceMemory buffer_memory;
20347 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20348 ASSERT_VK_SUCCESS(err);
20349
20350 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20351 ASSERT_VK_SUCCESS(err);
20352
20353 vkDestroyBuffer(m_device->device(), buffer, NULL);
20354 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20355
20356 m_errorMonitor->VerifyNotFound();
20357 }
20358}
20359
20360TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20361 VkResult err;
20362
20363 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20364
20365 ASSERT_NO_FATAL_FAILURE(InitState());
20366 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20367
20368 std::vector<const char *> device_extension_names;
20369 auto features = m_device->phy().features();
20370 // Artificially disable support for non-solid fill modes
20371 features.fillModeNonSolid = false;
20372 // The sacrificial device object
20373 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20374
20375 VkRenderpassObj render_pass(&test_device);
20376
20377 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20378 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20379 pipeline_layout_ci.setLayoutCount = 0;
20380 pipeline_layout_ci.pSetLayouts = NULL;
20381
20382 VkPipelineLayout pipeline_layout;
20383 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20384 ASSERT_VK_SUCCESS(err);
20385
20386 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20387 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20388 rs_ci.pNext = nullptr;
20389 rs_ci.lineWidth = 1.0f;
20390 rs_ci.rasterizerDiscardEnable = true;
20391
20392 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20393 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20394
20395 // Set polygonMode=FILL. No error is expected
20396 m_errorMonitor->ExpectSuccess();
20397 {
20398 VkPipelineObj pipe(&test_device);
20399 pipe.AddShader(&vs);
20400 pipe.AddShader(&fs);
20401 pipe.AddColorAttachment();
20402 // Set polygonMode to a good value
20403 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20404 pipe.SetRasterization(&rs_ci);
20405 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20406 }
20407 m_errorMonitor->VerifyNotFound();
20408
20409 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
20410}
20411
20412TEST_F(VkPositiveLayerTest, ValidPushConstants) {
20413 VkResult err;
20414 ASSERT_NO_FATAL_FAILURE(InitState());
20415 ASSERT_NO_FATAL_FAILURE(InitViewport());
20416 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20417
20418 VkPipelineLayout pipeline_layout;
20419 VkPushConstantRange pc_range = {};
20420 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20421 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20422 pipeline_layout_ci.pushConstantRangeCount = 1;
20423 pipeline_layout_ci.pPushConstantRanges = &pc_range;
20424
20425 //
20426 // Check for invalid push constant ranges in pipeline layouts.
20427 //
20428 struct PipelineLayoutTestCase {
20429 VkPushConstantRange const range;
20430 char const *msg;
20431 };
20432
20433 // Check for overlapping ranges
20434 const uint32_t ranges_per_test = 5;
20435 struct OverlappingRangeTestCase {
20436 VkPushConstantRange const ranges[ranges_per_test];
20437 char const *msg;
20438 };
20439
20440 // Run some positive tests to make sure overlap checking in the layer is OK
20441 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = { { { { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 },
20442 { VK_SHADER_STAGE_VERTEX_BIT, 4, 4 },
20443 { VK_SHADER_STAGE_VERTEX_BIT, 8, 4 },
20444 { VK_SHADER_STAGE_VERTEX_BIT, 12, 4 },
20445 { VK_SHADER_STAGE_VERTEX_BIT, 16, 4 } },
20446 "" },
20447 { { { VK_SHADER_STAGE_VERTEX_BIT, 92, 24 },
20448 { VK_SHADER_STAGE_VERTEX_BIT, 80, 4 },
20449 { VK_SHADER_STAGE_VERTEX_BIT, 64, 8 },
20450 { VK_SHADER_STAGE_VERTEX_BIT, 4, 16 },
20451 { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 } },
20452 "" } } };
20453 for (const auto &iter : overlapping_range_tests_pos) {
20454 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
20455 m_errorMonitor->ExpectSuccess();
20456 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20457 m_errorMonitor->VerifyNotFound();
20458 if (VK_SUCCESS == err) {
20459 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20460 }
20461 }
20462
20463 //
20464 // CmdPushConstants tests
20465 //
20466 const uint8_t dummy_values[100] = {};
20467
Tony Barbour552f6c02016-12-21 14:34:07 -070020468 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020469
20470 // positive overlapping range tests with cmd
20471 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = { {
20472 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 16 }, "" },
20473 { { VK_SHADER_STAGE_VERTEX_BIT, 0, 4 }, "" },
20474 { { VK_SHADER_STAGE_VERTEX_BIT, 20, 12 }, "" },
20475 { { VK_SHADER_STAGE_VERTEX_BIT, 56, 36 }, "" },
20476 } };
20477
20478 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
20479 const VkPushConstantRange pc_range4[] = {
20480 { VK_SHADER_STAGE_VERTEX_BIT, 20, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 0, 16 },{ VK_SHADER_STAGE_VERTEX_BIT, 44, 8 },
20481 { VK_SHADER_STAGE_VERTEX_BIT, 80, 12 },{ VK_SHADER_STAGE_VERTEX_BIT, 36, 8 },{ VK_SHADER_STAGE_VERTEX_BIT, 56, 24 },
20482 };
20483
20484 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
20485 pipeline_layout_ci.pPushConstantRanges = pc_range4;
20486 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20487 ASSERT_VK_SUCCESS(err);
20488 for (const auto &iter : cmd_overlap_tests_pos) {
20489 m_errorMonitor->ExpectSuccess();
20490 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
20491 iter.range.size, dummy_values);
20492 m_errorMonitor->VerifyNotFound();
20493 }
20494 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
20495
Tony Barbour552f6c02016-12-21 14:34:07 -070020496 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020497}
20498
20499
20500
20501
20502
20503
20504
20505#if 0 // A few devices have issues with this test so disabling for now
20506TEST_F(VkPositiveLayerTest, LongFenceChain)
20507{
20508 m_errorMonitor->ExpectSuccess();
20509
20510 ASSERT_NO_FATAL_FAILURE(InitState());
20511 VkResult err;
20512
20513 std::vector<VkFence> fences;
20514
20515 const int chainLength = 32768;
20516
20517 for (int i = 0; i < chainLength; i++) {
20518 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
20519 VkFence fence;
20520 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
20521 ASSERT_VK_SUCCESS(err);
20522
20523 fences.push_back(fence);
20524
20525 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
20526 0, nullptr, 0, nullptr };
20527 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
20528 ASSERT_VK_SUCCESS(err);
20529
20530 }
20531
20532 // BOOM, stack overflow.
20533 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
20534
20535 for (auto fence : fences)
20536 vkDestroyFence(m_device->device(), fence, nullptr);
20537
20538 m_errorMonitor->VerifyNotFound();
20539}
20540#endif
20541
20542
Cody Northrop1242dfd2016-07-13 17:24:59 -060020543#if defined(ANDROID) && defined(VALIDATION_APK)
20544static bool initialized = false;
20545static bool active = false;
20546
20547// Convert Intents to argv
20548// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020549std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020550 std::vector<std::string> args;
20551 JavaVM &vm = *app.activity->vm;
20552 JNIEnv *p_env;
20553 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK)
20554 return args;
20555
20556 JNIEnv &env = *p_env;
20557 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020558 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020559 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020560 jmethodID get_string_extra_method =
20561 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060020562 jvalue get_string_extra_args;
20563 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020564 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060020565
20566 std::string args_str;
20567 if (extra_str) {
20568 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
20569 args_str = extra_utf;
20570 env.ReleaseStringUTFChars(extra_str, extra_utf);
20571 env.DeleteLocalRef(extra_str);
20572 }
20573
20574 env.DeleteLocalRef(get_string_extra_args.l);
20575 env.DeleteLocalRef(intent);
20576 vm.DetachCurrentThread();
20577
20578 // split args_str
20579 std::stringstream ss(args_str);
20580 std::string arg;
20581 while (std::getline(ss, arg, ' ')) {
20582 if (!arg.empty())
20583 args.push_back(arg);
20584 }
20585
20586 return args;
20587}
20588
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020589static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020590
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020591static void processCommand(struct android_app *app, int32_t cmd) {
20592 switch (cmd) {
20593 case APP_CMD_INIT_WINDOW: {
20594 if (app->window) {
20595 initialized = true;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020596 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020597 break;
20598 }
20599 case APP_CMD_GAINED_FOCUS: {
20600 active = true;
20601 break;
20602 }
20603 case APP_CMD_LOST_FOCUS: {
20604 active = false;
20605 break;
20606 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020607 }
20608}
20609
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020610void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020611 app_dummy();
20612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020613 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060020614
20615 int vulkanSupport = InitVulkan();
20616 if (vulkanSupport == 0) {
20617 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
20618 return;
20619 }
20620
20621 app->onAppCmd = processCommand;
20622 app->onInputEvent = processInput;
20623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020624 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020625 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020626 struct android_poll_source *source;
20627 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060020628 if (source) {
20629 source->process(app, source);
20630 }
20631
20632 if (app->destroyRequested != 0) {
20633 VkTestFramework::Finish();
20634 return;
20635 }
20636 }
20637
20638 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020639 // Use the following key to send arguments to gtest, i.e.
20640 // --es args "--gtest_filter=-VkLayerTest.foo"
20641 const char key[] = "args";
20642 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020644 std::string filter = "";
20645 if (args.size() > 0) {
20646 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
20647 filter += args[0];
20648 } else {
20649 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
20650 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020651
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020652 int argc = 2;
20653 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
20654 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020655
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020656 // Route output to files until we can override the gtest output
20657 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
20658 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020660 ::testing::InitGoogleTest(&argc, argv);
20661 VkTestFramework::InitArgs(&argc, argv);
20662 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020663
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020664 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020665
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020666 if (result != 0) {
20667 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
20668 } else {
20669 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
20670 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060020671
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020672 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060020673
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020674 fclose(stdout);
20675 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020676
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020677 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060020678
Mark Lobodzinskice751c62016-09-08 10:45:35 -060020679 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060020680 }
20681 }
20682}
20683#endif
20684
Tony Barbour300a6082015-04-07 13:44:53 -060020685int main(int argc, char **argv) {
20686 int result;
20687
Cody Northrop8e54a402016-03-08 22:25:52 -070020688#ifdef ANDROID
20689 int vulkanSupport = InitVulkan();
20690 if (vulkanSupport == 0)
20691 return 1;
20692#endif
20693
Tony Barbour300a6082015-04-07 13:44:53 -060020694 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060020695 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060020696
20697 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
20698
20699 result = RUN_ALL_TESTS();
20700
Tony Barbour6918cd52015-04-09 12:58:51 -060020701 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060020702 return result;
20703}