blob: e72205d259826fba4173f571c1b98f8f66e5554f [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
46//--------------------------------------------------------------------------------------
47// Mesh and VertexFormat Data
48//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070049struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070050 float posX, posY, posZ, posW; // Position data
51 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050052};
53
Karl Schultz6addd812016-02-02 17:17:23 -070054#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055
56typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070057 BsoFailNone = 0x00000000,
58 BsoFailLineWidth = 0x00000001,
59 BsoFailDepthBias = 0x00000002,
60 BsoFailViewport = 0x00000004,
61 BsoFailScissor = 0x00000008,
62 BsoFailBlend = 0x00000010,
63 BsoFailDepthBounds = 0x00000020,
64 BsoFailStencilReadMask = 0x00000040,
65 BsoFailStencilWriteMask = 0x00000080,
66 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060067 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060068 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050069} BsoFailSelect;
70
71struct vktriangle_vs_uniform {
72 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070073 float mvp[4][4];
74 float position[3][4];
75 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050076};
77
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070078static const char bindStateVertShaderText[] =
79 "#version 450\n"
80 "vec2 vertices[3];\n"
81 "out gl_PerVertex {\n"
82 " vec4 gl_Position;\n"
83 "};\n"
84 "void main() {\n"
85 " vertices[0] = vec2(-1.0, -1.0);\n"
86 " vertices[1] = vec2( 1.0, -1.0);\n"
87 " vertices[2] = vec2( 0.0, 1.0);\n"
88 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
89 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050090
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070091static const char bindStateFragShaderText[] =
92 "#version 450\n"
93 "\n"
94 "layout(location = 0) out vec4 uFragColor;\n"
95 "void main(){\n"
96 " uFragColor = vec4(0,1,0,1);\n"
97 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050098
Mark Lobodzinskice751c62016-09-08 10:45:35 -060099static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
100 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
101 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600102
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600103// ErrorMonitor Usage:
104//
Dave Houltonfbf52152017-01-06 12:55:29 -0700105// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600106// encountered log messages, or a validation error enum identifying
107// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
108// will match all log messages. logMsg will return true for skipCall
109// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600110//
Dave Houltonfbf52152017-01-06 12:55:29 -0700111// Call VerifyFound to determine if all desired failure messages
112// were encountered. Call VerifyNotFound to determine if any unexpected
113// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600114class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700115 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700116 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700117 test_platform_thread_create_mutex(&mutex_);
118 test_platform_thread_lock_mutex(&mutex_);
119 Reset();
120 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600121 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600122
Dave Houltonfbf52152017-01-06 12:55:29 -0700123 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600124
Dave Houltonfbf52152017-01-06 12:55:29 -0700125 // Set monitor to pristine state
126 void Reset() {
127 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
128 bailout_ = NULL;
129 message_found_ = VK_FALSE;
130 failure_message_strings_.clear();
131 desired_message_strings_.clear();
132 desired_message_ids_.clear();
133 other_messages_.clear();
134 message_outstanding_count_ = 0;
135 }
136
137 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700138 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700139 test_platform_thread_lock_mutex(&mutex_);
140 desired_message_strings_.insert(msgString);
141 message_flags_ |= msgFlags;
142 message_outstanding_count_++;
143 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600144 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600145
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700146 // ErrorMonitor will look for an error message containing the specified string(s)
147 template <typename Iter>
148 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
149 for (; iter != end; ++iter) {
150 SetDesiredFailureMsg(msgFlags, *iter);
151 }
152 }
153
Dave Houltonfbf52152017-01-06 12:55:29 -0700154 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700155 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700156 test_platform_thread_lock_mutex(&mutex_);
157 desired_message_ids_.insert(msg_id);
158 message_flags_ |= msgFlags;
159 message_outstanding_count_++;
160 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600161 }
162
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700163 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600164 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700165 test_platform_thread_lock_mutex(&mutex_);
166 if (bailout_ != NULL) {
167 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600168 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600169 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600170 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600171
Dave Houltonfbf52152017-01-06 12:55:29 -0700172 for (auto desired_msg : desired_message_strings_) {
Karl Schultz05cc4e32016-10-12 13:25:23 -0600173 if (desired_msg.length() == 0) {
174 // An empty desired_msg string "" indicates a positive test - not expecting an error.
175 // Return true to avoid calling layers/driver with this error.
176 // And don't erase the "" string, so it remains if another error is found.
177 result = VK_TRUE;
Tony Barbourae58dba2016-12-13 16:30:36 -0700178 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700179 message_found_ = VK_TRUE;
180 failure_message_strings_.insert(errorString);
Karl Schultz05cc4e32016-10-12 13:25:23 -0600181 } else if (errorString.find(desired_msg) != string::npos) {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600182 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700183 message_outstanding_count_--;
184 failure_message_strings_.insert(errorString);
185 message_found_ = VK_TRUE;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600186 result = VK_TRUE;
187 // We only want one match for each expected error so remove from set here
188 // 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 -0700189 desired_message_strings_.erase(desired_msg);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600190 break;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600191 }
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600192 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700193 for (auto desired_id : desired_message_ids_) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600194 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
195 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
196 // Return true to avoid calling layers/driver with this error.
197 result = VK_TRUE;
198 } else if (desired_id == message_code) {
199 // Double-check that the string matches the error enum
200 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
201 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700202 message_outstanding_count_--;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600203 result = VK_TRUE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700204 message_found_ = VK_TRUE;
205 desired_message_ids_.erase(desired_id);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 break;
207 } else {
208 // Treat this message as a regular unexpected error, but print a warning jic
209 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
210 errorString.c_str(), desired_id, validation_error_map[desired_id]);
211 }
212 }
213 }
214
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600215 if (!found_expected) {
Chris Forbes5b9442b2016-09-13 16:49:57 +1200216 printf("Unexpected: %s\n", msgString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700217 other_messages_.push_back(errorString);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600218 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700219 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600220 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600221 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600222
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700223 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600224
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700225 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600226
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700227 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600228
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700229 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700230
231 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600232
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700233 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600234 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600235 if (otherMsgs.size()) {
236 cout << "Other error messages logged for this test were:" << endl;
237 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
238 cout << " " << *iter << endl;
239 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600240 }
241 }
242
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600243 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200244
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600245 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700246 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600247 // Match ANY message matching specified type
248 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700249 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200250 }
251
252 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600253 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700254 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200255 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700256 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700257 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600258 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700259 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700260 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600261 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700263 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200264 }
265
266 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600267 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700268 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200269 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700270 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700271 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600272 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700274 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200275 }
276
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700277 private:
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700278 VkFlags message_flags_;
279 std::unordered_set<uint32_t> desired_message_ids_;
280 std::unordered_set<string> desired_message_strings_;
281 std::unordered_set<string> failure_message_strings_;
282 vector<string> other_messages_;
283 test_platform_thread_mutex mutex_;
284 bool *bailout_;
285 VkBool32 message_found_;
286 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600287};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500288
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600289static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
290 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
291 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600292 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
293 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600294 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600295 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600296 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600297}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500298
Karl Schultz6addd812016-02-02 17:17:23 -0700299class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700300 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600301 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
302 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700303 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600304 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
305 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700306 }
Tony Barbour300a6082015-04-07 13:44:53 -0600307
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600308 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
309 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700310 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600311 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700312 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600313 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700314 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600315 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
316 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
317 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700318 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
319 }
320 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
321 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
322 }
323
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700324 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700325 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600326 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600327
328 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600329 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600330 std::vector<const char *> instance_extension_names;
331 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600332
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700333 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600334 /*
335 * Since CreateDbgMsgCallback is an instance level extension call
336 * any extension / layer that utilizes that feature also needs
337 * to be enabled at create instance time.
338 */
Karl Schultz6addd812016-02-02 17:17:23 -0700339 // Use Threading layer first to protect others from
340 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700341 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600342 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800343 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700344 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800345 instance_layer_names.push_back("VK_LAYER_LUNARG_image");
Ian Elliotte48a1382016-04-28 14:22:58 -0600346 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700347 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600348
Ian Elliott2c1daf52016-05-12 09:41:46 -0600349 if (m_enableWSI) {
350 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
351 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
352#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
353#if defined(VK_USE_PLATFORM_ANDROID_KHR)
354 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600356#if defined(VK_USE_PLATFORM_MIR_KHR)
357 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700358#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600359#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
360 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700361#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600362#if defined(VK_USE_PLATFORM_WIN32_KHR)
363 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700364#endif // VK_USE_PLATFORM_WIN32_KHR
365#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600366#if defined(VK_USE_PLATFORM_XCB_KHR)
367 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
368#elif defined(VK_USE_PLATFORM_XLIB_KHR)
369 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700370#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600371 }
372
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600373 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600374 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800375 this->app_info.pApplicationName = "layer_tests";
376 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600377 this->app_info.pEngineName = "unittest";
378 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600379 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600380
Tony Barbour15524c32015-04-29 17:34:29 -0600381 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600382 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600383 }
384
385 virtual void TearDown() {
386 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600387 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600388 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600389 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600390
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600391 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600392};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500393
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600394void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500395 // Create identity matrix
396 int i;
397 struct vktriangle_vs_uniform data;
398
399 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700400 glm::mat4 View = glm::mat4(1.0f);
401 glm::mat4 Model = glm::mat4(1.0f);
402 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500403 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700404 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500405
406 memcpy(&data.mvp, &MVP[0][0], matrixSize);
407
Karl Schultz6addd812016-02-02 17:17:23 -0700408 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600409 {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 -0500410 };
411
Karl Schultz6addd812016-02-02 17:17:23 -0700412 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500413 data.position[i][0] = tri_data[i].posX;
414 data.position[i][1] = tri_data[i].posY;
415 data.position[i][2] = tri_data[i].posZ;
416 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700417 data.color[i][0] = tri_data[i].r;
418 data.color[i][1] = tri_data[i].g;
419 data.color[i][2] = tri_data[i].b;
420 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500421 }
422
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423 ASSERT_NO_FATAL_FAILURE(InitViewport());
424
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200425 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
426 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500427
Karl Schultz6addd812016-02-02 17:17:23 -0700428 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600429 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500430
431 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800432 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 pipelineobj.AddShader(&vs);
434 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600435 if (failMask & BsoFailLineWidth) {
436 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600437 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600438 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600439 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
440 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600441 }
442 if (failMask & BsoFailDepthBias) {
443 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600444 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600445 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600446 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600447 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600448 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600449 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700450 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700451 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600452 if (failMask & BsoFailViewport) {
453 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
454 }
455 if (failMask & BsoFailScissor) {
456 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
457 }
458 if (failMask & BsoFailBlend) {
459 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600460 VkPipelineColorBlendAttachmentState att_state = {};
461 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
462 att_state.blendEnable = VK_TRUE;
463 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600464 }
465 if (failMask & BsoFailDepthBounds) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
467 }
468 if (failMask & BsoFailStencilReadMask) {
469 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
470 }
471 if (failMask & BsoFailStencilWriteMask) {
472 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
473 }
474 if (failMask & BsoFailStencilReference) {
475 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
476 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500477
478 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600479 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500480
481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700482 m_commandBuffer->BeginCommandBuffer();
483 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500484
Tony Barbourfe3351b2015-07-28 10:17:20 -0600485 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500486
487 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600488 if (failMask & BsoFailIndexBuffer) {
489 // Use DrawIndexed w/o an index buffer bound
490 DrawIndexed(3, 1, 0, 0, 0);
491 } else {
492 Draw(3, 1, 0, 0);
493 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500494
Mark Muellerd4914412016-06-13 17:52:06 -0600495 if (failMask & BsoFailCmdClearAttachments) {
496 VkClearAttachment color_attachment = {};
497 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700498 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600499 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
500
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600501 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600502 }
503
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500504 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700505 m_commandBuffer->EndRenderPass();
506 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600507 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500508}
509
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600510void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
511 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500512 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600513 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600515 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516 }
517
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800518 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700519 // Make sure depthWriteEnable is set so that Depth fail test will work
520 // correctly
521 // Make sure stencilTestEnable is set so that Stencil fail test will work
522 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600523 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800524 stencil.failOp = VK_STENCIL_OP_KEEP;
525 stencil.passOp = VK_STENCIL_OP_KEEP;
526 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
527 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600528
529 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
530 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600531 ds_ci.pNext = NULL;
532 ds_ci.depthTestEnable = VK_FALSE;
533 ds_ci.depthWriteEnable = VK_TRUE;
534 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
535 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600536 if (failMask & BsoFailDepthBounds) {
537 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600538 ds_ci.maxDepthBounds = 0.0f;
539 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600540 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600541 ds_ci.stencilTestEnable = VK_TRUE;
542 ds_ci.front = stencil;
543 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600544
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600545 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600546 pipelineobj.SetViewport(m_viewports);
547 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800548 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600549 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600550 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800551 commandBuffer->BindPipeline(pipelineobj);
552 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500553}
554
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600555class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700556 public:
557 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600558};
559
Ian Elliott2c1daf52016-05-12 09:41:46 -0600560class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700561 public:
562 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600563 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600564};
565
Mark Muellerdfe37552016-07-07 14:47:42 -0600566class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700567 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600568 enum eTestEnFlags {
569 eDoubleDelete,
570 eInvalidDeviceOffset,
571 eInvalidMemoryOffset,
572 eBindNullBuffer,
573 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600574 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600575 };
576
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600577 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600578
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600579 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
580 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600581 return true;
582 }
583 VkDeviceSize offset_limit = 0;
584 if (eInvalidMemoryOffset == aTestFlag) {
585 VkBuffer vulkanBuffer;
586 VkBufferCreateInfo buffer_create_info = {};
587 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
588 buffer_create_info.size = 32;
589 buffer_create_info.usage = aBufferUsage;
590
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600591 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600592 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600593
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600594 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600595 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
596 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600597 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
598 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600599 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600600 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600601 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600602 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600603 }
604 if (eOffsetAlignment < offset_limit) {
605 return true;
606 }
607 return false;
608 }
609
610 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600611 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
612 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600613 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 Lobodzinski64318ba2017-01-26 13:34:13 -0700680 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 Lobodzinski64318ba2017-01-26 13:34:13 -0700692 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600693 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600694 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700695 : BoundCurrent(false),
696 AttributeCount(aAttributeCount),
697 BindingCount(aBindingCount),
698 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600699 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
701 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700702 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600703
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600704 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
705 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600706
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600707 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
708 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
709 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
710 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
711 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600712
713 unsigned i = 0;
714 do {
715 VertexInputAttributeDescription[i].binding = BindId;
716 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600717 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
718 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719 i++;
720 } while (AttributeCount < i);
721
722 i = 0;
723 do {
724 VertexInputBindingDescription[i].binding = BindId;
725 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600726 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600727 i++;
728 } while (BindingCount < i);
729 }
730
731 ~VkVerticesObj() {
732 if (VertexInputAttributeDescription) {
733 delete[] VertexInputAttributeDescription;
734 }
735 if (VertexInputBindingDescription) {
736 delete[] VertexInputBindingDescription;
737 }
738 }
739
740 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600741 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
742 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600743 return true;
744 }
745
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600746 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600747 VkDeviceSize *offsetList;
748 unsigned offsetCount;
749
750 if (aOffsetCount) {
751 offsetList = aOffsetList;
752 offsetCount = aOffsetCount;
753 } else {
754 offsetList = new VkDeviceSize[1]();
755 offsetCount = 1;
756 }
757
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600758 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600759 BoundCurrent = true;
760
761 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600762 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600763 }
764 }
765
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700766 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 static uint32_t BindIdGenerator;
768
769 bool BoundCurrent;
770 unsigned AttributeCount;
771 unsigned BindingCount;
772 uint32_t BindId;
773
774 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
775 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
776 VkVertexInputBindingDescription *VertexInputBindingDescription;
777 VkConstantBufferObj VulkanMemoryBuffer;
778};
779
780uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500781// ********************************************************************************************************************
782// ********************************************************************************************************************
783// ********************************************************************************************************************
784// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600785TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700786 TEST_DESCRIPTION(
787 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
788 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600789
790 ASSERT_NO_FATAL_FAILURE(InitState());
791
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600793 // Specify NULL for a pointer to a handle
794 // Expected to trigger an error with
795 // parameter_validation::validate_required_pointer
796 vkGetPhysicalDeviceFeatures(gpu(), NULL);
797 m_errorMonitor->VerifyFound();
798
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
800 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600801 // Specify NULL for pointer to array count
802 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600803 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600804 m_errorMonitor->VerifyFound();
805
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600807 // Specify 0 for a required array count
808 // Expected to trigger an error with parameter_validation::validate_array
809 VkViewport view_port = {};
810 m_commandBuffer->SetViewport(0, 0, &view_port);
811 m_errorMonitor->VerifyFound();
812
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600814 // Specify NULL for a required array
815 // Expected to trigger an error with parameter_validation::validate_array
816 m_commandBuffer->SetViewport(0, 1, NULL);
817 m_errorMonitor->VerifyFound();
818
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600819 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600820 // Specify VK_NULL_HANDLE for a required handle
821 // Expected to trigger an error with
822 // parameter_validation::validate_required_handle
823 vkUnmapMemory(device(), VK_NULL_HANDLE);
824 m_errorMonitor->VerifyFound();
825
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600826 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
827 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600828 // Specify VK_NULL_HANDLE for a required handle array entry
829 // Expected to trigger an error with
830 // parameter_validation::validate_required_handle_array
831 VkFence fence = VK_NULL_HANDLE;
832 vkResetFences(device(), 1, &fence);
833 m_errorMonitor->VerifyFound();
834
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600836 // Specify NULL for a required struct pointer
837 // Expected to trigger an error with
838 // parameter_validation::validate_struct_type
839 VkDeviceMemory memory = VK_NULL_HANDLE;
840 vkAllocateMemory(device(), NULL, NULL, &memory);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 // Specify 0 for a required VkFlags parameter
845 // Expected to trigger an error with parameter_validation::validate_flags
846 m_commandBuffer->SetStencilReference(0, 0);
847 m_errorMonitor->VerifyFound();
848
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600849 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 -0600850 // Specify 0 for a required VkFlags array entry
851 // Expected to trigger an error with
852 // parameter_validation::validate_flags_array
853 VkSemaphore semaphore = VK_NULL_HANDLE;
854 VkPipelineStageFlags stageFlags = 0;
855 VkSubmitInfo submitInfo = {};
856 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
857 submitInfo.waitSemaphoreCount = 1;
858 submitInfo.pWaitSemaphores = &semaphore;
859 submitInfo.pWaitDstStageMask = &stageFlags;
860 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
861 m_errorMonitor->VerifyFound();
862}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600863
Dustin Gravesfce74c02016-05-10 11:42:58 -0600864TEST_F(VkLayerTest, ReservedParameter) {
865 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
866
867 ASSERT_NO_FATAL_FAILURE(InitState());
868
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600870 // Specify 0 for a reserved VkFlags parameter
871 // Expected to trigger an error with
872 // parameter_validation::validate_reserved_flags
873 VkEvent event_handle = VK_NULL_HANDLE;
874 VkEventCreateInfo event_info = {};
875 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
876 event_info.flags = 1;
877 vkCreateEvent(device(), &event_info, NULL, &event_handle);
878 m_errorMonitor->VerifyFound();
879}
880
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600881TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700882 TEST_DESCRIPTION(
883 "Specify an invalid VkStructureType for a Vulkan "
884 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600885
886 ASSERT_NO_FATAL_FAILURE(InitState());
887
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600889 // Zero struct memory, effectively setting sType to
890 // VK_STRUCTURE_TYPE_APPLICATION_INFO
891 // Expected to trigger an error with
892 // parameter_validation::validate_struct_type
893 VkMemoryAllocateInfo alloc_info = {};
894 VkDeviceMemory memory = VK_NULL_HANDLE;
895 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
896 m_errorMonitor->VerifyFound();
897
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600899 // Zero struct memory, effectively setting sType to
900 // VK_STRUCTURE_TYPE_APPLICATION_INFO
901 // Expected to trigger an error with
902 // parameter_validation::validate_struct_type_array
903 VkSubmitInfo submit_info = {};
904 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
905 m_errorMonitor->VerifyFound();
906}
907
908TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600909 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600910
911 ASSERT_NO_FATAL_FAILURE(InitState());
912
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600914 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600915 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600916 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600917 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600918 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600919 // Zero-initialization will provide the correct sType
920 VkApplicationInfo app_info = {};
921 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
922 event_alloc_info.pNext = &app_info;
923 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
924 m_errorMonitor->VerifyFound();
925
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
927 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600928 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
929 // a function that has allowed pNext structure types and specify
930 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600931 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600932 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600933 VkMemoryAllocateInfo memory_alloc_info = {};
934 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
935 memory_alloc_info.pNext = &app_info;
936 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600937 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600938}
Dustin Graves5d33d532016-05-09 16:21:12 -0600939
940TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600941 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600942
943 ASSERT_NO_FATAL_FAILURE(InitState());
944
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700945 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
946 "does not fall within the begin..end "
947 "range of the core VkFormat "
948 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600949 // Specify an invalid VkFormat value
950 // Expected to trigger an error with
951 // parameter_validation::validate_ranged_enum
952 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600953 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600954 m_errorMonitor->VerifyFound();
955
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 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 -0600957 // Specify an invalid VkFlags bitmask value
958 // Expected to trigger an error with parameter_validation::validate_flags
959 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600960 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
961 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600962 m_errorMonitor->VerifyFound();
963
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600964 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 -0600965 // Specify an invalid VkFlags array entry
966 // Expected to trigger an error with
967 // parameter_validation::validate_flags_array
968 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600969 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -0600970 VkSubmitInfo submit_info = {};
971 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
972 submit_info.waitSemaphoreCount = 1;
973 submit_info.pWaitSemaphores = &semaphore;
974 submit_info.pWaitDstStageMask = &stage_flags;
975 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
976 m_errorMonitor->VerifyFound();
977
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 // Specify an invalid VkBool32 value
980 // Expected to trigger a warning with
981 // parameter_validation::validate_bool32
982 VkSampler sampler = VK_NULL_HANDLE;
983 VkSamplerCreateInfo sampler_info = {};
984 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
985 sampler_info.pNext = NULL;
986 sampler_info.magFilter = VK_FILTER_NEAREST;
987 sampler_info.minFilter = VK_FILTER_NEAREST;
988 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
989 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
990 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
991 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
992 sampler_info.mipLodBias = 1.0;
993 sampler_info.maxAnisotropy = 1;
994 sampler_info.compareEnable = VK_FALSE;
995 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
996 sampler_info.minLod = 1.0;
997 sampler_info.maxLod = 1.0;
998 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
999 sampler_info.unnormalizedCoordinates = VK_FALSE;
1000 // Not VK_TRUE or VK_FALSE
1001 sampler_info.anisotropyEnable = 3;
1002 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1003 m_errorMonitor->VerifyFound();
1004}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001005
1006TEST_F(VkLayerTest, FailedReturnValue) {
1007 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1008
1009 ASSERT_NO_FATAL_FAILURE(InitState());
1010
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001011 // Find an unsupported image format
1012 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1013 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1014 VkFormat format = static_cast<VkFormat>(f);
1015 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001016 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001017 unsupported = format;
1018 break;
1019 }
1020 }
1021
1022 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1024 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001025 // Specify an unsupported VkFormat value to generate a
1026 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1027 // Expected to trigger a warning from
1028 // parameter_validation::validate_result
1029 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001030 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1031 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001032 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1033 m_errorMonitor->VerifyFound();
1034 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001035}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001036
1037TEST_F(VkLayerTest, UpdateBufferAlignment) {
1038 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001039 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001040
1041 ASSERT_NO_FATAL_FAILURE(InitState());
1042
1043 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1044 vk_testing::Buffer buffer;
1045 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1046
Tony Barbour552f6c02016-12-21 14:34:07 -07001047 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001048 // Introduce failure by using dstOffset 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(), 1, 4, updateData);
1051 m_errorMonitor->VerifyFound();
1052
1053 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001055 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1056 m_errorMonitor->VerifyFound();
1057
1058 // Introduce failure by using dataSize that is < 0
1059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001060 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001061 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1062 m_errorMonitor->VerifyFound();
1063
1064 // Introduce failure by using dataSize that is > 65536
1065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001066 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001067 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1068 m_errorMonitor->VerifyFound();
1069
Tony Barbour552f6c02016-12-21 14:34:07 -07001070 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001071}
1072
1073TEST_F(VkLayerTest, FillBufferAlignment) {
1074 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1075
1076 ASSERT_NO_FATAL_FAILURE(InitState());
1077
1078 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1079 vk_testing::Buffer buffer;
1080 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1081
Tony Barbour552f6c02016-12-21 14:34:07 -07001082 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001083
1084 // Introduce failure by using dstOffset 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(), 1, 4, 0x11111111);
1087 m_errorMonitor->VerifyFound();
1088
1089 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001096 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1097 m_errorMonitor->VerifyFound();
1098
Tony Barbour552f6c02016-12-21 14:34:07 -07001099 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001100}
Dustin Graves40f35822016-06-23 11:12:53 -06001101
Cortd889ff92016-07-27 09:51:27 -07001102TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1103 VkResult err;
1104
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001105 TEST_DESCRIPTION(
1106 "Attempt to use a non-solid polygon fill mode in a "
1107 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001108
1109 ASSERT_NO_FATAL_FAILURE(InitState());
1110 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1111
1112 std::vector<const char *> device_extension_names;
1113 auto features = m_device->phy().features();
1114 // Artificially disable support for non-solid fill modes
1115 features.fillModeNonSolid = false;
1116 // The sacrificial device object
1117 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1118
1119 VkRenderpassObj render_pass(&test_device);
1120
1121 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1122 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1123 pipeline_layout_ci.setLayoutCount = 0;
1124 pipeline_layout_ci.pSetLayouts = NULL;
1125
1126 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001127 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001128 ASSERT_VK_SUCCESS(err);
1129
1130 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1131 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1132 rs_ci.pNext = nullptr;
1133 rs_ci.lineWidth = 1.0f;
1134 rs_ci.rasterizerDiscardEnable = true;
1135
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001136 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1137 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001138
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001139 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1141 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001142 {
1143 VkPipelineObj pipe(&test_device);
1144 pipe.AddShader(&vs);
1145 pipe.AddShader(&fs);
1146 pipe.AddColorAttachment();
1147 // Introduce failure by setting unsupported polygon mode
1148 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1149 pipe.SetRasterization(&rs_ci);
1150 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1151 }
1152 m_errorMonitor->VerifyFound();
1153
1154 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1156 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001157 {
1158 VkPipelineObj pipe(&test_device);
1159 pipe.AddShader(&vs);
1160 pipe.AddShader(&fs);
1161 pipe.AddColorAttachment();
1162 // Introduce failure by setting unsupported polygon mode
1163 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1164 pipe.SetRasterization(&rs_ci);
1165 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1166 }
1167 m_errorMonitor->VerifyFound();
1168
Cortd889ff92016-07-27 09:51:27 -07001169 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1170}
1171
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001172#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001173TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001174{
1175 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001176 VkFenceCreateInfo fenceInfo = {};
1177 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1178 fenceInfo.pNext = NULL;
1179 fenceInfo.flags = 0;
1180
Mike Weiblencce7ec72016-10-17 19:33:05 -06001181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001182
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001183 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001184
1185 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1186 vk_testing::Buffer buffer;
1187 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001188
Tony Barbourfe3351b2015-07-28 10:17:20 -06001189 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001190 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001191 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001192
1193 testFence.init(*m_device, fenceInfo);
1194
1195 // Bypass framework since it does the waits automatically
1196 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001197 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001198 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1199 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001200 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001201 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001202 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001203 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001204 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001205 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001206 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001207
1208 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001209 ASSERT_VK_SUCCESS( err );
1210
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001211 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001212 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001213
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001214 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001215}
1216
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001217TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001218{
1219 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001220 VkFenceCreateInfo fenceInfo = {};
1221 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1222 fenceInfo.pNext = NULL;
1223 fenceInfo.flags = 0;
1224
Mike Weiblencce7ec72016-10-17 19:33:05 -06001225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001226
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001227 ASSERT_NO_FATAL_FAILURE(InitState());
1228 ASSERT_NO_FATAL_FAILURE(InitViewport());
1229 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1230
Tony Barbourfe3351b2015-07-28 10:17:20 -06001231 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001232 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001233 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001234
1235 testFence.init(*m_device, fenceInfo);
1236
1237 // Bypass framework since it does the waits automatically
1238 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001239 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001240 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1241 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001242 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001243 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001244 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001245 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001246 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001247 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001248 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001249
1250 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251 ASSERT_VK_SUCCESS( err );
1252
Jon Ashburnf19916e2016-01-11 13:12:43 -07001253 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001254 VkCommandBufferBeginInfo info = {};
1255 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1256 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001257 info.renderPass = VK_NULL_HANDLE;
1258 info.subpass = 0;
1259 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001260 info.occlusionQueryEnable = VK_FALSE;
1261 info.queryFlags = 0;
1262 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001263
1264 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001265 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001266
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001267 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001268}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001269#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001270
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001271TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1272 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1273
1274 ASSERT_NO_FATAL_FAILURE(InitState());
1275
1276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1277 VkBuffer buffer;
1278 VkBufferCreateInfo buf_info = {};
1279 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1280 buf_info.pNext = NULL;
1281 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1282 buf_info.size = 2048;
1283 buf_info.queueFamilyIndexCount = 0;
1284 buf_info.pQueueFamilyIndices = NULL;
1285 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1286 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1287 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1288 m_errorMonitor->VerifyFound();
1289
1290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1291 VkImage image;
1292 VkImageCreateInfo image_create_info = {};
1293 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1294 image_create_info.pNext = NULL;
1295 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1296 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1297 image_create_info.extent.width = 512;
1298 image_create_info.extent.height = 64;
1299 image_create_info.extent.depth = 1;
1300 image_create_info.mipLevels = 1;
1301 image_create_info.arrayLayers = 1;
1302 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1303 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1304 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1305 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1306 image_create_info.queueFamilyIndexCount = 0;
1307 image_create_info.pQueueFamilyIndices = NULL;
1308 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1309 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1310 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1311 m_errorMonitor->VerifyFound();
1312}
1313
Dave Houlton829c0d82017-01-24 15:09:17 -07001314TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1315 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1316
1317 // Determine which device feature are available
1318 VkPhysicalDeviceFeatures available_features;
1319 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1320
1321 // Mask out device features we don't want
1322 VkPhysicalDeviceFeatures desired_features = available_features;
1323 desired_features.sparseResidencyImage2D = VK_FALSE;
1324 desired_features.sparseResidencyImage3D = VK_FALSE;
1325 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1326
1327 VkImage image = VK_NULL_HANDLE;
1328 VkResult result = VK_RESULT_MAX_ENUM;
1329 VkImageCreateInfo image_create_info = {};
1330 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1331 image_create_info.pNext = NULL;
1332 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1333 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1334 image_create_info.extent.width = 512;
1335 image_create_info.extent.height = 1;
1336 image_create_info.extent.depth = 1;
1337 image_create_info.mipLevels = 1;
1338 image_create_info.arrayLayers = 1;
1339 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1340 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1341 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1342 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1343 image_create_info.queueFamilyIndexCount = 0;
1344 image_create_info.pQueueFamilyIndices = NULL;
1345 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1346 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1347
1348 // 1D image w/ sparse residency is an error
1349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1350 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1351 m_errorMonitor->VerifyFound();
1352 if (VK_SUCCESS == result) {
1353 vkDestroyImage(m_device->device(), image, NULL);
1354 image = VK_NULL_HANDLE;
1355 }
1356
1357 // 2D image w/ sparse residency when feature isn't available
1358 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1359 image_create_info.extent.height = 64;
1360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1361 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1362 m_errorMonitor->VerifyFound();
1363 if (VK_SUCCESS == result) {
1364 vkDestroyImage(m_device->device(), image, NULL);
1365 image = VK_NULL_HANDLE;
1366 }
1367
1368 // 3D image w/ sparse residency when feature isn't available
1369 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1370 image_create_info.extent.depth = 8;
1371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1372 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1373 m_errorMonitor->VerifyFound();
1374 if (VK_SUCCESS == result) {
1375 vkDestroyImage(m_device->device(), image, NULL);
1376 image = VK_NULL_HANDLE;
1377 }
1378}
1379
1380TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1381 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1382
1383 // Determine which device feature are available
1384 VkPhysicalDeviceFeatures available_features;
1385 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1386
1387 // These tests all require that the device support sparse residency for 2D images
1388 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1389 return;
1390 }
1391
1392 // Mask out device features we don't want
1393 VkPhysicalDeviceFeatures desired_features = available_features;
1394 desired_features.sparseResidency2Samples = VK_FALSE;
1395 desired_features.sparseResidency4Samples = VK_FALSE;
1396 desired_features.sparseResidency8Samples = VK_FALSE;
1397 desired_features.sparseResidency16Samples = VK_FALSE;
1398 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1399
1400 VkImage image = VK_NULL_HANDLE;
1401 VkResult result = VK_RESULT_MAX_ENUM;
1402 VkImageCreateInfo image_create_info = {};
1403 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1404 image_create_info.pNext = NULL;
1405 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1406 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1407 image_create_info.extent.width = 64;
1408 image_create_info.extent.height = 64;
1409 image_create_info.extent.depth = 1;
1410 image_create_info.mipLevels = 1;
1411 image_create_info.arrayLayers = 1;
1412 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1413 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1414 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1415 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1416 image_create_info.queueFamilyIndexCount = 0;
1417 image_create_info.pQueueFamilyIndices = NULL;
1418 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1419 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1420
1421 // 2D image w/ sparse residency and linear tiling is an error
1422 m_errorMonitor->SetDesiredFailureMsg(
1423 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1424 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1425 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1426 m_errorMonitor->VerifyFound();
1427 if (VK_SUCCESS == result) {
1428 vkDestroyImage(m_device->device(), image, NULL);
1429 image = VK_NULL_HANDLE;
1430 }
1431 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1432
1433 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1434 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1436 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1437 m_errorMonitor->VerifyFound();
1438 if (VK_SUCCESS == result) {
1439 vkDestroyImage(m_device->device(), image, NULL);
1440 image = VK_NULL_HANDLE;
1441 }
1442
1443 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1445 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1446 m_errorMonitor->VerifyFound();
1447 if (VK_SUCCESS == result) {
1448 vkDestroyImage(m_device->device(), image, NULL);
1449 image = VK_NULL_HANDLE;
1450 }
1451
1452 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1453 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1454 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1455 m_errorMonitor->VerifyFound();
1456 if (VK_SUCCESS == result) {
1457 vkDestroyImage(m_device->device(), image, NULL);
1458 image = VK_NULL_HANDLE;
1459 }
1460
1461 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1462 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1463 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1464 m_errorMonitor->VerifyFound();
1465 if (VK_SUCCESS == result) {
1466 vkDestroyImage(m_device->device(), image, NULL);
1467 image = VK_NULL_HANDLE;
1468 }
1469}
1470
Tobin Ehlisf11be982016-05-11 13:52:53 -06001471TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001472 TEST_DESCRIPTION(
1473 "Create a buffer and image, allocate memory, and bind the "
1474 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001475 VkResult err;
1476 bool pass;
1477 ASSERT_NO_FATAL_FAILURE(InitState());
1478
Tobin Ehlis077ded32016-05-12 17:39:13 -06001479 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001480 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001481 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001482 VkDeviceMemory mem; // buffer will be bound first
1483 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001484 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001485 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001486
1487 VkBufferCreateInfo buf_info = {};
1488 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1489 buf_info.pNext = NULL;
1490 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1491 buf_info.size = 256;
1492 buf_info.queueFamilyIndexCount = 0;
1493 buf_info.pQueueFamilyIndices = NULL;
1494 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1495 buf_info.flags = 0;
1496 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1497 ASSERT_VK_SUCCESS(err);
1498
Tobin Ehlis077ded32016-05-12 17:39:13 -06001499 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001500
1501 VkImageCreateInfo image_create_info = {};
1502 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1503 image_create_info.pNext = NULL;
1504 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1505 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1506 image_create_info.extent.width = 64;
1507 image_create_info.extent.height = 64;
1508 image_create_info.extent.depth = 1;
1509 image_create_info.mipLevels = 1;
1510 image_create_info.arrayLayers = 1;
1511 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001512 // Image tiling must be optimal to trigger error when aliasing linear buffer
1513 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001514 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1515 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1516 image_create_info.queueFamilyIndexCount = 0;
1517 image_create_info.pQueueFamilyIndices = NULL;
1518 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1519 image_create_info.flags = 0;
1520
Tobin Ehlisf11be982016-05-11 13:52:53 -06001521 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1522 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001523 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1524 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001525
Tobin Ehlis077ded32016-05-12 17:39:13 -06001526 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1527
1528 VkMemoryAllocateInfo alloc_info = {};
1529 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1530 alloc_info.pNext = NULL;
1531 alloc_info.memoryTypeIndex = 0;
1532 // Ensure memory is big enough for both bindings
1533 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001534 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1535 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001536 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001537 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001538 vkDestroyImage(m_device->device(), image, NULL);
1539 return;
1540 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001541 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1542 ASSERT_VK_SUCCESS(err);
1543 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1544 ASSERT_VK_SUCCESS(err);
1545
Rene Lindsayd14f5572016-12-16 14:57:18 -07001546 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1547
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001549 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001550 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1551 m_errorMonitor->VerifyFound();
1552
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001553 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001554 // aliasing buffer2
1555 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1556 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001557 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1558 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001559 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001560 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001562 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001563 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001564 m_errorMonitor->VerifyFound();
1565
1566 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001568 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001569 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001570 vkFreeMemory(m_device->device(), mem, NULL);
1571 vkFreeMemory(m_device->device(), mem_img, NULL);
1572}
1573
Tobin Ehlis35372522016-05-12 08:32:31 -06001574TEST_F(VkLayerTest, InvalidMemoryMapping) {
1575 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1576 VkResult err;
1577 bool pass;
1578 ASSERT_NO_FATAL_FAILURE(InitState());
1579
1580 VkBuffer buffer;
1581 VkDeviceMemory mem;
1582 VkMemoryRequirements mem_reqs;
1583
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001584 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1585
Tobin Ehlis35372522016-05-12 08:32:31 -06001586 VkBufferCreateInfo buf_info = {};
1587 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1588 buf_info.pNext = NULL;
1589 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1590 buf_info.size = 256;
1591 buf_info.queueFamilyIndexCount = 0;
1592 buf_info.pQueueFamilyIndices = NULL;
1593 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1594 buf_info.flags = 0;
1595 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1596 ASSERT_VK_SUCCESS(err);
1597
1598 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1599 VkMemoryAllocateInfo alloc_info = {};
1600 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1601 alloc_info.pNext = NULL;
1602 alloc_info.memoryTypeIndex = 0;
1603
1604 // Ensure memory is big enough for both bindings
1605 static const VkDeviceSize allocation_size = 0x10000;
1606 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001607 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 -06001608 if (!pass) {
1609 vkDestroyBuffer(m_device->device(), buffer, NULL);
1610 return;
1611 }
1612 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1613 ASSERT_VK_SUCCESS(err);
1614
1615 uint8_t *pData;
1616 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001617 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 -06001618 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1619 m_errorMonitor->VerifyFound();
1620 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001621 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001622 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1624 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1625 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001626 m_errorMonitor->VerifyFound();
1627
1628 // Unmap the memory to avoid re-map error
1629 vkUnmapMemory(m_device->device(), mem);
1630 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001631 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1632 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1633 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001634 m_errorMonitor->VerifyFound();
1635 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1637 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001638 m_errorMonitor->VerifyFound();
1639 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001641 vkUnmapMemory(m_device->device(), mem);
1642 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001643
Tobin Ehlis35372522016-05-12 08:32:31 -06001644 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001645 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001646 ASSERT_VK_SUCCESS(err);
1647 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001648 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001650 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001652 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1653 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001654
Tobin Ehlis35372522016-05-12 08:32:31 -06001655 // Now flush range that oversteps mapped range
1656 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001657 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001658 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001659 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001660 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1662 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1663 m_errorMonitor->VerifyFound();
1664
1665 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1666 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001667 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001668 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001669 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001670 mmr.size = VK_WHOLE_SIZE;
1671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001672 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1673 m_errorMonitor->VerifyFound();
1674
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001675#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001676 // Some platforms have an atomsize of 1 which makes the test meaningless
1677 if (atom_size > 3) {
1678 // Now with an offset NOT a multiple of the device limit
1679 vkUnmapMemory(m_device->device(), mem);
1680 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1681 ASSERT_VK_SUCCESS(err);
1682 mmr.offset = 3; // Not a multiple of atom_size
1683 mmr.size = VK_WHOLE_SIZE;
1684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1685 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1686 m_errorMonitor->VerifyFound();
1687
1688 // Now with a size NOT a multiple of the device limit
1689 vkUnmapMemory(m_device->device(), mem);
1690 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1691 ASSERT_VK_SUCCESS(err);
1692 mmr.offset = atom_size;
1693 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1695 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1696 m_errorMonitor->VerifyFound();
1697 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001698#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001699 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1700 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001701 if (!pass) {
1702 vkFreeMemory(m_device->device(), mem, NULL);
1703 vkDestroyBuffer(m_device->device(), buffer, NULL);
1704 return;
1705 }
1706 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1707 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1708
1709 vkDestroyBuffer(m_device->device(), buffer, NULL);
1710 vkFreeMemory(m_device->device(), mem, NULL);
1711}
1712
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001713#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001714TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1715 VkResult err;
1716 bool pass;
1717
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001718 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1719 // following declaration (which is temporarily being moved below):
1720 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001721 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001722 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001723 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001724 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001725 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001726 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001727
1728 ASSERT_NO_FATAL_FAILURE(InitState());
1729
Ian Elliott3f06ce52016-04-29 14:46:21 -06001730#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1731#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1732 // Use the functions from the VK_KHR_android_surface extension without
1733 // enabling that extension:
1734
1735 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001736 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1738 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001739 pass = (err != VK_SUCCESS);
1740 ASSERT_TRUE(pass);
1741 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001742#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001743
Ian Elliott3f06ce52016-04-29 14:46:21 -06001744#if defined(VK_USE_PLATFORM_MIR_KHR)
1745 // Use the functions from the VK_KHR_mir_surface extension without enabling
1746 // that extension:
1747
1748 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001749 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001751 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1752 pass = (err != VK_SUCCESS);
1753 ASSERT_TRUE(pass);
1754 m_errorMonitor->VerifyFound();
1755
1756 // Tell whether an mir_connection supports presentation:
1757 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1759 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001760 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001761#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001762
Ian Elliott3f06ce52016-04-29 14:46:21 -06001763#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1764 // Use the functions from the VK_KHR_wayland_surface extension without
1765 // enabling that extension:
1766
1767 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001768 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1770 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001771 pass = (err != VK_SUCCESS);
1772 ASSERT_TRUE(pass);
1773 m_errorMonitor->VerifyFound();
1774
1775 // Tell whether an wayland_display supports presentation:
1776 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001777 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1778 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001779 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001780#endif // VK_USE_PLATFORM_WAYLAND_KHR
1781#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001782
Ian Elliott3f06ce52016-04-29 14:46:21 -06001783#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001784 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1785 // TO NON-LINUX PLATFORMS:
1786 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001787 // Use the functions from the VK_KHR_win32_surface extension without
1788 // enabling that extension:
1789
1790 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001791 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1793 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001794 pass = (err != VK_SUCCESS);
1795 ASSERT_TRUE(pass);
1796 m_errorMonitor->VerifyFound();
1797
1798 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001800 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001801 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001802// Set this (for now, until all platforms are supported and tested):
1803#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001804#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001805#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001806 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1807 // TO NON-LINUX PLATFORMS:
1808 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001809#endif
1810#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001811 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1812 // that extension:
1813
1814 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001815 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001817 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1818 pass = (err != VK_SUCCESS);
1819 ASSERT_TRUE(pass);
1820 m_errorMonitor->VerifyFound();
1821
1822 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001823 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001824 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1826 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001827 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001828// Set this (for now, until all platforms are supported and tested):
1829#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001830#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001831
Ian Elliott12630812016-04-29 14:35:43 -06001832#if defined(VK_USE_PLATFORM_XLIB_KHR)
1833 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1834 // that extension:
1835
1836 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001837 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001839 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1840 pass = (err != VK_SUCCESS);
1841 ASSERT_TRUE(pass);
1842 m_errorMonitor->VerifyFound();
1843
1844 // Tell whether an Xlib VisualID supports presentation:
1845 Display *dpy = NULL;
1846 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001848 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1849 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001850// Set this (for now, until all platforms are supported and tested):
1851#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001852#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001854// Use the functions from the VK_KHR_surface extension without enabling
1855// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001856
Ian Elliott489eec02016-05-05 14:12:44 -06001857#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001860 vkDestroySurfaceKHR(instance(), surface, NULL);
1861 m_errorMonitor->VerifyFound();
1862
1863 // Check if surface supports presentation:
1864 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001866 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1867 pass = (err != VK_SUCCESS);
1868 ASSERT_TRUE(pass);
1869 m_errorMonitor->VerifyFound();
1870
1871 // Check surface capabilities:
1872 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1874 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001875 pass = (err != VK_SUCCESS);
1876 ASSERT_TRUE(pass);
1877 m_errorMonitor->VerifyFound();
1878
1879 // Check surface formats:
1880 uint32_t format_count = 0;
1881 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1883 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001884 pass = (err != VK_SUCCESS);
1885 ASSERT_TRUE(pass);
1886 m_errorMonitor->VerifyFound();
1887
1888 // Check surface present modes:
1889 uint32_t present_mode_count = 0;
1890 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1892 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001893 pass = (err != VK_SUCCESS);
1894 ASSERT_TRUE(pass);
1895 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001896#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001897
Ian Elliott1c32c772016-04-28 14:47:13 -06001898 // Use the functions from the VK_KHR_swapchain extension without enabling
1899 // that extension:
1900
1901 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001903 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1904 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001905 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001906 pass = (err != VK_SUCCESS);
1907 ASSERT_TRUE(pass);
1908 m_errorMonitor->VerifyFound();
1909
1910 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1912 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001913 pass = (err != VK_SUCCESS);
1914 ASSERT_TRUE(pass);
1915 m_errorMonitor->VerifyFound();
1916
Chris Forbeseb7d5502016-09-13 18:19:21 +12001917 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1918 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1919 VkFence fence;
1920 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1921
Ian Elliott1c32c772016-04-28 14:47:13 -06001922 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001924 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001925 pass = (err != VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927 m_errorMonitor->VerifyFound();
1928
Chris Forbeseb7d5502016-09-13 18:19:21 +12001929 vkDestroyFence(m_device->device(), fence, nullptr);
1930
Ian Elliott1c32c772016-04-28 14:47:13 -06001931 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001932 //
1933 // NOTE: Currently can't test this because a real swapchain is needed (as
1934 // opposed to the fake one we created) in order for the layer to lookup the
1935 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001936
1937 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001939 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1940 m_errorMonitor->VerifyFound();
1941}
Chris Forbes09368e42016-10-13 11:59:22 +13001942#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001943
Karl Schultz6addd812016-02-02 17:17:23 -07001944TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1945 VkResult err;
1946 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001947
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1949 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001950
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001951 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001952
1953 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001954 VkImage image;
1955 VkDeviceMemory mem;
1956 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001957
Karl Schultz6addd812016-02-02 17:17:23 -07001958 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1959 const int32_t tex_width = 32;
1960 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001961
Tony Barboureb254902015-07-15 12:50:33 -06001962 VkImageCreateInfo image_create_info = {};
1963 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001964 image_create_info.pNext = NULL;
1965 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1966 image_create_info.format = tex_format;
1967 image_create_info.extent.width = tex_width;
1968 image_create_info.extent.height = tex_height;
1969 image_create_info.extent.depth = 1;
1970 image_create_info.mipLevels = 1;
1971 image_create_info.arrayLayers = 1;
1972 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1973 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1974 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
1975 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12001976 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001977
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001978 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08001979 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001980 mem_alloc.pNext = NULL;
1981 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001982
Chia-I Wuf7458c52015-10-26 21:10:41 +08001983 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001984 ASSERT_VK_SUCCESS(err);
1985
Karl Schultz6addd812016-02-02 17:17:23 -07001986 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001987
Mark Lobodzinski23065352015-05-29 09:32:35 -05001988 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001989
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001990 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001991 if (!pass) { // If we can't find any unmappable memory this test doesn't
1992 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08001993 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06001994 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06001995 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06001996
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001997 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001998 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001999 ASSERT_VK_SUCCESS(err);
2000
2001 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002002 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002003 ASSERT_VK_SUCCESS(err);
2004
2005 // Map memory as if to initialize the image
2006 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002007 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002008
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002009 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002010
Chia-I Wuf7458c52015-10-26 21:10:41 +08002011 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002012 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002013}
2014
Karl Schultz6addd812016-02-02 17:17:23 -07002015TEST_F(VkLayerTest, RebindMemory) {
2016 VkResult err;
2017 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002019 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002020
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002021 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002022
2023 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002024 VkImage image;
2025 VkDeviceMemory mem1;
2026 VkDeviceMemory mem2;
2027 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002028
Karl Schultz6addd812016-02-02 17:17:23 -07002029 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2030 const int32_t tex_width = 32;
2031 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002032
Tony Barboureb254902015-07-15 12:50:33 -06002033 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002034 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2035 image_create_info.pNext = NULL;
2036 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2037 image_create_info.format = tex_format;
2038 image_create_info.extent.width = tex_width;
2039 image_create_info.extent.height = tex_height;
2040 image_create_info.extent.depth = 1;
2041 image_create_info.mipLevels = 1;
2042 image_create_info.arrayLayers = 1;
2043 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2044 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2045 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2046 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002047
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002048 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002049 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2050 mem_alloc.pNext = NULL;
2051 mem_alloc.allocationSize = 0;
2052 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002053
Karl Schultz6addd812016-02-02 17:17:23 -07002054 // Introduce failure, do NOT set memProps to
2055 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002056 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002057 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002058 ASSERT_VK_SUCCESS(err);
2059
Karl Schultz6addd812016-02-02 17:17:23 -07002060 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002061
2062 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002063 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002064 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002065
2066 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002067 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002068 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002069 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002070 ASSERT_VK_SUCCESS(err);
2071
2072 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002073 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002074 ASSERT_VK_SUCCESS(err);
2075
Karl Schultz6addd812016-02-02 17:17:23 -07002076 // Introduce validation failure, try to bind a different memory object to
2077 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002078 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002079
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002080 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002081
Chia-I Wuf7458c52015-10-26 21:10:41 +08002082 vkDestroyImage(m_device->device(), image, NULL);
2083 vkFreeMemory(m_device->device(), mem1, NULL);
2084 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002085}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002086
Karl Schultz6addd812016-02-02 17:17:23 -07002087TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002088 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002089
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2091 "submitted in SIGNALED state. Fences "
2092 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002093
2094 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002095 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2096 fenceInfo.pNext = NULL;
2097 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002098
Tony Barbour300a6082015-04-07 13:44:53 -06002099 ASSERT_NO_FATAL_FAILURE(InitState());
2100 ASSERT_NO_FATAL_FAILURE(InitViewport());
2101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2102
Tony Barbour552f6c02016-12-21 14:34:07 -07002103 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002104 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002105 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002106
2107 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002108
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002109 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002110 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2111 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002112 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002113 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002114 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002115 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002116 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002117 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002118 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002119
2120 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002121 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002122
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002123 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002124}
Chris Forbes4e44c912016-06-16 10:20:00 +12002125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002126TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002127 TEST_DESCRIPTION(
2128 "Specify wrong usage for image then create conflicting view of image "
2129 "Initialize buffer with wrong usage then perform copy expecting errors "
2130 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002132
2133 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002134
2135 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2136
Tony Barbourf92621a2016-05-02 14:28:12 -06002137 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002138 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002139 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002140 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002141
Tony Barbourf92621a2016-05-02 14:28:12 -06002142 VkImageView dsv;
2143 VkImageViewCreateInfo dsvci = {};
2144 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2145 dsvci.image = image.handle();
2146 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002147 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002148 dsvci.subresourceRange.layerCount = 1;
2149 dsvci.subresourceRange.baseMipLevel = 0;
2150 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002151 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002152
Tony Barbourf92621a2016-05-02 14:28:12 -06002153 // Create a view with depth / stencil aspect for image with different usage
2154 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002155
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002156 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002157
2158 // Initialize buffer with TRANSFER_DST usage
2159 vk_testing::Buffer buffer;
2160 VkMemoryPropertyFlags reqs = 0;
2161 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2162 VkBufferImageCopy region = {};
2163 region.bufferRowLength = 128;
2164 region.bufferImageHeight = 128;
2165 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2166 region.imageSubresource.layerCount = 1;
2167 region.imageExtent.height = 16;
2168 region.imageExtent.width = 16;
2169 region.imageExtent.depth = 1;
2170
Tony Barbourf92621a2016-05-02 14:28:12 -06002171 // Buffer usage not set to TRANSFER_SRC and image usage not set to
2172 // TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002173 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002174
Chris Forbesda581202016-10-06 18:25:26 +13002175 // two separate errors from this call:
2176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2178
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002179 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2180 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002181 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002182}
Tony Barbour75d79f02016-08-30 09:39:07 -06002183
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002184TEST_F(VkLayerTest, LeakAnObject) {
2185 VkResult err;
2186
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002187 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002188
2189 // Note that we have to create a new device since destroying the
2190 // framework's device causes Teardown() to fail and just calling Teardown
2191 // will destroy the errorMonitor.
2192
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002194
2195 ASSERT_NO_FATAL_FAILURE(InitState());
2196
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002197 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002198 std::vector<VkDeviceQueueCreateInfo> queue_info;
2199 queue_info.reserve(queue_props.size());
2200 std::vector<std::vector<float>> queue_priorities;
2201 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2202 VkDeviceQueueCreateInfo qi = {};
2203 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2204 qi.pNext = NULL;
2205 qi.queueFamilyIndex = i;
2206 qi.queueCount = queue_props[i].queueCount;
2207 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2208 qi.pQueuePriorities = queue_priorities[i].data();
2209 queue_info.push_back(qi);
2210 }
2211
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002212 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002213
2214 // The sacrificial device object
2215 VkDevice testDevice;
2216 VkDeviceCreateInfo device_create_info = {};
2217 auto features = m_device->phy().features();
2218 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2219 device_create_info.pNext = NULL;
2220 device_create_info.queueCreateInfoCount = queue_info.size();
2221 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002222 device_create_info.enabledLayerCount = 0;
2223 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002224 device_create_info.pEnabledFeatures = &features;
2225 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2226 ASSERT_VK_SUCCESS(err);
2227
2228 VkFence fence;
2229 VkFenceCreateInfo fence_create_info = {};
2230 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2231 fence_create_info.pNext = NULL;
2232 fence_create_info.flags = 0;
2233 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2234 ASSERT_VK_SUCCESS(err);
2235
2236 // Induce failure by not calling vkDestroyFence
2237 vkDestroyDevice(testDevice, NULL);
2238 m_errorMonitor->VerifyFound();
2239}
2240
2241TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002242 TEST_DESCRIPTION(
2243 "Allocate command buffers from one command pool and "
2244 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002245
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002247
Cody Northropc31a84f2016-08-22 10:41:47 -06002248 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002249 VkCommandPool command_pool_one;
2250 VkCommandPool command_pool_two;
2251
2252 VkCommandPoolCreateInfo pool_create_info{};
2253 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2254 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2255 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2256
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002257 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002258
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002259 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002260
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002261 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002262 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002263 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002264 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002265 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002266 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002267 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002268
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002269 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002270
2271 m_errorMonitor->VerifyFound();
2272
2273 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2274 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2275}
2276
2277TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2278 VkResult err;
2279
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002280 TEST_DESCRIPTION(
2281 "Allocate descriptor sets from one DS pool and "
2282 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002283
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002285
2286 ASSERT_NO_FATAL_FAILURE(InitState());
2287 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2288
2289 VkDescriptorPoolSize ds_type_count = {};
2290 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2291 ds_type_count.descriptorCount = 1;
2292
2293 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2294 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2295 ds_pool_ci.pNext = NULL;
2296 ds_pool_ci.flags = 0;
2297 ds_pool_ci.maxSets = 1;
2298 ds_pool_ci.poolSizeCount = 1;
2299 ds_pool_ci.pPoolSizes = &ds_type_count;
2300
2301 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002302 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002303 ASSERT_VK_SUCCESS(err);
2304
2305 // Create a second descriptor pool
2306 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002307 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002308 ASSERT_VK_SUCCESS(err);
2309
2310 VkDescriptorSetLayoutBinding dsl_binding = {};
2311 dsl_binding.binding = 0;
2312 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2313 dsl_binding.descriptorCount = 1;
2314 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2315 dsl_binding.pImmutableSamplers = NULL;
2316
2317 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2318 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2319 ds_layout_ci.pNext = NULL;
2320 ds_layout_ci.bindingCount = 1;
2321 ds_layout_ci.pBindings = &dsl_binding;
2322
2323 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002325 ASSERT_VK_SUCCESS(err);
2326
2327 VkDescriptorSet descriptorSet;
2328 VkDescriptorSetAllocateInfo alloc_info = {};
2329 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2330 alloc_info.descriptorSetCount = 1;
2331 alloc_info.descriptorPool = ds_pool_one;
2332 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002333 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002334 ASSERT_VK_SUCCESS(err);
2335
2336 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2337
2338 m_errorMonitor->VerifyFound();
2339
2340 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2341 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2342 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2343}
2344
2345TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002347
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002348 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002349
2350 ASSERT_NO_FATAL_FAILURE(InitState());
2351
2352 // Pass bogus handle into GetImageMemoryRequirements
2353 VkMemoryRequirements mem_reqs;
2354 uint64_t fakeImageHandle = 0xCADECADE;
2355 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2356
2357 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2358
2359 m_errorMonitor->VerifyFound();
2360}
2361
Karl Schultz6addd812016-02-02 17:17:23 -07002362TEST_F(VkLayerTest, PipelineNotBound) {
2363 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002364
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002365 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002366
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002368
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002369 ASSERT_NO_FATAL_FAILURE(InitState());
2370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002371
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002372 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002373 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2374 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002375
2376 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002377 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2378 ds_pool_ci.pNext = NULL;
2379 ds_pool_ci.maxSets = 1;
2380 ds_pool_ci.poolSizeCount = 1;
2381 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002382
2383 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002384 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002385 ASSERT_VK_SUCCESS(err);
2386
2387 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002388 dsl_binding.binding = 0;
2389 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2390 dsl_binding.descriptorCount = 1;
2391 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2392 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002393
2394 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002395 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2396 ds_layout_ci.pNext = NULL;
2397 ds_layout_ci.bindingCount = 1;
2398 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002399
2400 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002401 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002402 ASSERT_VK_SUCCESS(err);
2403
2404 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002405 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002406 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002407 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002408 alloc_info.descriptorPool = ds_pool;
2409 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002410 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002411 ASSERT_VK_SUCCESS(err);
2412
2413 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002414 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2415 pipeline_layout_ci.pNext = NULL;
2416 pipeline_layout_ci.setLayoutCount = 1;
2417 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002418
2419 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002420 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002421 ASSERT_VK_SUCCESS(err);
2422
Mark Youngad779052016-01-06 14:26:04 -07002423 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002424
Tony Barbour552f6c02016-12-21 14:34:07 -07002425 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002426 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002427
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002428 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002429
Chia-I Wuf7458c52015-10-26 21:10:41 +08002430 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2431 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2432 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002433}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002434
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002435TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2436 VkResult err;
2437
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002438 TEST_DESCRIPTION(
2439 "Test validation check for an invalid memory type index "
2440 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002441
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002442 ASSERT_NO_FATAL_FAILURE(InitState());
2443
2444 // Create an image, allocate memory, set a bad typeIndex and then try to
2445 // bind it
2446 VkImage image;
2447 VkDeviceMemory mem;
2448 VkMemoryRequirements mem_reqs;
2449 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2450 const int32_t tex_width = 32;
2451 const int32_t tex_height = 32;
2452
2453 VkImageCreateInfo image_create_info = {};
2454 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2455 image_create_info.pNext = NULL;
2456 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2457 image_create_info.format = tex_format;
2458 image_create_info.extent.width = tex_width;
2459 image_create_info.extent.height = tex_height;
2460 image_create_info.extent.depth = 1;
2461 image_create_info.mipLevels = 1;
2462 image_create_info.arrayLayers = 1;
2463 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2464 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2465 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2466 image_create_info.flags = 0;
2467
2468 VkMemoryAllocateInfo mem_alloc = {};
2469 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2470 mem_alloc.pNext = NULL;
2471 mem_alloc.allocationSize = 0;
2472 mem_alloc.memoryTypeIndex = 0;
2473
2474 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2475 ASSERT_VK_SUCCESS(err);
2476
2477 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2478 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002479
2480 // Introduce Failure, select invalid TypeIndex
2481 VkPhysicalDeviceMemoryProperties memory_info;
2482
2483 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2484 unsigned int i;
2485 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2486 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2487 mem_alloc.memoryTypeIndex = i;
2488 break;
2489 }
2490 }
2491 if (i >= memory_info.memoryTypeCount) {
2492 printf("No invalid memory type index could be found; skipped.\n");
2493 vkDestroyImage(m_device->device(), image, NULL);
2494 return;
2495 }
2496
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002497 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 -06002498
2499 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2500 ASSERT_VK_SUCCESS(err);
2501
2502 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2503 (void)err;
2504
2505 m_errorMonitor->VerifyFound();
2506
2507 vkDestroyImage(m_device->device(), image, NULL);
2508 vkFreeMemory(m_device->device(), mem, NULL);
2509}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002510
Karl Schultz6addd812016-02-02 17:17:23 -07002511TEST_F(VkLayerTest, BindInvalidMemory) {
2512 VkResult err;
2513 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002514
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002516
Tobin Ehlisec598302015-09-15 15:02:17 -06002517 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002518
2519 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002520 VkImage image;
2521 VkDeviceMemory mem;
2522 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002523
Karl Schultz6addd812016-02-02 17:17:23 -07002524 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2525 const int32_t tex_width = 32;
2526 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002527
2528 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002529 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2530 image_create_info.pNext = NULL;
2531 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2532 image_create_info.format = tex_format;
2533 image_create_info.extent.width = tex_width;
2534 image_create_info.extent.height = tex_height;
2535 image_create_info.extent.depth = 1;
2536 image_create_info.mipLevels = 1;
2537 image_create_info.arrayLayers = 1;
2538 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2539 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2540 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2541 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002542
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002543 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002544 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2545 mem_alloc.pNext = NULL;
2546 mem_alloc.allocationSize = 0;
2547 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002548
Chia-I Wuf7458c52015-10-26 21:10:41 +08002549 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002550 ASSERT_VK_SUCCESS(err);
2551
Karl Schultz6addd812016-02-02 17:17:23 -07002552 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002553
2554 mem_alloc.allocationSize = mem_reqs.size;
2555
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002556 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002557 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002558
2559 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002560 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002561 ASSERT_VK_SUCCESS(err);
2562
2563 // Introduce validation failure, free memory before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002564 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002565
2566 // Try to bind free memory that has been freed
2567 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2568 // This may very well return an error.
2569 (void)err;
2570
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002571 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002572
Chia-I Wuf7458c52015-10-26 21:10:41 +08002573 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002574}
2575
Karl Schultz6addd812016-02-02 17:17:23 -07002576TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2577 VkResult err;
2578 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002579
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002580 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002581
Tobin Ehlisec598302015-09-15 15:02:17 -06002582 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002583
Karl Schultz6addd812016-02-02 17:17:23 -07002584 // Create an image object, allocate memory, destroy the object and then try
2585 // to bind it
2586 VkImage image;
2587 VkDeviceMemory mem;
2588 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002589
Karl Schultz6addd812016-02-02 17:17:23 -07002590 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2591 const int32_t tex_width = 32;
2592 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002593
2594 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002595 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2596 image_create_info.pNext = NULL;
2597 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2598 image_create_info.format = tex_format;
2599 image_create_info.extent.width = tex_width;
2600 image_create_info.extent.height = tex_height;
2601 image_create_info.extent.depth = 1;
2602 image_create_info.mipLevels = 1;
2603 image_create_info.arrayLayers = 1;
2604 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2605 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2606 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2607 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002608
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002609 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002610 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2611 mem_alloc.pNext = NULL;
2612 mem_alloc.allocationSize = 0;
2613 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002614
Chia-I Wuf7458c52015-10-26 21:10:41 +08002615 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002616 ASSERT_VK_SUCCESS(err);
2617
Karl Schultz6addd812016-02-02 17:17:23 -07002618 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002619
2620 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002621 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002622 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002623
2624 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002625 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002626 ASSERT_VK_SUCCESS(err);
2627
2628 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002629 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002630 ASSERT_VK_SUCCESS(err);
2631
2632 // Now Try to bind memory to this destroyed object
2633 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2634 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002635 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002636
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002637 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002638
Chia-I Wuf7458c52015-10-26 21:10:41 +08002639 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002640}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002641
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002642TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2643 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2644
2645 ASSERT_NO_FATAL_FAILURE(InitState());
2646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2647
2648 VkVertexInputBindingDescription input_binding;
2649 memset(&input_binding, 0, sizeof(input_binding));
2650
2651 VkVertexInputAttributeDescription input_attribs;
2652 memset(&input_attribs, 0, sizeof(input_attribs));
2653
2654 // Pick a really bad format for this purpose and make sure it should fail
2655 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2656 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2657 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
2658 printf("Format unsuitable for test; skipped.\n");
2659 return;
2660 }
2661
2662 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002663 char const *vsSource =
2664 "#version 450\n"
2665 "\n"
2666 "out gl_PerVertex {\n"
2667 " vec4 gl_Position;\n"
2668 "};\n"
2669 "void main(){\n"
2670 " gl_Position = vec4(1);\n"
2671 "}\n";
2672 char const *fsSource =
2673 "#version 450\n"
2674 "\n"
2675 "layout(location=0) out vec4 color;\n"
2676 "void main(){\n"
2677 " color = vec4(1);\n"
2678 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002679
2680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2681 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2682 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2683
2684 VkPipelineObj pipe(m_device);
2685 pipe.AddColorAttachment();
2686 pipe.AddShader(&vs);
2687 pipe.AddShader(&fs);
2688
2689 pipe.AddVertexInputBindings(&input_binding, 1);
2690 pipe.AddVertexInputAttribs(&input_attribs, 1);
2691
2692 VkDescriptorSetObj descriptorSet(m_device);
2693 descriptorSet.AppendDummy();
2694 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
2695
2696 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
2697
2698 m_errorMonitor->VerifyFound();
2699}
2700
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002701TEST_F(VkLayerTest, ImageSampleCounts) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002702 TEST_DESCRIPTION(
2703 "Use bad sample counts in image transfer calls to trigger "
2704 "validation errors.");
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002705 ASSERT_NO_FATAL_FAILURE(InitState());
2706
2707 VkMemoryPropertyFlags reqs = 0;
2708 VkImageCreateInfo image_create_info = {};
2709 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2710 image_create_info.pNext = NULL;
2711 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2712 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2713 image_create_info.extent.width = 256;
2714 image_create_info.extent.height = 256;
2715 image_create_info.extent.depth = 1;
2716 image_create_info.mipLevels = 1;
2717 image_create_info.arrayLayers = 1;
2718 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2719 image_create_info.flags = 0;
2720
2721 VkImageBlit blit_region = {};
2722 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2723 blit_region.srcSubresource.baseArrayLayer = 0;
2724 blit_region.srcSubresource.layerCount = 1;
2725 blit_region.srcSubresource.mipLevel = 0;
2726 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2727 blit_region.dstSubresource.baseArrayLayer = 0;
2728 blit_region.dstSubresource.layerCount = 1;
2729 blit_region.dstSubresource.mipLevel = 0;
2730
2731 // Create two images, the source with sampleCount = 2, and attempt to blit
2732 // between them
2733 {
2734 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002735 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002736 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002737 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002738 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002739 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002740 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002741 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002742 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2744 "was created with a sample count "
2745 "of VK_SAMPLE_COUNT_2_BIT but "
2746 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002747 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2748 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002749 m_errorMonitor->VerifyFound();
2750 m_commandBuffer->EndCommandBuffer();
2751 }
2752
2753 // Create two images, the dest with sampleCount = 4, and attempt to blit
2754 // between them
2755 {
2756 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002757 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002758 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002759 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002760 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002761 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002762 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002763 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002764 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2766 "was created with a sample count "
2767 "of VK_SAMPLE_COUNT_4_BIT but "
2768 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002769 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
2770 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002771 m_errorMonitor->VerifyFound();
2772 m_commandBuffer->EndCommandBuffer();
2773 }
2774
2775 VkBufferImageCopy copy_region = {};
2776 copy_region.bufferRowLength = 128;
2777 copy_region.bufferImageHeight = 128;
2778 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2779 copy_region.imageSubresource.layerCount = 1;
2780 copy_region.imageExtent.height = 64;
2781 copy_region.imageExtent.width = 64;
2782 copy_region.imageExtent.depth = 1;
2783
2784 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
2785 // buffer to image
2786 {
2787 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002788 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
2789 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002790 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002791 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002792 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002793 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2795 "was created with a sample count "
2796 "of VK_SAMPLE_COUNT_8_BIT but "
2797 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002798 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
2799 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002800 m_errorMonitor->VerifyFound();
2801 m_commandBuffer->EndCommandBuffer();
2802 }
2803
2804 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
2805 // image to buffer
2806 {
2807 vk_testing::Buffer dst_buffer;
2808 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
2809 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002810 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002811 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002812 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002813 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2815 "was created with a sample count "
2816 "of VK_SAMPLE_COUNT_2_BIT but "
2817 "must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002818 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06002819 dst_buffer.handle(), 1, &copy_region);
2820 m_errorMonitor->VerifyFound();
2821 m_commandBuffer->EndCommandBuffer();
2822 }
2823}
2824
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002825TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002826 ASSERT_NO_FATAL_FAILURE(InitState());
2827
2828 VkImageObj src_image(m_device);
2829 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
2830 VkImageObj dst_image(m_device);
2831 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
2832 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06002833 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 -06002834
2835 VkImageBlit blitRegion = {};
2836 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2837 blitRegion.srcSubresource.baseArrayLayer = 0;
2838 blitRegion.srcSubresource.layerCount = 1;
2839 blitRegion.srcSubresource.mipLevel = 0;
2840 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2841 blitRegion.dstSubresource.baseArrayLayer = 0;
2842 blitRegion.dstSubresource.layerCount = 1;
2843 blitRegion.dstSubresource.mipLevel = 0;
2844
Dave Houlton34df4cb2016-12-01 16:43:06 -07002845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
2846
2847 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
2848 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002849
2850 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07002851 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002852 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
2853 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002854
2855 m_errorMonitor->VerifyFound();
2856
Dave Houlton34df4cb2016-12-01 16:43:06 -07002857 // Test should generate 2 VU failures
2858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
2859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002860
2861 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07002862 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
2863 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002864
Dave Houlton34df4cb2016-12-01 16:43:06 -07002865 // TODO: Note that this only verifies that at least one of the VU enums was found
2866 // 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 -06002867 m_errorMonitor->VerifyFound();
2868
Tony Barbour552f6c02016-12-21 14:34:07 -07002869 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06002870}
2871
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002872TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
2873 VkResult err;
2874 bool pass;
2875
2876 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
2877 ASSERT_NO_FATAL_FAILURE(InitState());
2878
2879 // If w/d/h granularity is 1, test is not meaningful
2880 // TODO: When virtual device limits are available, create a set of limits for this test that
2881 // will always have a granularity of > 1 for w, h, and d
2882 auto index = m_device->graphics_queue_node_index_;
2883 auto queue_family_properties = m_device->phy().queue_properties();
2884
2885 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
2886 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
2887 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
2888 return;
2889 }
2890
2891 // Create two images of different types and try to copy between them
2892 VkImage srcImage;
2893 VkImage dstImage;
2894 VkDeviceMemory srcMem;
2895 VkDeviceMemory destMem;
2896 VkMemoryRequirements memReqs;
2897
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002898 VkImageCreateInfo image_create_info = {};
2899 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2900 image_create_info.pNext = NULL;
2901 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2902 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
2903 image_create_info.extent.width = 32;
2904 image_create_info.extent.height = 32;
2905 image_create_info.extent.depth = 1;
2906 image_create_info.mipLevels = 1;
2907 image_create_info.arrayLayers = 4;
2908 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2909 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2910 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2911 image_create_info.flags = 0;
2912
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002913 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002914 ASSERT_VK_SUCCESS(err);
2915
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002916 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002917 ASSERT_VK_SUCCESS(err);
2918
2919 // Allocate memory
2920 VkMemoryAllocateInfo memAlloc = {};
2921 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2922 memAlloc.pNext = NULL;
2923 memAlloc.allocationSize = 0;
2924 memAlloc.memoryTypeIndex = 0;
2925
2926 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
2927 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002928 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002929 ASSERT_TRUE(pass);
2930 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
2931 ASSERT_VK_SUCCESS(err);
2932
2933 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
2934 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002935 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002936 ASSERT_VK_SUCCESS(err);
2937 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
2938 ASSERT_VK_SUCCESS(err);
2939
2940 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
2941 ASSERT_VK_SUCCESS(err);
2942 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
2943 ASSERT_VK_SUCCESS(err);
2944
Tony Barbour552f6c02016-12-21 14:34:07 -07002945 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002946 VkImageCopy copyRegion;
2947 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2948 copyRegion.srcSubresource.mipLevel = 0;
2949 copyRegion.srcSubresource.baseArrayLayer = 0;
2950 copyRegion.srcSubresource.layerCount = 1;
2951 copyRegion.srcOffset.x = 0;
2952 copyRegion.srcOffset.y = 0;
2953 copyRegion.srcOffset.z = 0;
2954 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2955 copyRegion.dstSubresource.mipLevel = 0;
2956 copyRegion.dstSubresource.baseArrayLayer = 0;
2957 copyRegion.dstSubresource.layerCount = 1;
2958 copyRegion.dstOffset.x = 0;
2959 copyRegion.dstOffset.y = 0;
2960 copyRegion.dstOffset.z = 0;
2961 copyRegion.extent.width = 1;
2962 copyRegion.extent.height = 1;
2963 copyRegion.extent.depth = 1;
2964
2965 // Introduce failure by setting srcOffset to a bad granularity value
2966 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2968 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002969 m_errorMonitor->VerifyFound();
2970
2971 // Introduce failure by setting extent to a bad granularity value
2972 copyRegion.srcOffset.y = 0;
2973 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2975 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06002976 m_errorMonitor->VerifyFound();
2977
2978 // Now do some buffer/image copies
2979 vk_testing::Buffer buffer;
2980 VkMemoryPropertyFlags reqs = 0;
2981 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2982 VkBufferImageCopy region = {};
2983 region.bufferOffset = 0;
2984 region.bufferRowLength = 3;
2985 region.bufferImageHeight = 128;
2986 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
2987 region.imageSubresource.layerCount = 1;
2988 region.imageExtent.height = 16;
2989 region.imageExtent.width = 16;
2990 region.imageExtent.depth = 1;
2991 region.imageOffset.x = 0;
2992 region.imageOffset.y = 0;
2993 region.imageOffset.z = 0;
2994
2995 // Introduce failure by setting bufferRowLength to a bad granularity value
2996 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
2998 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
2999 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003000 m_errorMonitor->VerifyFound();
3001 region.bufferRowLength = 128;
3002
3003 // Introduce failure by setting bufferOffset to a bad granularity value
3004 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3006 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3007 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003008 m_errorMonitor->VerifyFound();
3009 region.bufferOffset = 0;
3010
3011 // Introduce failure by setting bufferImageHeight to a bad granularity value
3012 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3014 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3015 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003016 m_errorMonitor->VerifyFound();
3017 region.bufferImageHeight = 128;
3018
3019 // Introduce failure by setting imageExtent to a bad granularity value
3020 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3022 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3023 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003024 m_errorMonitor->VerifyFound();
3025 region.imageExtent.width = 16;
3026
3027 // Introduce failure by setting imageOffset to a bad granularity value
3028 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003029 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3030 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3031 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003032 m_errorMonitor->VerifyFound();
3033
Tony Barbour552f6c02016-12-21 14:34:07 -07003034 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003035
3036 vkDestroyImage(m_device->device(), srcImage, NULL);
3037 vkDestroyImage(m_device->device(), dstImage, NULL);
3038 vkFreeMemory(m_device->device(), srcMem, NULL);
3039 vkFreeMemory(m_device->device(), destMem, NULL);
3040}
3041
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003042TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003043 TEST_DESCRIPTION(
3044 "Submit command buffer created using one queue family and "
3045 "attempt to submit them on a queue created in a different "
3046 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003047
Cody Northropc31a84f2016-08-22 10:41:47 -06003048 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003049 // This test is meaningless unless we have multiple queue families
3050 auto queue_family_properties = m_device->phy().queue_properties();
3051 if (queue_family_properties.size() < 2) {
3052 return;
3053 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003054 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003055 // Get safe index of another queue family
3056 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3057 ASSERT_NO_FATAL_FAILURE(InitState());
3058 // Create a second queue using a different queue family
3059 VkQueue other_queue;
3060 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3061
3062 // Record an empty cmd buffer
3063 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3064 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3065 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3066 vkEndCommandBuffer(m_commandBuffer->handle());
3067
3068 // And submit on the wrong queue
3069 VkSubmitInfo submit_info = {};
3070 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3071 submit_info.commandBufferCount = 1;
3072 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003073 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003074
3075 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003076}
3077
Chris Forbes4c24a922016-11-16 08:59:10 +13003078TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3079 ASSERT_NO_FATAL_FAILURE(InitState());
3080
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003081 // There are no attachments, but refer to attachment 0.
3082 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003083 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003084 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003085 };
3086
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003087 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003088 VkRenderPass rp;
3089
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003090 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003092 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3093 m_errorMonitor->VerifyFound();
3094}
3095
Chris Forbesa58c4522016-09-28 15:19:39 +13003096TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3097 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3098 ASSERT_NO_FATAL_FAILURE(InitState());
3099
3100 // A renderpass with two subpasses, both writing the same attachment.
3101 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003102 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3103 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3104 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003105 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003106 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003107 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003108 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3109 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003110 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003111 VkSubpassDependency dep = {0,
3112 1,
3113 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3114 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3115 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3116 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3117 VK_DEPENDENCY_BY_REGION_BIT};
3118 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003119 VkRenderPass rp;
3120 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3121 ASSERT_VK_SUCCESS(err);
3122
3123 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003124 image.init_no_layout(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Chris Forbesa58c4522016-09-28 15:19:39 +13003125 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3126
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003127 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003128 VkFramebuffer fb;
3129 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3130 ASSERT_VK_SUCCESS(err);
3131
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003132 char const *vsSource =
3133 "#version 450\n"
3134 "void main() { gl_Position = vec4(1); }\n";
3135 char const *fsSource =
3136 "#version 450\n"
3137 "layout(location=0) out vec4 color;\n"
3138 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003139
3140 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3141 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3142 VkPipelineObj pipe(m_device);
3143 pipe.AddColorAttachment();
3144 pipe.AddShader(&vs);
3145 pipe.AddShader(&fs);
3146 VkViewport view_port = {};
3147 m_viewports.push_back(view_port);
3148 pipe.SetViewport(m_viewports);
3149 VkRect2D rect = {};
3150 m_scissors.push_back(rect);
3151 pipe.SetScissor(m_scissors);
3152
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003153 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003154 VkPipelineLayout pl;
3155 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3156 ASSERT_VK_SUCCESS(err);
3157 pipe.CreateVKPipeline(pl, rp);
3158
Tony Barbour552f6c02016-12-21 14:34:07 -07003159 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003160
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003161 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3162 nullptr,
3163 rp,
3164 fb,
3165 {{
3166 0, 0,
3167 },
3168 {32, 32}},
3169 0,
3170 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003171
3172 // subtest 1: bind in the wrong subpass
3173 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3174 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003176 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3177 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3178 m_errorMonitor->VerifyFound();
3179
3180 vkCmdEndRenderPass(m_commandBuffer->handle());
3181
3182 // subtest 2: bind in correct subpass, then transition to next subpass
3183 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3184 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3185 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "built for subpass 0 but used in subpass 1");
Chris Forbesa58c4522016-09-28 15:19:39 +13003187 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3188 m_errorMonitor->VerifyFound();
3189
3190 vkCmdEndRenderPass(m_commandBuffer->handle());
3191
Tony Barbour552f6c02016-12-21 14:34:07 -07003192 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003193
3194 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3195 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3196 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3197}
3198
Tony Barbour4e919972016-08-09 13:27:40 -06003199TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003200 TEST_DESCRIPTION(
3201 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3202 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003203 ASSERT_NO_FATAL_FAILURE(InitState());
3204 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3205
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3207 "Cannot execute a render pass with renderArea "
3208 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003209
3210 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3211 m_renderPassBeginInfo.renderArea.extent.width = 257;
3212 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003213 m_commandBuffer->BeginCommandBuffer();
3214 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003215 m_errorMonitor->VerifyFound();
3216}
3217
3218TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003219 TEST_DESCRIPTION(
3220 "Generate INDEPENDENT_BLEND by disabling independent "
3221 "blend and then specifying different blend states for two "
3222 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003223 VkPhysicalDeviceFeatures features = {};
3224 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003225 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3228 "Invalid Pipeline CreateInfo: If independent blend feature not "
3229 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003230
Cody Northropc31a84f2016-08-22 10:41:47 -06003231 VkDescriptorSetObj descriptorSet(m_device);
3232 descriptorSet.AppendDummy();
3233 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003234
Cody Northropc31a84f2016-08-22 10:41:47 -06003235 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003236 // Create a renderPass with two color attachments
3237 VkAttachmentReference attachments[2] = {};
3238 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3239 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3240
3241 VkSubpassDescription subpass = {};
3242 subpass.pColorAttachments = attachments;
3243 subpass.colorAttachmentCount = 2;
3244
3245 VkRenderPassCreateInfo rpci = {};
3246 rpci.subpassCount = 1;
3247 rpci.pSubpasses = &subpass;
3248 rpci.attachmentCount = 1;
3249
3250 VkAttachmentDescription attach_desc = {};
3251 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3252 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3253 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3254 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3255
3256 rpci.pAttachments = &attach_desc;
3257 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3258
3259 VkRenderPass renderpass;
3260 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003261 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003262 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003263
Cody Northropc31a84f2016-08-22 10:41:47 -06003264 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3265 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3266 att_state1.blendEnable = VK_TRUE;
3267 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3268 att_state2.blendEnable = VK_FALSE;
3269 pipeline.AddColorAttachment(0, &att_state1);
3270 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003271 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003272 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003273 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003274}
3275
Chris Forbes26ec2122016-11-29 08:58:33 +13003276#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003277TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3278 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3279 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003280 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003281
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3283 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003284
3285 // Create a renderPass with a single color attachment
3286 VkAttachmentReference attach = {};
3287 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3288 VkSubpassDescription subpass = {};
3289 VkRenderPassCreateInfo rpci = {};
3290 rpci.subpassCount = 1;
3291 rpci.pSubpasses = &subpass;
3292 rpci.attachmentCount = 1;
3293 VkAttachmentDescription attach_desc = {};
3294 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3295 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3296 rpci.pAttachments = &attach_desc;
3297 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3298 VkRenderPass rp;
3299 subpass.pDepthStencilAttachment = &attach;
3300 subpass.pColorAttachments = NULL;
3301 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3302 m_errorMonitor->VerifyFound();
3303}
Chris Forbes26ec2122016-11-29 08:58:33 +13003304#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003305
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003306TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003307 TEST_DESCRIPTION(
3308 "Create a framebuffer where a subpass has a preserve "
3309 "attachment reference of VK_ATTACHMENT_UNUSED");
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, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003315
3316 VkAttachmentReference color_attach = {};
3317 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3318 color_attach.attachment = 0;
3319 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3320 VkSubpassDescription subpass = {};
3321 subpass.colorAttachmentCount = 1;
3322 subpass.pColorAttachments = &color_attach;
3323 subpass.preserveAttachmentCount = 1;
3324 subpass.pPreserveAttachments = &preserve_attachment;
3325
3326 VkRenderPassCreateInfo rpci = {};
3327 rpci.subpassCount = 1;
3328 rpci.pSubpasses = &subpass;
3329 rpci.attachmentCount = 1;
3330 VkAttachmentDescription attach_desc = {};
3331 attach_desc.format = VK_FORMAT_UNDEFINED;
3332 rpci.pAttachments = &attach_desc;
3333 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3334 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003335 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003336
3337 m_errorMonitor->VerifyFound();
3338
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003339 if (result == VK_SUCCESS) {
3340 vkDestroyRenderPass(m_device->device(), rp, NULL);
3341 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003342}
3343
Chris Forbesc5389742016-06-29 11:49:23 +12003344TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003345 TEST_DESCRIPTION(
3346 "Ensure that CreateRenderPass produces a validation error "
3347 "when the source of a subpass multisample resolve "
3348 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003349
Chris Forbesc5389742016-06-29 11:49:23 +12003350 ASSERT_NO_FATAL_FAILURE(InitState());
3351
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3353 "Subpass 0 requests multisample resolve from attachment 0 which has "
3354 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003355
3356 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003357 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3358 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3359 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3360 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3361 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3362 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003363 };
3364
3365 VkAttachmentReference color = {
3366 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3367 };
3368
3369 VkAttachmentReference resolve = {
3370 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3371 };
3372
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003373 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003374
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003375 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003376
3377 VkRenderPass rp;
3378 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3379
3380 m_errorMonitor->VerifyFound();
3381
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003382 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003383}
3384
3385TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003386 TEST_DESCRIPTION(
3387 "Ensure CreateRenderPass produces a validation error "
3388 "when a subpass multisample resolve operation is "
3389 "requested, and the destination of that resolve has "
3390 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003391
Chris Forbesc5389742016-06-29 11:49:23 +12003392 ASSERT_NO_FATAL_FAILURE(InitState());
3393
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3395 "Subpass 0 requests multisample resolve into attachment 1, which "
3396 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003397
3398 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003399 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3400 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3401 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3402 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3403 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3404 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003405 };
3406
3407 VkAttachmentReference color = {
3408 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3409 };
3410
3411 VkAttachmentReference resolve = {
3412 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3413 };
3414
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003415 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003417 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003418
3419 VkRenderPass rp;
3420 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3421
3422 m_errorMonitor->VerifyFound();
3423
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003424 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003425}
3426
Chris Forbes3f128ef2016-06-29 14:58:53 +12003427TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003428 TEST_DESCRIPTION(
3429 "Ensure CreateRenderPass produces a validation error "
3430 "when the color and depth attachments used by a subpass "
3431 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003432
Chris Forbes3f128ef2016-06-29 14:58:53 +12003433 ASSERT_NO_FATAL_FAILURE(InitState());
3434
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003435 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3436 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003437
3438 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003439 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3440 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3441 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3442 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3443 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3444 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003445 };
3446
3447 VkAttachmentReference color[] = {
3448 {
3449 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3450 },
3451 {
3452 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3453 },
3454 };
3455
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003456 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003457
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003458 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003459
3460 VkRenderPass rp;
3461 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3462
3463 m_errorMonitor->VerifyFound();
3464
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003465 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003466}
3467
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003468TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003469 TEST_DESCRIPTION(
3470 "Hit errors when attempting to create a framebuffer :\n"
3471 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3472 " 2. Use a color image as depthStencil attachment\n"
3473 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3474 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3475 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3476 " 6. Framebuffer attachment where dimensions don't match\n"
3477 " 7. Framebuffer attachment w/o identity swizzle\n"
3478 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003479
3480 ASSERT_NO_FATAL_FAILURE(InitState());
3481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3484 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 "
3485 "does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003486
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003487 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003488 VkAttachmentReference attach = {};
3489 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3490 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003491 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003492 VkRenderPassCreateInfo rpci = {};
3493 rpci.subpassCount = 1;
3494 rpci.pSubpasses = &subpass;
3495 rpci.attachmentCount = 1;
3496 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003497 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003498 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003499 rpci.pAttachments = &attach_desc;
3500 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3501 VkRenderPass rp;
3502 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3503 ASSERT_VK_SUCCESS(err);
3504
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003505 VkImageView ivs[2];
3506 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3507 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003508 VkFramebufferCreateInfo fb_info = {};
3509 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3510 fb_info.pNext = NULL;
3511 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003512 // Set mis-matching attachmentCount
3513 fb_info.attachmentCount = 2;
3514 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003515 fb_info.width = 100;
3516 fb_info.height = 100;
3517 fb_info.layers = 1;
3518
3519 VkFramebuffer fb;
3520 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3521
3522 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003523 if (err == VK_SUCCESS) {
3524 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3525 }
3526 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003527
3528 // Create a renderPass with a depth-stencil attachment created with
3529 // IMAGE_USAGE_COLOR_ATTACHMENT
3530 // Add our color attachment to pDepthStencilAttachment
3531 subpass.pDepthStencilAttachment = &attach;
3532 subpass.pColorAttachments = NULL;
3533 VkRenderPass rp_ds;
3534 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3535 ASSERT_VK_SUCCESS(err);
3536 // Set correct attachment count, but attachment has COLOR usage bit set
3537 fb_info.attachmentCount = 1;
3538 fb_info.renderPass = rp_ds;
3539
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003541 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3542
3543 m_errorMonitor->VerifyFound();
3544 if (err == VK_SUCCESS) {
3545 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3546 }
3547 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003548
3549 // Create new renderpass with alternate attachment format from fb
3550 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3551 subpass.pDepthStencilAttachment = NULL;
3552 subpass.pColorAttachments = &attach;
3553 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3554 ASSERT_VK_SUCCESS(err);
3555
3556 // Cause error due to mis-matched formats between rp & fb
3557 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3558 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3560 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003561 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3562
3563 m_errorMonitor->VerifyFound();
3564 if (err == VK_SUCCESS) {
3565 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3566 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003567 vkDestroyRenderPass(m_device->device(), rp, NULL);
3568
3569 // Create new renderpass with alternate sample count from fb
3570 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3571 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3572 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3573 ASSERT_VK_SUCCESS(err);
3574
3575 // Cause error due to mis-matched sample count between rp & fb
3576 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3578 " has VK_SAMPLE_COUNT_1_BIT samples "
3579 "that do not match the "
3580 "VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003581 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3582
3583 m_errorMonitor->VerifyFound();
3584 if (err == VK_SUCCESS) {
3585 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3586 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003587
3588 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003589
3590 // Create a custom imageView with non-1 mip levels
3591 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003592 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 -06003593 ASSERT_TRUE(image.initialized());
3594
3595 VkImageView view;
3596 VkImageViewCreateInfo ivci = {};
3597 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3598 ivci.image = image.handle();
3599 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3600 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3601 ivci.subresourceRange.layerCount = 1;
3602 ivci.subresourceRange.baseMipLevel = 0;
3603 // Set level count 2 (only 1 is allowed for FB attachment)
3604 ivci.subresourceRange.levelCount = 2;
3605 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3606 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3607 ASSERT_VK_SUCCESS(err);
3608 // Re-create renderpass to have matching sample count
3609 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3610 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3611 ASSERT_VK_SUCCESS(err);
3612
3613 fb_info.renderPass = rp;
3614 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003615 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003616 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3617
3618 m_errorMonitor->VerifyFound();
3619 if (err == VK_SUCCESS) {
3620 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3621 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003622 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003623 // Update view to original color buffer and grow FB dimensions too big
3624 fb_info.pAttachments = ivs;
3625 fb_info.height = 1024;
3626 fb_info.width = 1024;
3627 fb_info.layers = 2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003628 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3629 " Attachment dimensions must be at "
3630 "least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003631 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3632
3633 m_errorMonitor->VerifyFound();
3634 if (err == VK_SUCCESS) {
3635 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3636 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003637 // Create view attachment with non-identity swizzle
3638 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3639 ivci.image = image.handle();
3640 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3641 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3642 ivci.subresourceRange.layerCount = 1;
3643 ivci.subresourceRange.baseMipLevel = 0;
3644 ivci.subresourceRange.levelCount = 1;
3645 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3646 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3647 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3648 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3649 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3650 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3651 ASSERT_VK_SUCCESS(err);
3652
3653 fb_info.pAttachments = &view;
3654 fb_info.height = 100;
3655 fb_info.width = 100;
3656 fb_info.layers = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3658 " has non-identy swizzle. All "
3659 "framebuffer attachments must have "
3660 "been created with the identity "
3661 "swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003662 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3663
3664 m_errorMonitor->VerifyFound();
3665 if (err == VK_SUCCESS) {
3666 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3667 }
3668 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003669 // reset attachment to color attachment
3670 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003671
3672 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003673 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003674 fb_info.height = 100;
3675 fb_info.layers = 1;
3676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
3677 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3678
3679 m_errorMonitor->VerifyFound();
3680 if (err == VK_SUCCESS) {
3681 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3682 }
3683
3684 // Request fb that exceeds max height
3685 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003686 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003687 fb_info.layers = 1;
3688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
3689 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3690
3691 m_errorMonitor->VerifyFound();
3692 if (err == VK_SUCCESS) {
3693 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3694 }
3695
3696 // Request fb that exceeds max layers
3697 fb_info.width = 100;
3698 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003699 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003701 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3702
3703 m_errorMonitor->VerifyFound();
3704 if (err == VK_SUCCESS) {
3705 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3706 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003707
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003708 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003709}
3710
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003711TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003712 TEST_DESCRIPTION(
3713 "Run a simple draw calls to validate failure when Depth Bias dynamic "
3714 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003715
Cody Northropc31a84f2016-08-22 10:41:47 -06003716 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003717 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003718 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
3719 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003720 m_errorMonitor->VerifyFound();
3721}
3722
3723TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003724 TEST_DESCRIPTION(
3725 "Run a simple draw calls to validate failure when Line Width dynamic "
3726 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003727
Cody Northropc31a84f2016-08-22 10:41:47 -06003728 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003729 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
3731 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003732 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003733}
3734
3735TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003736 TEST_DESCRIPTION(
3737 "Run a simple draw calls to validate failure when Viewport dynamic "
3738 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003739
Cody Northropc31a84f2016-08-22 10:41:47 -06003740 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003741 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003742 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3743 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003744 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003745 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003746}
3747
3748TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003749 TEST_DESCRIPTION(
3750 "Run a simple draw calls to validate failure when Scissor dynamic "
3751 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003752
Cody Northropc31a84f2016-08-22 10:41:47 -06003753 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003754 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003755 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3756 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003757 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003758 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003759}
3760
Cortd713fe82016-07-27 09:51:27 -07003761TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003762 TEST_DESCRIPTION(
3763 "Run a simple draw calls to validate failure when Blend Constants "
3764 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003765
3766 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003767 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3769 "Dynamic blend constants state not set for this command buffer");
3770 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06003771 m_errorMonitor->VerifyFound();
3772}
3773
3774TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003775 TEST_DESCRIPTION(
3776 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
3777 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003778
3779 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06003780 if (!m_device->phy().features().depthBounds) {
3781 printf("Device does not support depthBounds test; skipped.\n");
3782 return;
3783 }
3784 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3786 "Dynamic depth bounds state not set for this command buffer");
3787 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003788 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003789}
3790
3791TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003792 TEST_DESCRIPTION(
3793 "Run a simple draw calls to validate failure when Stencil Read dynamic "
3794 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003795
3796 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003797 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3799 "Dynamic stencil read mask state not set for this command buffer");
3800 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003801 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003802}
3803
3804TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003805 TEST_DESCRIPTION(
3806 "Run a simple draw calls to validate failure when Stencil Write dynamic"
3807 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003808
3809 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003810 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3812 "Dynamic stencil write mask state not set for this command buffer");
3813 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003814 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06003815}
3816
3817TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003818 TEST_DESCRIPTION(
3819 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
3820 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003821
3822 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06003823 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3825 "Dynamic stencil reference state not set for this command buffer");
3826 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003827 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06003828}
3829
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003830TEST_F(VkLayerTest, IndexBufferNotBound) {
3831 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06003832
3833 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3835 "Index buffer object not bound to this command buffer when Indexed ");
3836 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06003837 m_errorMonitor->VerifyFound();
3838}
3839
Karl Schultz6addd812016-02-02 17:17:23 -07003840TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3842 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
3843 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003844
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003845 ASSERT_NO_FATAL_FAILURE(InitState());
3846 ASSERT_NO_FATAL_FAILURE(InitViewport());
3847 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3848
Karl Schultz6addd812016-02-02 17:17:23 -07003849 // We luck out b/c by default the framework creates CB w/ the
3850 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07003851 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003852 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07003853 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003854
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003855 // Bypass framework since it does the waits automatically
3856 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003857 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08003858 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3859 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003860 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003861 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07003862 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08003863 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08003864 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08003865 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06003866 submit_info.pSignalSemaphores = NULL;
3867
Chris Forbes40028e22016-06-13 09:59:34 +12003868 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07003869 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003870 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003871
Karl Schultz6addd812016-02-02 17:17:23 -07003872 // Cause validation error by re-submitting cmd buffer that should only be
3873 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12003874 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07003875 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003876
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003877 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06003878}
3879
Karl Schultz6addd812016-02-02 17:17:23 -07003880TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003881 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07003882 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003883
3884 ASSERT_NO_FATAL_FAILURE(InitState());
3885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003886
Karl Schultz6addd812016-02-02 17:17:23 -07003887 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
3888 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003889 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003890 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003891 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003892
3893 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003894 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3895 ds_pool_ci.pNext = NULL;
3896 ds_pool_ci.flags = 0;
3897 ds_pool_ci.maxSets = 1;
3898 ds_pool_ci.poolSizeCount = 1;
3899 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003900
3901 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003902 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003903 ASSERT_VK_SUCCESS(err);
3904
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003905 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
3906 dsl_binding_samp.binding = 0;
3907 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
3908 dsl_binding_samp.descriptorCount = 1;
3909 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
3910 dsl_binding_samp.pImmutableSamplers = NULL;
3911
3912 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
3913 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3914 ds_layout_ci.pNext = NULL;
3915 ds_layout_ci.bindingCount = 1;
3916 ds_layout_ci.pBindings = &dsl_binding_samp;
3917
3918 VkDescriptorSetLayout ds_layout_samp;
3919 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
3920 ASSERT_VK_SUCCESS(err);
3921
3922 // Try to allocate 2 sets when pool only has 1 set
3923 VkDescriptorSet descriptor_sets[2];
3924 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
3925 VkDescriptorSetAllocateInfo alloc_info = {};
3926 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
3927 alloc_info.descriptorSetCount = 2;
3928 alloc_info.descriptorPool = ds_pool;
3929 alloc_info.pSetLayouts = set_layouts;
3930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
3931 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
3932 m_errorMonitor->VerifyFound();
3933
3934 alloc_info.descriptorSetCount = 1;
3935 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003936 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003937 dsl_binding.binding = 0;
3938 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3939 dsl_binding.descriptorCount = 1;
3940 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3941 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003942
Karl Schultz6addd812016-02-02 17:17:23 -07003943 ds_layout_ci.bindingCount = 1;
3944 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003945
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003946 VkDescriptorSetLayout ds_layout_ub;
3947 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003948 ASSERT_VK_SUCCESS(err);
3949
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003950 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07003951 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003952 alloc_info.pSetLayouts = &ds_layout_ub;
3953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
3954 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003955
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003956 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003957
Karl Schultz2825ab92016-12-02 08:23:14 -07003958 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07003959 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08003960 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06003961}
3962
Karl Schultz6addd812016-02-02 17:17:23 -07003963TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
3964 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06003965
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07003966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06003967
Tobin Ehlise735c692015-10-08 13:13:50 -06003968 ASSERT_NO_FATAL_FAILURE(InitState());
3969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06003970
Chia-I Wu1b99bb22015-10-27 19:25:11 +08003971 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003972 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3973 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06003974
3975 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003976 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
3977 ds_pool_ci.pNext = NULL;
3978 ds_pool_ci.maxSets = 1;
3979 ds_pool_ci.poolSizeCount = 1;
3980 ds_pool_ci.flags = 0;
3981 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
3982 // app can only call vkResetDescriptorPool on this pool.;
3983 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06003984
3985 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003986 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06003987 ASSERT_VK_SUCCESS(err);
3988
3989 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003990 dsl_binding.binding = 0;
3991 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
3992 dsl_binding.descriptorCount = 1;
3993 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
3994 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06003995
3996 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07003997 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
3998 ds_layout_ci.pNext = NULL;
3999 ds_layout_ci.bindingCount = 1;
4000 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004001
4002 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004003 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004004 ASSERT_VK_SUCCESS(err);
4005
4006 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004007 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004008 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004009 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004010 alloc_info.descriptorPool = ds_pool;
4011 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004012 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004013 ASSERT_VK_SUCCESS(err);
4014
4015 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004016 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004017
Chia-I Wuf7458c52015-10-26 21:10:41 +08004018 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4019 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004020}
4021
Karl Schultz6addd812016-02-02 17:17:23 -07004022TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004023 // Attempt to clear Descriptor Pool with bad object.
4024 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004025
4026 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004028 uint64_t fake_pool_handle = 0xbaad6001;
4029 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4030 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004031 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004032}
4033
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004034TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004035 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4036 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004037 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004038 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004039
4040 uint64_t fake_set_handle = 0xbaad6001;
4041 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004042 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004043 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004044
4045 ASSERT_NO_FATAL_FAILURE(InitState());
4046
4047 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4048 layout_bindings[0].binding = 0;
4049 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4050 layout_bindings[0].descriptorCount = 1;
4051 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4052 layout_bindings[0].pImmutableSamplers = NULL;
4053
4054 VkDescriptorSetLayout descriptor_set_layout;
4055 VkDescriptorSetLayoutCreateInfo dslci = {};
4056 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4057 dslci.pNext = NULL;
4058 dslci.bindingCount = 1;
4059 dslci.pBindings = layout_bindings;
4060 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004061 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004062
4063 VkPipelineLayout pipeline_layout;
4064 VkPipelineLayoutCreateInfo plci = {};
4065 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4066 plci.pNext = NULL;
4067 plci.setLayoutCount = 1;
4068 plci.pSetLayouts = &descriptor_set_layout;
4069 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004070 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004071
Tony Barbour552f6c02016-12-21 14:34:07 -07004072 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004073 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4074 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004075 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004076 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004077 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4078 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004079}
4080
Karl Schultz6addd812016-02-02 17:17:23 -07004081TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004082 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4083 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004084 uint64_t fake_layout_handle = 0xbaad6001;
4085 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004086 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004087 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004088 VkPipelineLayout pipeline_layout;
4089 VkPipelineLayoutCreateInfo plci = {};
4090 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4091 plci.pNext = NULL;
4092 plci.setLayoutCount = 1;
4093 plci.pSetLayouts = &bad_layout;
4094 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4095
4096 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004097}
4098
Mark Muellerd4914412016-06-13 17:52:06 -06004099TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004100 TEST_DESCRIPTION(
4101 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4102 "1) A uniform buffer update must have a valid buffer index."
4103 "2) When using an array of descriptors in a single WriteDescriptor,"
4104 " the descriptor types and stageflags must all be the same."
4105 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004106
Mike Weiblena6666382017-01-05 15:16:11 -07004107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004108
4109 ASSERT_NO_FATAL_FAILURE(InitState());
4110 VkDescriptorPoolSize ds_type_count[4] = {};
4111 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4112 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004113 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004114 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004115 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004116 ds_type_count[2].descriptorCount = 1;
4117 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4118 ds_type_count[3].descriptorCount = 1;
4119
4120 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4121 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4122 ds_pool_ci.maxSets = 1;
4123 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4124 ds_pool_ci.pPoolSizes = ds_type_count;
4125
4126 VkDescriptorPool ds_pool;
4127 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4128 ASSERT_VK_SUCCESS(err);
4129
Mark Muellerb9896722016-06-16 09:54:29 -06004130 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004131 layout_binding[0].binding = 0;
4132 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4133 layout_binding[0].descriptorCount = 1;
4134 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4135 layout_binding[0].pImmutableSamplers = NULL;
4136
4137 layout_binding[1].binding = 1;
4138 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4139 layout_binding[1].descriptorCount = 1;
4140 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4141 layout_binding[1].pImmutableSamplers = NULL;
4142
4143 VkSamplerCreateInfo sampler_ci = {};
4144 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4145 sampler_ci.pNext = NULL;
4146 sampler_ci.magFilter = VK_FILTER_NEAREST;
4147 sampler_ci.minFilter = VK_FILTER_NEAREST;
4148 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4149 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4150 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4151 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4152 sampler_ci.mipLodBias = 1.0;
4153 sampler_ci.anisotropyEnable = VK_FALSE;
4154 sampler_ci.maxAnisotropy = 1;
4155 sampler_ci.compareEnable = VK_FALSE;
4156 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4157 sampler_ci.minLod = 1.0;
4158 sampler_ci.maxLod = 1.0;
4159 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4160 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4161 VkSampler sampler;
4162
4163 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4164 ASSERT_VK_SUCCESS(err);
4165
4166 layout_binding[2].binding = 2;
4167 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4168 layout_binding[2].descriptorCount = 1;
4169 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4170 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4171
Mark Muellerd4914412016-06-13 17:52:06 -06004172 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4173 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4174 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4175 ds_layout_ci.pBindings = layout_binding;
4176 VkDescriptorSetLayout ds_layout;
4177 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4178 ASSERT_VK_SUCCESS(err);
4179
4180 VkDescriptorSetAllocateInfo alloc_info = {};
4181 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4182 alloc_info.descriptorSetCount = 1;
4183 alloc_info.descriptorPool = ds_pool;
4184 alloc_info.pSetLayouts = &ds_layout;
4185 VkDescriptorSet descriptorSet;
4186 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4187 ASSERT_VK_SUCCESS(err);
4188
4189 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4190 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4191 pipeline_layout_ci.pNext = NULL;
4192 pipeline_layout_ci.setLayoutCount = 1;
4193 pipeline_layout_ci.pSetLayouts = &ds_layout;
4194
4195 VkPipelineLayout pipeline_layout;
4196 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4197 ASSERT_VK_SUCCESS(err);
4198
Mark Mueller5c838ce2016-06-16 09:54:29 -06004199 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004200 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4201 descriptor_write.dstSet = descriptorSet;
4202 descriptor_write.dstBinding = 0;
4203 descriptor_write.descriptorCount = 1;
4204 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4205
Mark Mueller5c838ce2016-06-16 09:54:29 -06004206 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004207 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4208 m_errorMonitor->VerifyFound();
4209
4210 // Create a buffer to update the descriptor with
4211 uint32_t qfi = 0;
4212 VkBufferCreateInfo buffCI = {};
4213 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4214 buffCI.size = 1024;
4215 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4216 buffCI.queueFamilyIndexCount = 1;
4217 buffCI.pQueueFamilyIndices = &qfi;
4218
4219 VkBuffer dyub;
4220 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4221 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004222
Tony Barboure132c5f2016-12-12 11:50:20 -07004223 VkDeviceMemory mem;
4224 VkMemoryRequirements mem_reqs;
4225 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4226
4227 VkMemoryAllocateInfo mem_alloc_info = {};
4228 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4229 mem_alloc_info.allocationSize = mem_reqs.size;
4230 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4231 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4232 ASSERT_VK_SUCCESS(err);
4233
4234 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4235 ASSERT_VK_SUCCESS(err);
4236
4237 VkDescriptorBufferInfo buffInfo[2] = {};
4238 buffInfo[0].buffer = dyub;
4239 buffInfo[0].offset = 0;
4240 buffInfo[0].range = 1024;
4241 buffInfo[1].buffer = dyub;
4242 buffInfo[1].offset = 0;
4243 buffInfo[1].range = 1024;
4244 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004245 descriptor_write.descriptorCount = 2;
4246
Mark Mueller5c838ce2016-06-16 09:54:29 -06004247 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004249 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4250 m_errorMonitor->VerifyFound();
4251
Mark Mueller5c838ce2016-06-16 09:54:29 -06004252 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4253 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004254 descriptor_write.dstBinding = 1;
4255 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004256
Mark Mueller5c838ce2016-06-16 09:54:29 -06004257 // Make pImageInfo index non-null to avoid complaints of it missing
4258 VkDescriptorImageInfo imageInfo = {};
4259 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4260 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004262 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4263 m_errorMonitor->VerifyFound();
4264
Mark Muellerd4914412016-06-13 17:52:06 -06004265 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004266 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004267 vkDestroySampler(m_device->device(), sampler, NULL);
4268 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4269 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4270 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4271}
4272
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004273TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004274 TEST_DESCRIPTION(
4275 "Attempt to draw with a command buffer that is invalid "
4276 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004277 ASSERT_NO_FATAL_FAILURE(InitState());
4278
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004279 VkBuffer buffer;
4280 VkDeviceMemory mem;
4281 VkMemoryRequirements mem_reqs;
4282
4283 VkBufferCreateInfo buf_info = {};
4284 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004285 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004286 buf_info.size = 256;
4287 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4288 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4289 ASSERT_VK_SUCCESS(err);
4290
4291 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4292
4293 VkMemoryAllocateInfo alloc_info = {};
4294 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4295 alloc_info.allocationSize = 256;
4296 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004297 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 -06004298 if (!pass) {
4299 vkDestroyBuffer(m_device->device(), buffer, NULL);
4300 return;
4301 }
4302 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4303 ASSERT_VK_SUCCESS(err);
4304
4305 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4306 ASSERT_VK_SUCCESS(err);
4307
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004308 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004309 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004310 m_commandBuffer->EndCommandBuffer();
4311
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004313 // Destroy buffer dependency prior to submit to cause ERROR
4314 vkDestroyBuffer(m_device->device(), buffer, NULL);
4315
4316 VkSubmitInfo submit_info = {};
4317 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4318 submit_info.commandBufferCount = 1;
4319 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4320 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4321
4322 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004323 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004324 vkFreeMemory(m_device->handle(), mem, NULL);
4325}
4326
Tobin Ehlisea413442016-09-28 10:23:59 -06004327TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4328 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4329
4330 ASSERT_NO_FATAL_FAILURE(InitState());
4331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4332
4333 VkDescriptorPoolSize ds_type_count;
4334 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4335 ds_type_count.descriptorCount = 1;
4336
4337 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4338 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4339 ds_pool_ci.maxSets = 1;
4340 ds_pool_ci.poolSizeCount = 1;
4341 ds_pool_ci.pPoolSizes = &ds_type_count;
4342
4343 VkDescriptorPool ds_pool;
4344 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4345 ASSERT_VK_SUCCESS(err);
4346
4347 VkDescriptorSetLayoutBinding layout_binding;
4348 layout_binding.binding = 0;
4349 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4350 layout_binding.descriptorCount = 1;
4351 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4352 layout_binding.pImmutableSamplers = NULL;
4353
4354 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4355 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4356 ds_layout_ci.bindingCount = 1;
4357 ds_layout_ci.pBindings = &layout_binding;
4358 VkDescriptorSetLayout ds_layout;
4359 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4360 ASSERT_VK_SUCCESS(err);
4361
4362 VkDescriptorSetAllocateInfo alloc_info = {};
4363 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4364 alloc_info.descriptorSetCount = 1;
4365 alloc_info.descriptorPool = ds_pool;
4366 alloc_info.pSetLayouts = &ds_layout;
4367 VkDescriptorSet descriptor_set;
4368 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4369 ASSERT_VK_SUCCESS(err);
4370
4371 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4372 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4373 pipeline_layout_ci.pNext = NULL;
4374 pipeline_layout_ci.setLayoutCount = 1;
4375 pipeline_layout_ci.pSetLayouts = &ds_layout;
4376
4377 VkPipelineLayout pipeline_layout;
4378 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4379 ASSERT_VK_SUCCESS(err);
4380
4381 VkBuffer buffer;
4382 uint32_t queue_family_index = 0;
4383 VkBufferCreateInfo buffer_create_info = {};
4384 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4385 buffer_create_info.size = 1024;
4386 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4387 buffer_create_info.queueFamilyIndexCount = 1;
4388 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4389
4390 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4391 ASSERT_VK_SUCCESS(err);
4392
4393 VkMemoryRequirements memory_reqs;
4394 VkDeviceMemory buffer_memory;
4395
4396 VkMemoryAllocateInfo memory_info = {};
4397 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4398 memory_info.allocationSize = 0;
4399 memory_info.memoryTypeIndex = 0;
4400
4401 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4402 memory_info.allocationSize = memory_reqs.size;
4403 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4404 ASSERT_TRUE(pass);
4405
4406 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4407 ASSERT_VK_SUCCESS(err);
4408 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4409 ASSERT_VK_SUCCESS(err);
4410
4411 VkBufferView view;
4412 VkBufferViewCreateInfo bvci = {};
4413 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4414 bvci.buffer = buffer;
4415 bvci.format = VK_FORMAT_R8_UNORM;
4416 bvci.range = VK_WHOLE_SIZE;
4417
4418 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4419 ASSERT_VK_SUCCESS(err);
4420
4421 VkWriteDescriptorSet descriptor_write = {};
4422 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4423 descriptor_write.dstSet = descriptor_set;
4424 descriptor_write.dstBinding = 0;
4425 descriptor_write.descriptorCount = 1;
4426 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4427 descriptor_write.pTexelBufferView = &view;
4428
4429 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4430
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004431 char const *vsSource =
4432 "#version 450\n"
4433 "\n"
4434 "out gl_PerVertex { \n"
4435 " vec4 gl_Position;\n"
4436 "};\n"
4437 "void main(){\n"
4438 " gl_Position = vec4(1);\n"
4439 "}\n";
4440 char const *fsSource =
4441 "#version 450\n"
4442 "\n"
4443 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4444 "layout(location=0) out vec4 x;\n"
4445 "void main(){\n"
4446 " x = imageLoad(s, 0);\n"
4447 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004448 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4449 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4450 VkPipelineObj pipe(m_device);
4451 pipe.AddShader(&vs);
4452 pipe.AddShader(&fs);
4453 pipe.AddColorAttachment();
4454 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4455
4456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4457 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4458
Tony Barbour552f6c02016-12-21 14:34:07 -07004459 m_commandBuffer->BeginCommandBuffer();
4460 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4461
Tobin Ehlisea413442016-09-28 10:23:59 -06004462 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4463 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4464 VkRect2D scissor = {{0, 0}, {16, 16}};
4465 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4466 // Bind pipeline to cmd buffer
4467 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4468 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4469 &descriptor_set, 0, nullptr);
4470 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004471 m_commandBuffer->EndRenderPass();
4472 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004473
4474 // Delete BufferView in order to invalidate cmd buffer
4475 vkDestroyBufferView(m_device->device(), view, NULL);
4476 // Now attempt submit of cmd buffer
4477 VkSubmitInfo submit_info = {};
4478 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4479 submit_info.commandBufferCount = 1;
4480 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4481 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4482 m_errorMonitor->VerifyFound();
4483
4484 // Clean-up
4485 vkDestroyBuffer(m_device->device(), buffer, NULL);
4486 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4487 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4488 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4489 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4490}
4491
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004492TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004493 TEST_DESCRIPTION(
4494 "Attempt to draw with a command buffer that is invalid "
4495 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004496 ASSERT_NO_FATAL_FAILURE(InitState());
4497
4498 VkImage image;
4499 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4500 VkImageCreateInfo image_create_info = {};
4501 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4502 image_create_info.pNext = NULL;
4503 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4504 image_create_info.format = tex_format;
4505 image_create_info.extent.width = 32;
4506 image_create_info.extent.height = 32;
4507 image_create_info.extent.depth = 1;
4508 image_create_info.mipLevels = 1;
4509 image_create_info.arrayLayers = 1;
4510 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4511 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004512 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004513 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004514 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004515 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004516 // Have to bind memory to image before recording cmd in cmd buffer using it
4517 VkMemoryRequirements mem_reqs;
4518 VkDeviceMemory image_mem;
4519 bool pass;
4520 VkMemoryAllocateInfo mem_alloc = {};
4521 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4522 mem_alloc.pNext = NULL;
4523 mem_alloc.memoryTypeIndex = 0;
4524 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4525 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004526 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004527 ASSERT_TRUE(pass);
4528 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4529 ASSERT_VK_SUCCESS(err);
4530 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4531 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004532
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004533 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004534 VkClearColorValue ccv;
4535 ccv.float32[0] = 1.0f;
4536 ccv.float32[1] = 1.0f;
4537 ccv.float32[2] = 1.0f;
4538 ccv.float32[3] = 1.0f;
4539 VkImageSubresourceRange isr = {};
4540 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004541 isr.baseArrayLayer = 0;
4542 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004543 isr.layerCount = 1;
4544 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004545 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004546 m_commandBuffer->EndCommandBuffer();
4547
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004549 // Destroy image dependency prior to submit to cause ERROR
4550 vkDestroyImage(m_device->device(), image, NULL);
4551
4552 VkSubmitInfo submit_info = {};
4553 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4554 submit_info.commandBufferCount = 1;
4555 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4556 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4557
4558 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004559 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004560}
4561
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004562TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004563 TEST_DESCRIPTION(
4564 "Attempt to draw with a command buffer that is invalid "
4565 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004566 VkFormatProperties format_properties;
4567 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004568 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4569 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004570 return;
4571 }
4572
4573 ASSERT_NO_FATAL_FAILURE(InitState());
4574 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4575
4576 VkImageCreateInfo image_ci = {};
4577 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4578 image_ci.pNext = NULL;
4579 image_ci.imageType = VK_IMAGE_TYPE_2D;
4580 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4581 image_ci.extent.width = 32;
4582 image_ci.extent.height = 32;
4583 image_ci.extent.depth = 1;
4584 image_ci.mipLevels = 1;
4585 image_ci.arrayLayers = 1;
4586 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4587 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004588 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004589 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4590 image_ci.flags = 0;
4591 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004592 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004593
4594 VkMemoryRequirements memory_reqs;
4595 VkDeviceMemory image_memory;
4596 bool pass;
4597 VkMemoryAllocateInfo memory_info = {};
4598 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4599 memory_info.pNext = NULL;
4600 memory_info.allocationSize = 0;
4601 memory_info.memoryTypeIndex = 0;
4602 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4603 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004604 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004605 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004606 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004607 ASSERT_VK_SUCCESS(err);
4608 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4609 ASSERT_VK_SUCCESS(err);
4610
4611 VkImageViewCreateInfo ivci = {
4612 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4613 nullptr,
4614 0,
4615 image,
4616 VK_IMAGE_VIEW_TYPE_2D,
4617 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004618 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004619 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4620 };
4621 VkImageView view;
4622 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4623 ASSERT_VK_SUCCESS(err);
4624
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004625 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004626 VkFramebuffer fb;
4627 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4628 ASSERT_VK_SUCCESS(err);
4629
4630 // Just use default renderpass with our framebuffer
4631 m_renderPassBeginInfo.framebuffer = fb;
4632 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004633 m_commandBuffer->BeginCommandBuffer();
4634 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4635 m_commandBuffer->EndRenderPass();
4636 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004637 // Destroy image attached to framebuffer to invalidate cmd buffer
4638 vkDestroyImage(m_device->device(), image, NULL);
4639 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004641 QueueCommandBuffer(false);
4642 m_errorMonitor->VerifyFound();
4643
4644 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4645 vkDestroyImageView(m_device->device(), view, nullptr);
4646 vkFreeMemory(m_device->device(), image_memory, nullptr);
4647}
4648
Tobin Ehlisb329f992016-10-12 13:20:29 -06004649TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4650 TEST_DESCRIPTION("Delete in-use framebuffer.");
4651 VkFormatProperties format_properties;
4652 VkResult err = VK_SUCCESS;
4653 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4654
4655 ASSERT_NO_FATAL_FAILURE(InitState());
4656 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4657
4658 VkImageObj image(m_device);
4659 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
4660 ASSERT_TRUE(image.initialized());
4661 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
4662
4663 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4664 VkFramebuffer fb;
4665 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4666 ASSERT_VK_SUCCESS(err);
4667
4668 // Just use default renderpass with our framebuffer
4669 m_renderPassBeginInfo.framebuffer = fb;
4670 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004671 m_commandBuffer->BeginCommandBuffer();
4672 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4673 m_commandBuffer->EndRenderPass();
4674 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06004675 // Submit cmd buffer to put it in-flight
4676 VkSubmitInfo submit_info = {};
4677 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4678 submit_info.commandBufferCount = 1;
4679 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4680 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4681 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06004683 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4684 m_errorMonitor->VerifyFound();
4685 // Wait for queue to complete so we can safely destroy everything
4686 vkQueueWaitIdle(m_device->m_queue);
4687 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4688}
4689
Tobin Ehlis88becd72016-09-21 14:33:41 -06004690TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
4691 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
4692 VkFormatProperties format_properties;
4693 VkResult err = VK_SUCCESS;
4694 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004695
4696 ASSERT_NO_FATAL_FAILURE(InitState());
4697 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4698
4699 VkImageCreateInfo image_ci = {};
4700 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4701 image_ci.pNext = NULL;
4702 image_ci.imageType = VK_IMAGE_TYPE_2D;
4703 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4704 image_ci.extent.width = 256;
4705 image_ci.extent.height = 256;
4706 image_ci.extent.depth = 1;
4707 image_ci.mipLevels = 1;
4708 image_ci.arrayLayers = 1;
4709 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4710 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06004711 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06004712 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4713 image_ci.flags = 0;
4714 VkImage image;
4715 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
4716
4717 VkMemoryRequirements memory_reqs;
4718 VkDeviceMemory image_memory;
4719 bool pass;
4720 VkMemoryAllocateInfo memory_info = {};
4721 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4722 memory_info.pNext = NULL;
4723 memory_info.allocationSize = 0;
4724 memory_info.memoryTypeIndex = 0;
4725 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4726 memory_info.allocationSize = memory_reqs.size;
4727 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4728 ASSERT_TRUE(pass);
4729 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
4730 ASSERT_VK_SUCCESS(err);
4731 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4732 ASSERT_VK_SUCCESS(err);
4733
4734 VkImageViewCreateInfo ivci = {
4735 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4736 nullptr,
4737 0,
4738 image,
4739 VK_IMAGE_VIEW_TYPE_2D,
4740 VK_FORMAT_B8G8R8A8_UNORM,
4741 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
4742 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4743 };
4744 VkImageView view;
4745 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4746 ASSERT_VK_SUCCESS(err);
4747
4748 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
4749 VkFramebuffer fb;
4750 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4751 ASSERT_VK_SUCCESS(err);
4752
4753 // Just use default renderpass with our framebuffer
4754 m_renderPassBeginInfo.framebuffer = fb;
4755 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004756 m_commandBuffer->BeginCommandBuffer();
4757 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4758 m_commandBuffer->EndRenderPass();
4759 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06004760 // Submit cmd buffer to put it (and attached imageView) in-flight
4761 VkSubmitInfo submit_info = {};
4762 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4763 submit_info.commandBufferCount = 1;
4764 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4765 // Submit cmd buffer to put framebuffer and children in-flight
4766 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4767 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06004769 vkDestroyImage(m_device->device(), image, NULL);
4770 m_errorMonitor->VerifyFound();
4771 // Wait for queue to complete so we can safely destroy image and other objects
4772 vkQueueWaitIdle(m_device->m_queue);
4773 vkDestroyImage(m_device->device(), image, NULL);
4774 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4775 vkDestroyImageView(m_device->device(), view, nullptr);
4776 vkFreeMemory(m_device->device(), image_memory, nullptr);
4777}
4778
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004779TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
4780 TEST_DESCRIPTION("Delete in-use renderPass.");
4781
4782 ASSERT_NO_FATAL_FAILURE(InitState());
4783 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4784
4785 // Create simple renderpass
4786 VkAttachmentReference attach = {};
4787 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
4788 VkSubpassDescription subpass = {};
4789 subpass.pColorAttachments = &attach;
4790 VkRenderPassCreateInfo rpci = {};
4791 rpci.subpassCount = 1;
4792 rpci.pSubpasses = &subpass;
4793 rpci.attachmentCount = 1;
4794 VkAttachmentDescription attach_desc = {};
4795 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
4796 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4797 rpci.pAttachments = &attach_desc;
4798 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
4799 VkRenderPass rp;
4800 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4801 ASSERT_VK_SUCCESS(err);
4802
4803 // Create a pipeline that uses the given renderpass
4804 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4805 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4806
4807 VkPipelineLayout pipeline_layout;
4808 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4809 ASSERT_VK_SUCCESS(err);
4810
4811 VkPipelineViewportStateCreateInfo vp_state_ci = {};
4812 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
4813 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004814 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004815 vp_state_ci.pViewports = &vp;
4816 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004817 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004818 vp_state_ci.pScissors = &scissors;
4819
4820 VkPipelineShaderStageCreateInfo shaderStages[2];
4821 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
4822
4823 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004824 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06004825 // but add it to be able to run on more devices
4826 shaderStages[0] = vs.GetStageCreateInfo();
4827 shaderStages[1] = fs.GetStageCreateInfo();
4828
4829 VkPipelineVertexInputStateCreateInfo vi_ci = {};
4830 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
4831
4832 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
4833 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
4834 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
4835
4836 VkPipelineRasterizationStateCreateInfo rs_ci = {};
4837 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
4838 rs_ci.rasterizerDiscardEnable = true;
4839 rs_ci.lineWidth = 1.0f;
4840
4841 VkPipelineColorBlendAttachmentState att = {};
4842 att.blendEnable = VK_FALSE;
4843 att.colorWriteMask = 0xf;
4844
4845 VkPipelineColorBlendStateCreateInfo cb_ci = {};
4846 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
4847 cb_ci.attachmentCount = 1;
4848 cb_ci.pAttachments = &att;
4849
4850 VkGraphicsPipelineCreateInfo gp_ci = {};
4851 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
4852 gp_ci.stageCount = 2;
4853 gp_ci.pStages = shaderStages;
4854 gp_ci.pVertexInputState = &vi_ci;
4855 gp_ci.pInputAssemblyState = &ia_ci;
4856 gp_ci.pViewportState = &vp_state_ci;
4857 gp_ci.pRasterizationState = &rs_ci;
4858 gp_ci.pColorBlendState = &cb_ci;
4859 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
4860 gp_ci.layout = pipeline_layout;
4861 gp_ci.renderPass = rp;
4862
4863 VkPipelineCacheCreateInfo pc_ci = {};
4864 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
4865
4866 VkPipeline pipeline;
4867 VkPipelineCache pipe_cache;
4868 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
4869 ASSERT_VK_SUCCESS(err);
4870
4871 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
4872 ASSERT_VK_SUCCESS(err);
4873 // Bind pipeline to cmd buffer, will also bind renderpass
4874 m_commandBuffer->BeginCommandBuffer();
4875 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
4876 m_commandBuffer->EndCommandBuffer();
4877
4878 VkSubmitInfo submit_info = {};
4879 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4880 submit_info.commandBufferCount = 1;
4881 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4882 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4883
4884 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
4885 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4886 m_errorMonitor->VerifyFound();
4887
4888 // Wait for queue to complete so we can safely destroy everything
4889 vkQueueWaitIdle(m_device->m_queue);
4890 vkDestroyRenderPass(m_device->device(), rp, nullptr);
4891 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
4892 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
4893 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
4894}
4895
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004896TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004897 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004898 ASSERT_NO_FATAL_FAILURE(InitState());
4899
4900 VkImage image;
4901 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4902 VkImageCreateInfo image_create_info = {};
4903 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4904 image_create_info.pNext = NULL;
4905 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4906 image_create_info.format = tex_format;
4907 image_create_info.extent.width = 32;
4908 image_create_info.extent.height = 32;
4909 image_create_info.extent.depth = 1;
4910 image_create_info.mipLevels = 1;
4911 image_create_info.arrayLayers = 1;
4912 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4913 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004914 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004915 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004916 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004917 ASSERT_VK_SUCCESS(err);
4918 // Have to bind memory to image before recording cmd in cmd buffer using it
4919 VkMemoryRequirements mem_reqs;
4920 VkDeviceMemory image_mem;
4921 bool pass;
4922 VkMemoryAllocateInfo mem_alloc = {};
4923 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4924 mem_alloc.pNext = NULL;
4925 mem_alloc.memoryTypeIndex = 0;
4926 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4927 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004928 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004929 ASSERT_TRUE(pass);
4930 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4931 ASSERT_VK_SUCCESS(err);
4932
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004933 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
4934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004935 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004936
4937 m_commandBuffer->BeginCommandBuffer();
4938 VkClearColorValue ccv;
4939 ccv.float32[0] = 1.0f;
4940 ccv.float32[1] = 1.0f;
4941 ccv.float32[2] = 1.0f;
4942 ccv.float32[3] = 1.0f;
4943 VkImageSubresourceRange isr = {};
4944 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4945 isr.baseArrayLayer = 0;
4946 isr.baseMipLevel = 0;
4947 isr.layerCount = 1;
4948 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004950 m_commandBuffer->EndCommandBuffer();
4951
4952 m_errorMonitor->VerifyFound();
4953 vkDestroyImage(m_device->device(), image, NULL);
4954 vkFreeMemory(m_device->device(), image_mem, nullptr);
4955}
4956
4957TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004958 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004959 ASSERT_NO_FATAL_FAILURE(InitState());
4960
4961 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004962 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 -06004963 VK_IMAGE_TILING_OPTIMAL, 0);
4964 ASSERT_TRUE(image.initialized());
4965
4966 VkBuffer buffer;
4967 VkDeviceMemory mem;
4968 VkMemoryRequirements mem_reqs;
4969
4970 VkBufferCreateInfo buf_info = {};
4971 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12004972 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004973 buf_info.size = 256;
4974 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4975 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4976 ASSERT_VK_SUCCESS(err);
4977
4978 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4979
4980 VkMemoryAllocateInfo alloc_info = {};
4981 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4982 alloc_info.allocationSize = 256;
4983 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004984 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 -06004985 if (!pass) {
4986 vkDestroyBuffer(m_device->device(), buffer, NULL);
4987 return;
4988 }
4989 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4990 ASSERT_VK_SUCCESS(err);
4991
Tobin Ehlisfed999f2016-09-21 15:09:45 -06004992 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06004994 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06004995 VkBufferImageCopy region = {};
4996 region.bufferRowLength = 128;
4997 region.bufferImageHeight = 128;
4998 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4999
5000 region.imageSubresource.layerCount = 1;
5001 region.imageExtent.height = 4;
5002 region.imageExtent.width = 4;
5003 region.imageExtent.depth = 1;
5004 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005005 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5006 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005007 m_commandBuffer->EndCommandBuffer();
5008
5009 m_errorMonitor->VerifyFound();
5010
5011 vkDestroyBuffer(m_device->device(), buffer, NULL);
5012 vkFreeMemory(m_device->handle(), mem, NULL);
5013}
5014
Tobin Ehlis85940f52016-07-07 16:57:21 -06005015TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005016 TEST_DESCRIPTION(
5017 "Attempt to draw with a command buffer that is invalid "
5018 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005019 ASSERT_NO_FATAL_FAILURE(InitState());
5020
5021 VkEvent event;
5022 VkEventCreateInfo evci = {};
5023 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5024 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5025 ASSERT_VK_SUCCESS(result);
5026
5027 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005028 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005029 m_commandBuffer->EndCommandBuffer();
5030
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005031 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005032 // Destroy event dependency prior to submit to cause ERROR
5033 vkDestroyEvent(m_device->device(), event, NULL);
5034
5035 VkSubmitInfo submit_info = {};
5036 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5037 submit_info.commandBufferCount = 1;
5038 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5039 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5040
5041 m_errorMonitor->VerifyFound();
5042}
5043
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005044TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005045 TEST_DESCRIPTION(
5046 "Attempt to draw with a command buffer that is invalid "
5047 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005048 ASSERT_NO_FATAL_FAILURE(InitState());
5049
5050 VkQueryPool query_pool;
5051 VkQueryPoolCreateInfo qpci{};
5052 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5053 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5054 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005055 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005056 ASSERT_VK_SUCCESS(result);
5057
5058 m_commandBuffer->BeginCommandBuffer();
5059 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5060 m_commandBuffer->EndCommandBuffer();
5061
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005062 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005063 // Destroy query pool dependency prior to submit to cause ERROR
5064 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5065
5066 VkSubmitInfo submit_info = {};
5067 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5068 submit_info.commandBufferCount = 1;
5069 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5070 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5071
5072 m_errorMonitor->VerifyFound();
5073}
5074
Tobin Ehlis24130d92016-07-08 15:50:53 -06005075TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005076 TEST_DESCRIPTION(
5077 "Attempt to draw with a command buffer that is invalid "
5078 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005079 ASSERT_NO_FATAL_FAILURE(InitState());
5080 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5081
5082 VkResult err;
5083
5084 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5085 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5086
5087 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005088 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005089 ASSERT_VK_SUCCESS(err);
5090
5091 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5092 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5093 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005094 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005095 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005096 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005097 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005098 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005099
5100 VkPipelineShaderStageCreateInfo shaderStages[2];
5101 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5102
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005103 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005104 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005105 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005106 shaderStages[0] = vs.GetStageCreateInfo();
5107 shaderStages[1] = fs.GetStageCreateInfo();
5108
5109 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5110 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5111
5112 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5113 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5114 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5115
5116 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5117 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005118 rs_ci.rasterizerDiscardEnable = true;
5119 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005120
5121 VkPipelineColorBlendAttachmentState att = {};
5122 att.blendEnable = VK_FALSE;
5123 att.colorWriteMask = 0xf;
5124
5125 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5126 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5127 cb_ci.attachmentCount = 1;
5128 cb_ci.pAttachments = &att;
5129
5130 VkGraphicsPipelineCreateInfo gp_ci = {};
5131 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5132 gp_ci.stageCount = 2;
5133 gp_ci.pStages = shaderStages;
5134 gp_ci.pVertexInputState = &vi_ci;
5135 gp_ci.pInputAssemblyState = &ia_ci;
5136 gp_ci.pViewportState = &vp_state_ci;
5137 gp_ci.pRasterizationState = &rs_ci;
5138 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005139 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5140 gp_ci.layout = pipeline_layout;
5141 gp_ci.renderPass = renderPass();
5142
5143 VkPipelineCacheCreateInfo pc_ci = {};
5144 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5145
5146 VkPipeline pipeline;
5147 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005148 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005149 ASSERT_VK_SUCCESS(err);
5150
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005151 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005152 ASSERT_VK_SUCCESS(err);
5153
5154 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005155 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005156 m_commandBuffer->EndCommandBuffer();
5157 // Now destroy pipeline in order to cause error when submitting
5158 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5159
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005161
5162 VkSubmitInfo submit_info = {};
5163 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5164 submit_info.commandBufferCount = 1;
5165 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5166 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5167
5168 m_errorMonitor->VerifyFound();
5169 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5170 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5171}
5172
Tobin Ehlis31289162016-08-17 14:57:58 -06005173TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005174 TEST_DESCRIPTION(
5175 "Attempt to draw with a command buffer that is invalid "
5176 "due to a bound descriptor set with a buffer dependency "
5177 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005178 ASSERT_NO_FATAL_FAILURE(InitState());
5179 ASSERT_NO_FATAL_FAILURE(InitViewport());
5180 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5181
5182 VkDescriptorPoolSize ds_type_count = {};
5183 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5184 ds_type_count.descriptorCount = 1;
5185
5186 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5187 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5188 ds_pool_ci.pNext = NULL;
5189 ds_pool_ci.maxSets = 1;
5190 ds_pool_ci.poolSizeCount = 1;
5191 ds_pool_ci.pPoolSizes = &ds_type_count;
5192
5193 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005194 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005195 ASSERT_VK_SUCCESS(err);
5196
5197 VkDescriptorSetLayoutBinding dsl_binding = {};
5198 dsl_binding.binding = 0;
5199 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5200 dsl_binding.descriptorCount = 1;
5201 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5202 dsl_binding.pImmutableSamplers = NULL;
5203
5204 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5205 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5206 ds_layout_ci.pNext = NULL;
5207 ds_layout_ci.bindingCount = 1;
5208 ds_layout_ci.pBindings = &dsl_binding;
5209 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005210 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005211 ASSERT_VK_SUCCESS(err);
5212
5213 VkDescriptorSet descriptorSet;
5214 VkDescriptorSetAllocateInfo alloc_info = {};
5215 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5216 alloc_info.descriptorSetCount = 1;
5217 alloc_info.descriptorPool = ds_pool;
5218 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005219 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005220 ASSERT_VK_SUCCESS(err);
5221
5222 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5223 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5224 pipeline_layout_ci.pNext = NULL;
5225 pipeline_layout_ci.setLayoutCount = 1;
5226 pipeline_layout_ci.pSetLayouts = &ds_layout;
5227
5228 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005229 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005230 ASSERT_VK_SUCCESS(err);
5231
5232 // Create a buffer to update the descriptor with
5233 uint32_t qfi = 0;
5234 VkBufferCreateInfo buffCI = {};
5235 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5236 buffCI.size = 1024;
5237 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5238 buffCI.queueFamilyIndexCount = 1;
5239 buffCI.pQueueFamilyIndices = &qfi;
5240
5241 VkBuffer buffer;
5242 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5243 ASSERT_VK_SUCCESS(err);
5244 // Allocate memory and bind to buffer so we can make it to the appropriate
5245 // error
5246 VkMemoryAllocateInfo mem_alloc = {};
5247 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5248 mem_alloc.pNext = NULL;
5249 mem_alloc.allocationSize = 1024;
5250 mem_alloc.memoryTypeIndex = 0;
5251
5252 VkMemoryRequirements memReqs;
5253 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005254 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005255 if (!pass) {
5256 vkDestroyBuffer(m_device->device(), buffer, NULL);
5257 return;
5258 }
5259
5260 VkDeviceMemory mem;
5261 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5262 ASSERT_VK_SUCCESS(err);
5263 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5264 ASSERT_VK_SUCCESS(err);
5265 // Correctly update descriptor to avoid "NOT_UPDATED" error
5266 VkDescriptorBufferInfo buffInfo = {};
5267 buffInfo.buffer = buffer;
5268 buffInfo.offset = 0;
5269 buffInfo.range = 1024;
5270
5271 VkWriteDescriptorSet descriptor_write;
5272 memset(&descriptor_write, 0, sizeof(descriptor_write));
5273 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5274 descriptor_write.dstSet = descriptorSet;
5275 descriptor_write.dstBinding = 0;
5276 descriptor_write.descriptorCount = 1;
5277 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5278 descriptor_write.pBufferInfo = &buffInfo;
5279
5280 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5281
5282 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005283 char const *vsSource =
5284 "#version 450\n"
5285 "\n"
5286 "out gl_PerVertex { \n"
5287 " vec4 gl_Position;\n"
5288 "};\n"
5289 "void main(){\n"
5290 " gl_Position = vec4(1);\n"
5291 "}\n";
5292 char const *fsSource =
5293 "#version 450\n"
5294 "\n"
5295 "layout(location=0) out vec4 x;\n"
5296 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5297 "void main(){\n"
5298 " x = vec4(bar.y);\n"
5299 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005300 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5301 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5302 VkPipelineObj pipe(m_device);
5303 pipe.AddShader(&vs);
5304 pipe.AddShader(&fs);
5305 pipe.AddColorAttachment();
5306 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5307
Tony Barbour552f6c02016-12-21 14:34:07 -07005308 m_commandBuffer->BeginCommandBuffer();
5309 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005310 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5311 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5312 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005313
5314 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5315 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5316
Tobin Ehlis31289162016-08-17 14:57:58 -06005317 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005318 m_commandBuffer->EndRenderPass();
5319 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005321 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5322 vkDestroyBuffer(m_device->device(), buffer, NULL);
5323 // Attempt to submit cmd buffer
5324 VkSubmitInfo submit_info = {};
5325 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5326 submit_info.commandBufferCount = 1;
5327 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5328 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5329 m_errorMonitor->VerifyFound();
5330 // Cleanup
5331 vkFreeMemory(m_device->device(), mem, NULL);
5332
5333 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5334 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5335 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5336}
5337
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005338TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005339 TEST_DESCRIPTION(
5340 "Attempt to draw with a command buffer that is invalid "
5341 "due to a bound descriptor sets with a combined image "
5342 "sampler having their image, sampler, and descriptor set "
5343 "each respectively destroyed and then attempting to "
5344 "submit associated cmd buffers. Attempt to destroy a "
5345 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005346 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005347 ASSERT_NO_FATAL_FAILURE(InitViewport());
5348 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5349
5350 VkDescriptorPoolSize ds_type_count = {};
5351 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5352 ds_type_count.descriptorCount = 1;
5353
5354 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5355 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5356 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005357 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005358 ds_pool_ci.maxSets = 1;
5359 ds_pool_ci.poolSizeCount = 1;
5360 ds_pool_ci.pPoolSizes = &ds_type_count;
5361
5362 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005363 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005364 ASSERT_VK_SUCCESS(err);
5365
5366 VkDescriptorSetLayoutBinding dsl_binding = {};
5367 dsl_binding.binding = 0;
5368 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5369 dsl_binding.descriptorCount = 1;
5370 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5371 dsl_binding.pImmutableSamplers = NULL;
5372
5373 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5374 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5375 ds_layout_ci.pNext = NULL;
5376 ds_layout_ci.bindingCount = 1;
5377 ds_layout_ci.pBindings = &dsl_binding;
5378 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005379 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005380 ASSERT_VK_SUCCESS(err);
5381
5382 VkDescriptorSet descriptorSet;
5383 VkDescriptorSetAllocateInfo alloc_info = {};
5384 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5385 alloc_info.descriptorSetCount = 1;
5386 alloc_info.descriptorPool = ds_pool;
5387 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005388 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005389 ASSERT_VK_SUCCESS(err);
5390
5391 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5392 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5393 pipeline_layout_ci.pNext = NULL;
5394 pipeline_layout_ci.setLayoutCount = 1;
5395 pipeline_layout_ci.pSetLayouts = &ds_layout;
5396
5397 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005398 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005399 ASSERT_VK_SUCCESS(err);
5400
5401 // Create images to update the descriptor with
5402 VkImage image;
5403 VkImage image2;
5404 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5405 const int32_t tex_width = 32;
5406 const int32_t tex_height = 32;
5407 VkImageCreateInfo image_create_info = {};
5408 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5409 image_create_info.pNext = NULL;
5410 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5411 image_create_info.format = tex_format;
5412 image_create_info.extent.width = tex_width;
5413 image_create_info.extent.height = tex_height;
5414 image_create_info.extent.depth = 1;
5415 image_create_info.mipLevels = 1;
5416 image_create_info.arrayLayers = 1;
5417 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5418 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5419 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5420 image_create_info.flags = 0;
5421 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5422 ASSERT_VK_SUCCESS(err);
5423 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5424 ASSERT_VK_SUCCESS(err);
5425
5426 VkMemoryRequirements memory_reqs;
5427 VkDeviceMemory image_memory;
5428 bool pass;
5429 VkMemoryAllocateInfo memory_info = {};
5430 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5431 memory_info.pNext = NULL;
5432 memory_info.allocationSize = 0;
5433 memory_info.memoryTypeIndex = 0;
5434 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5435 // Allocate enough memory for both images
5436 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005437 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005438 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005439 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005440 ASSERT_VK_SUCCESS(err);
5441 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5442 ASSERT_VK_SUCCESS(err);
5443 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005444 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005445 ASSERT_VK_SUCCESS(err);
5446
5447 VkImageViewCreateInfo image_view_create_info = {};
5448 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5449 image_view_create_info.image = image;
5450 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5451 image_view_create_info.format = tex_format;
5452 image_view_create_info.subresourceRange.layerCount = 1;
5453 image_view_create_info.subresourceRange.baseMipLevel = 0;
5454 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005455 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005456
5457 VkImageView view;
5458 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005459 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005460 ASSERT_VK_SUCCESS(err);
5461 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005462 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005463 ASSERT_VK_SUCCESS(err);
5464 // Create Samplers
5465 VkSamplerCreateInfo sampler_ci = {};
5466 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5467 sampler_ci.pNext = NULL;
5468 sampler_ci.magFilter = VK_FILTER_NEAREST;
5469 sampler_ci.minFilter = VK_FILTER_NEAREST;
5470 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5471 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5472 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5473 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5474 sampler_ci.mipLodBias = 1.0;
5475 sampler_ci.anisotropyEnable = VK_FALSE;
5476 sampler_ci.maxAnisotropy = 1;
5477 sampler_ci.compareEnable = VK_FALSE;
5478 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5479 sampler_ci.minLod = 1.0;
5480 sampler_ci.maxLod = 1.0;
5481 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5482 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5483 VkSampler sampler;
5484 VkSampler sampler2;
5485 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5486 ASSERT_VK_SUCCESS(err);
5487 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5488 ASSERT_VK_SUCCESS(err);
5489 // Update descriptor with image and sampler
5490 VkDescriptorImageInfo img_info = {};
5491 img_info.sampler = sampler;
5492 img_info.imageView = view;
5493 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5494
5495 VkWriteDescriptorSet descriptor_write;
5496 memset(&descriptor_write, 0, sizeof(descriptor_write));
5497 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5498 descriptor_write.dstSet = descriptorSet;
5499 descriptor_write.dstBinding = 0;
5500 descriptor_write.descriptorCount = 1;
5501 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5502 descriptor_write.pImageInfo = &img_info;
5503
5504 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5505
5506 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005507 char const *vsSource =
5508 "#version 450\n"
5509 "\n"
5510 "out gl_PerVertex { \n"
5511 " vec4 gl_Position;\n"
5512 "};\n"
5513 "void main(){\n"
5514 " gl_Position = vec4(1);\n"
5515 "}\n";
5516 char const *fsSource =
5517 "#version 450\n"
5518 "\n"
5519 "layout(set=0, binding=0) uniform sampler2D s;\n"
5520 "layout(location=0) out vec4 x;\n"
5521 "void main(){\n"
5522 " x = texture(s, vec2(1));\n"
5523 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005524 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5525 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5526 VkPipelineObj pipe(m_device);
5527 pipe.AddShader(&vs);
5528 pipe.AddShader(&fs);
5529 pipe.AddColorAttachment();
5530 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5531
5532 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005534 m_commandBuffer->BeginCommandBuffer();
5535 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005536 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5537 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5538 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005539 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5540 VkRect2D scissor = {{0, 0}, {16, 16}};
5541 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5542 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005543 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005544 m_commandBuffer->EndRenderPass();
5545 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005546 // Destroy sampler invalidates the cmd buffer, causing error on submit
5547 vkDestroySampler(m_device->device(), sampler, NULL);
5548 // Attempt to submit cmd buffer
5549 VkSubmitInfo submit_info = {};
5550 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5551 submit_info.commandBufferCount = 1;
5552 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5553 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5554 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005555
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005556 // Now re-update descriptor with valid sampler and delete image
5557 img_info.sampler = sampler2;
5558 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005559
5560 VkCommandBufferBeginInfo info = {};
5561 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5562 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5563
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005565 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005566 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005567 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5568 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5569 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005570 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5571 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005572 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005573 m_commandBuffer->EndRenderPass();
5574 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005575 // Destroy image invalidates the cmd buffer, causing error on submit
5576 vkDestroyImage(m_device->device(), image, NULL);
5577 // Attempt to submit cmd buffer
5578 submit_info = {};
5579 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5580 submit_info.commandBufferCount = 1;
5581 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5582 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5583 m_errorMonitor->VerifyFound();
5584 // Now update descriptor to be valid, but then free descriptor
5585 img_info.imageView = view2;
5586 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005587 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005588 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005589 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5590 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5591 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005592 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5593 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005594 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005595 m_commandBuffer->EndRenderPass();
5596 m_commandBuffer->EndCommandBuffer();
Dave Houltonfbf52152017-01-06 12:55:29 -07005597
5598 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005600 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005601 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005602
5603 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005604 // TODO - though the particular error above doesn't re-occur, there are other 'unexpecteds' still to clean up
Dave Houltonfbf52152017-01-06 12:55:29 -07005605 vkQueueWaitIdle(m_device->m_queue);
5606 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5607
5608 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005609 submit_info = {};
5610 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5611 submit_info.commandBufferCount = 1;
5612 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005614 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5615 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005616
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005617 // Cleanup
5618 vkFreeMemory(m_device->device(), image_memory, NULL);
5619 vkDestroySampler(m_device->device(), sampler2, NULL);
5620 vkDestroyImage(m_device->device(), image2, NULL);
5621 vkDestroyImageView(m_device->device(), view, NULL);
5622 vkDestroyImageView(m_device->device(), view2, NULL);
5623 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5624 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5626}
5627
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005628TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5629 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5630 ASSERT_NO_FATAL_FAILURE(InitState());
5631 ASSERT_NO_FATAL_FAILURE(InitViewport());
5632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5633
5634 VkDescriptorPoolSize ds_type_count = {};
5635 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5636 ds_type_count.descriptorCount = 1;
5637
5638 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5639 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5640 ds_pool_ci.pNext = NULL;
5641 ds_pool_ci.maxSets = 1;
5642 ds_pool_ci.poolSizeCount = 1;
5643 ds_pool_ci.pPoolSizes = &ds_type_count;
5644
5645 VkDescriptorPool ds_pool;
5646 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5647 ASSERT_VK_SUCCESS(err);
5648
5649 VkDescriptorSetLayoutBinding dsl_binding = {};
5650 dsl_binding.binding = 0;
5651 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5652 dsl_binding.descriptorCount = 1;
5653 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5654 dsl_binding.pImmutableSamplers = NULL;
5655
5656 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5657 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5658 ds_layout_ci.pNext = NULL;
5659 ds_layout_ci.bindingCount = 1;
5660 ds_layout_ci.pBindings = &dsl_binding;
5661 VkDescriptorSetLayout ds_layout;
5662 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5663 ASSERT_VK_SUCCESS(err);
5664
5665 VkDescriptorSet descriptor_set;
5666 VkDescriptorSetAllocateInfo alloc_info = {};
5667 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5668 alloc_info.descriptorSetCount = 1;
5669 alloc_info.descriptorPool = ds_pool;
5670 alloc_info.pSetLayouts = &ds_layout;
5671 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
5672 ASSERT_VK_SUCCESS(err);
5673
5674 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5675 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5676 pipeline_layout_ci.pNext = NULL;
5677 pipeline_layout_ci.setLayoutCount = 1;
5678 pipeline_layout_ci.pSetLayouts = &ds_layout;
5679
5680 VkPipelineLayout pipeline_layout;
5681 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5682 ASSERT_VK_SUCCESS(err);
5683
5684 // Create image to update the descriptor with
5685 VkImageObj image(m_device);
5686 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5687 ASSERT_TRUE(image.initialized());
5688
5689 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5690 // Create Sampler
5691 VkSamplerCreateInfo sampler_ci = {};
5692 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5693 sampler_ci.pNext = NULL;
5694 sampler_ci.magFilter = VK_FILTER_NEAREST;
5695 sampler_ci.minFilter = VK_FILTER_NEAREST;
5696 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5697 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5698 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5699 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5700 sampler_ci.mipLodBias = 1.0;
5701 sampler_ci.anisotropyEnable = VK_FALSE;
5702 sampler_ci.maxAnisotropy = 1;
5703 sampler_ci.compareEnable = VK_FALSE;
5704 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5705 sampler_ci.minLod = 1.0;
5706 sampler_ci.maxLod = 1.0;
5707 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5708 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5709 VkSampler sampler;
5710 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5711 ASSERT_VK_SUCCESS(err);
5712 // Update descriptor with image and sampler
5713 VkDescriptorImageInfo img_info = {};
5714 img_info.sampler = sampler;
5715 img_info.imageView = view;
5716 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5717
5718 VkWriteDescriptorSet descriptor_write;
5719 memset(&descriptor_write, 0, sizeof(descriptor_write));
5720 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5721 descriptor_write.dstSet = descriptor_set;
5722 descriptor_write.dstBinding = 0;
5723 descriptor_write.descriptorCount = 1;
5724 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5725 descriptor_write.pImageInfo = &img_info;
5726
5727 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5728
5729 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005730 char const *vsSource =
5731 "#version 450\n"
5732 "\n"
5733 "out gl_PerVertex { \n"
5734 " vec4 gl_Position;\n"
5735 "};\n"
5736 "void main(){\n"
5737 " gl_Position = vec4(1);\n"
5738 "}\n";
5739 char const *fsSource =
5740 "#version 450\n"
5741 "\n"
5742 "layout(set=0, binding=0) uniform sampler2D s;\n"
5743 "layout(location=0) out vec4 x;\n"
5744 "void main(){\n"
5745 " x = texture(s, vec2(1));\n"
5746 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005747 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5748 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5749 VkPipelineObj pipe(m_device);
5750 pipe.AddShader(&vs);
5751 pipe.AddShader(&fs);
5752 pipe.AddColorAttachment();
5753 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5754
Tony Barbour552f6c02016-12-21 14:34:07 -07005755 m_commandBuffer->BeginCommandBuffer();
5756 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005757 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5758 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5759 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005760
5761 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5762 VkRect2D scissor = {{0, 0}, {16, 16}};
5763 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5764 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
5765
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005766 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005767 m_commandBuffer->EndRenderPass();
5768 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005769 // Submit cmd buffer to put pool in-flight
5770 VkSubmitInfo submit_info = {};
5771 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5772 submit_info.commandBufferCount = 1;
5773 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5774 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5775 // Destroy pool while in-flight, causing error
5776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
5777 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5778 m_errorMonitor->VerifyFound();
5779 vkQueueWaitIdle(m_device->m_queue);
5780 // Cleanup
5781 vkDestroySampler(m_device->device(), sampler, NULL);
5782 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5783 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5784 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07005785 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005786}
5787
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005788TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
5789 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
5790 ASSERT_NO_FATAL_FAILURE(InitState());
5791 ASSERT_NO_FATAL_FAILURE(InitViewport());
5792 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5793
5794 VkDescriptorPoolSize ds_type_count = {};
5795 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5796 ds_type_count.descriptorCount = 1;
5797
5798 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5799 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5800 ds_pool_ci.pNext = NULL;
5801 ds_pool_ci.maxSets = 1;
5802 ds_pool_ci.poolSizeCount = 1;
5803 ds_pool_ci.pPoolSizes = &ds_type_count;
5804
5805 VkDescriptorPool ds_pool;
5806 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
5807 ASSERT_VK_SUCCESS(err);
5808
5809 VkDescriptorSetLayoutBinding dsl_binding = {};
5810 dsl_binding.binding = 0;
5811 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5812 dsl_binding.descriptorCount = 1;
5813 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5814 dsl_binding.pImmutableSamplers = NULL;
5815
5816 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5817 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5818 ds_layout_ci.pNext = NULL;
5819 ds_layout_ci.bindingCount = 1;
5820 ds_layout_ci.pBindings = &dsl_binding;
5821 VkDescriptorSetLayout ds_layout;
5822 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
5823 ASSERT_VK_SUCCESS(err);
5824
5825 VkDescriptorSet descriptorSet;
5826 VkDescriptorSetAllocateInfo alloc_info = {};
5827 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5828 alloc_info.descriptorSetCount = 1;
5829 alloc_info.descriptorPool = ds_pool;
5830 alloc_info.pSetLayouts = &ds_layout;
5831 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
5832 ASSERT_VK_SUCCESS(err);
5833
5834 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5835 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5836 pipeline_layout_ci.pNext = NULL;
5837 pipeline_layout_ci.setLayoutCount = 1;
5838 pipeline_layout_ci.pSetLayouts = &ds_layout;
5839
5840 VkPipelineLayout pipeline_layout;
5841 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5842 ASSERT_VK_SUCCESS(err);
5843
5844 // Create images to update the descriptor with
5845 VkImage image;
5846 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5847 const int32_t tex_width = 32;
5848 const int32_t tex_height = 32;
5849 VkImageCreateInfo image_create_info = {};
5850 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5851 image_create_info.pNext = NULL;
5852 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5853 image_create_info.format = tex_format;
5854 image_create_info.extent.width = tex_width;
5855 image_create_info.extent.height = tex_height;
5856 image_create_info.extent.depth = 1;
5857 image_create_info.mipLevels = 1;
5858 image_create_info.arrayLayers = 1;
5859 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5860 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5861 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5862 image_create_info.flags = 0;
5863 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5864 ASSERT_VK_SUCCESS(err);
5865 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
5866 VkMemoryRequirements memory_reqs;
5867 VkDeviceMemory image_memory;
5868 bool pass;
5869 VkMemoryAllocateInfo memory_info = {};
5870 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5871 memory_info.pNext = NULL;
5872 memory_info.allocationSize = 0;
5873 memory_info.memoryTypeIndex = 0;
5874 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5875 // Allocate enough memory for image
5876 memory_info.allocationSize = memory_reqs.size;
5877 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5878 ASSERT_TRUE(pass);
5879 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5880 ASSERT_VK_SUCCESS(err);
5881 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5882 ASSERT_VK_SUCCESS(err);
5883
5884 VkImageViewCreateInfo image_view_create_info = {};
5885 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5886 image_view_create_info.image = image;
5887 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5888 image_view_create_info.format = tex_format;
5889 image_view_create_info.subresourceRange.layerCount = 1;
5890 image_view_create_info.subresourceRange.baseMipLevel = 0;
5891 image_view_create_info.subresourceRange.levelCount = 1;
5892 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5893
5894 VkImageView view;
5895 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
5896 ASSERT_VK_SUCCESS(err);
5897 // Create Samplers
5898 VkSamplerCreateInfo sampler_ci = {};
5899 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5900 sampler_ci.pNext = NULL;
5901 sampler_ci.magFilter = VK_FILTER_NEAREST;
5902 sampler_ci.minFilter = VK_FILTER_NEAREST;
5903 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5904 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5905 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5906 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5907 sampler_ci.mipLodBias = 1.0;
5908 sampler_ci.anisotropyEnable = VK_FALSE;
5909 sampler_ci.maxAnisotropy = 1;
5910 sampler_ci.compareEnable = VK_FALSE;
5911 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5912 sampler_ci.minLod = 1.0;
5913 sampler_ci.maxLod = 1.0;
5914 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5915 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5916 VkSampler sampler;
5917 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5918 ASSERT_VK_SUCCESS(err);
5919 // Update descriptor with image and sampler
5920 VkDescriptorImageInfo img_info = {};
5921 img_info.sampler = sampler;
5922 img_info.imageView = view;
5923 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5924
5925 VkWriteDescriptorSet descriptor_write;
5926 memset(&descriptor_write, 0, sizeof(descriptor_write));
5927 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5928 descriptor_write.dstSet = descriptorSet;
5929 descriptor_write.dstBinding = 0;
5930 descriptor_write.descriptorCount = 1;
5931 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5932 descriptor_write.pImageInfo = &img_info;
5933 // Break memory binding and attempt update
5934 vkFreeMemory(m_device->device(), image_memory, nullptr);
5935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005936 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06005937 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
5938 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
5939 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5940 m_errorMonitor->VerifyFound();
5941 // Cleanup
5942 vkDestroyImage(m_device->device(), image, NULL);
5943 vkDestroySampler(m_device->device(), sampler, NULL);
5944 vkDestroyImageView(m_device->device(), view, NULL);
5945 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5946 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5947 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5948}
5949
Karl Schultz6addd812016-02-02 17:17:23 -07005950TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06005951 // Attempt to bind an invalid Pipeline to a valid Command Buffer
5952 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005953 // Create a valid cmd buffer
5954 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06005955 uint64_t fake_pipeline_handle = 0xbaad6001;
5956 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06005957 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005958 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5959
Karl Schultzf78bcdd2016-11-30 12:36:01 -07005960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07005961 m_commandBuffer->BeginCommandBuffer();
5962 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005963 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06005964 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005965
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005966 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005967 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 -06005968 Draw(1, 0, 0, 0);
5969 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12005970
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005971 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "At Draw/Dispatch time no valid VkPipeline is bound!");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005973 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06005974 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
5975 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06005976}
5977
Karl Schultz6addd812016-02-02 17:17:23 -07005978TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06005979 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07005980 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005981
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06005983
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005984 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06005985 ASSERT_NO_FATAL_FAILURE(InitViewport());
5986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08005987 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005988 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5989 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06005990
5991 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07005992 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5993 ds_pool_ci.pNext = NULL;
5994 ds_pool_ci.maxSets = 1;
5995 ds_pool_ci.poolSizeCount = 1;
5996 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06005997
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06005998 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005999 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006000 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006001
Tony Barboureb254902015-07-15 12:50:33 -06006002 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006003 dsl_binding.binding = 0;
6004 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6005 dsl_binding.descriptorCount = 1;
6006 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6007 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006008
Tony Barboureb254902015-07-15 12:50:33 -06006009 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006010 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6011 ds_layout_ci.pNext = NULL;
6012 ds_layout_ci.bindingCount = 1;
6013 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006014 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006015 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006016 ASSERT_VK_SUCCESS(err);
6017
6018 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006019 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006020 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006021 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006022 alloc_info.descriptorPool = ds_pool;
6023 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006024 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006025 ASSERT_VK_SUCCESS(err);
6026
Tony Barboureb254902015-07-15 12:50:33 -06006027 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006028 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6029 pipeline_layout_ci.pNext = NULL;
6030 pipeline_layout_ci.setLayoutCount = 1;
6031 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006032
6033 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006034 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006035 ASSERT_VK_SUCCESS(err);
6036
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006037 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006038 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006039 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006040 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006041
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006042 VkPipelineObj pipe(m_device);
6043 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006044 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006045 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006046 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006047
Tony Barbour552f6c02016-12-21 14:34:07 -07006048 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006049 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6050 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6051 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006052
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006053 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006054
Chia-I Wuf7458c52015-10-26 21:10:41 +08006055 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6056 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6057 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006058}
6059
Karl Schultz6addd812016-02-02 17:17:23 -07006060TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006061 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006062 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006063
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006065
6066 ASSERT_NO_FATAL_FAILURE(InitState());
6067 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006068 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6069 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006070
6071 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006072 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6073 ds_pool_ci.pNext = NULL;
6074 ds_pool_ci.maxSets = 1;
6075 ds_pool_ci.poolSizeCount = 1;
6076 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006077
6078 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006079 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006080 ASSERT_VK_SUCCESS(err);
6081
6082 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006083 dsl_binding.binding = 0;
6084 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6085 dsl_binding.descriptorCount = 1;
6086 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6087 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006088
6089 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006090 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6091 ds_layout_ci.pNext = NULL;
6092 ds_layout_ci.bindingCount = 1;
6093 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006094 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006095 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006096 ASSERT_VK_SUCCESS(err);
6097
6098 VkDescriptorSet descriptorSet;
6099 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006100 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006101 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006102 alloc_info.descriptorPool = ds_pool;
6103 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006104 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006105 ASSERT_VK_SUCCESS(err);
6106
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006107 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006108 VkWriteDescriptorSet descriptor_write;
6109 memset(&descriptor_write, 0, sizeof(descriptor_write));
6110 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6111 descriptor_write.dstSet = descriptorSet;
6112 descriptor_write.dstBinding = 0;
6113 descriptor_write.descriptorCount = 1;
6114 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6115 descriptor_write.pTexelBufferView = &view;
6116
6117 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006119 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006120
6121 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6122 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6123}
6124
Mark Youngd339ba32016-05-30 13:28:35 -06006125TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006126 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 -06006127
6128 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006130 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006131
6132 ASSERT_NO_FATAL_FAILURE(InitState());
6133
6134 // Create a buffer with no bound memory and then attempt to create
6135 // a buffer view.
6136 VkBufferCreateInfo buff_ci = {};
6137 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006138 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006139 buff_ci.size = 256;
6140 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6141 VkBuffer buffer;
6142 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6143 ASSERT_VK_SUCCESS(err);
6144
6145 VkBufferViewCreateInfo buff_view_ci = {};
6146 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6147 buff_view_ci.buffer = buffer;
6148 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6149 buff_view_ci.range = VK_WHOLE_SIZE;
6150 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006151 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006152
6153 m_errorMonitor->VerifyFound();
6154 vkDestroyBuffer(m_device->device(), buffer, NULL);
6155 // If last error is success, it still created the view, so delete it.
6156 if (err == VK_SUCCESS) {
6157 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6158 }
6159}
6160
Karl Schultz6addd812016-02-02 17:17:23 -07006161TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6162 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6163 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006164 // 1. No dynamicOffset supplied
6165 // 2. Too many dynamicOffsets supplied
6166 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006167 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6169 " requires 1 dynamicOffsets, but only "
6170 "0 dynamicOffsets are left in "
6171 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006172
6173 ASSERT_NO_FATAL_FAILURE(InitState());
6174 ASSERT_NO_FATAL_FAILURE(InitViewport());
6175 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6176
6177 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006178 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6179 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006180
6181 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006182 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6183 ds_pool_ci.pNext = NULL;
6184 ds_pool_ci.maxSets = 1;
6185 ds_pool_ci.poolSizeCount = 1;
6186 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006187
6188 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006189 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006190 ASSERT_VK_SUCCESS(err);
6191
6192 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006193 dsl_binding.binding = 0;
6194 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6195 dsl_binding.descriptorCount = 1;
6196 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6197 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006198
6199 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006200 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6201 ds_layout_ci.pNext = NULL;
6202 ds_layout_ci.bindingCount = 1;
6203 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006204 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006206 ASSERT_VK_SUCCESS(err);
6207
6208 VkDescriptorSet descriptorSet;
6209 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006210 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006211 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006212 alloc_info.descriptorPool = ds_pool;
6213 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006214 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006215 ASSERT_VK_SUCCESS(err);
6216
6217 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006218 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6219 pipeline_layout_ci.pNext = NULL;
6220 pipeline_layout_ci.setLayoutCount = 1;
6221 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006222
6223 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006224 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006225 ASSERT_VK_SUCCESS(err);
6226
6227 // Create a buffer to update the descriptor with
6228 uint32_t qfi = 0;
6229 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006230 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6231 buffCI.size = 1024;
6232 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6233 buffCI.queueFamilyIndexCount = 1;
6234 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006235
6236 VkBuffer dyub;
6237 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6238 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006239 // Allocate memory and bind to buffer so we can make it to the appropriate
6240 // error
6241 VkMemoryAllocateInfo mem_alloc = {};
6242 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6243 mem_alloc.pNext = NULL;
6244 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006245 mem_alloc.memoryTypeIndex = 0;
6246
6247 VkMemoryRequirements memReqs;
6248 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006249 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006250 if (!pass) {
6251 vkDestroyBuffer(m_device->device(), dyub, NULL);
6252 return;
6253 }
6254
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006255 VkDeviceMemory mem;
6256 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6257 ASSERT_VK_SUCCESS(err);
6258 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6259 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006260 // Correctly update descriptor to avoid "NOT_UPDATED" error
6261 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006262 buffInfo.buffer = dyub;
6263 buffInfo.offset = 0;
6264 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006265
6266 VkWriteDescriptorSet descriptor_write;
6267 memset(&descriptor_write, 0, sizeof(descriptor_write));
6268 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6269 descriptor_write.dstSet = descriptorSet;
6270 descriptor_write.dstBinding = 0;
6271 descriptor_write.descriptorCount = 1;
6272 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6273 descriptor_write.pBufferInfo = &buffInfo;
6274
6275 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6276
Tony Barbour552f6c02016-12-21 14:34:07 -07006277 m_commandBuffer->BeginCommandBuffer();
6278 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006279 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6280 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006281 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006282 uint32_t pDynOff[2] = {512, 756};
6283 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6285 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6286 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6287 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006288 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006289 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6291 " dynamic offset 512 combined with "
6292 "offset 0 and range 1024 that "
6293 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006294 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006295 char const *vsSource =
6296 "#version 450\n"
6297 "\n"
6298 "out gl_PerVertex { \n"
6299 " vec4 gl_Position;\n"
6300 "};\n"
6301 "void main(){\n"
6302 " gl_Position = vec4(1);\n"
6303 "}\n";
6304 char const *fsSource =
6305 "#version 450\n"
6306 "\n"
6307 "layout(location=0) out vec4 x;\n"
6308 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6309 "void main(){\n"
6310 " x = vec4(bar.y);\n"
6311 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006312 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6313 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6314 VkPipelineObj pipe(m_device);
6315 pipe.AddShader(&vs);
6316 pipe.AddShader(&fs);
6317 pipe.AddColorAttachment();
6318 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6319
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006320 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6321 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6322 VkRect2D scissor = {{0, 0}, {16, 16}};
6323 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6324
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006325 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006326 // This update should succeed, but offset size of 512 will overstep buffer
6327 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006328 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6329 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006330 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006331 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006332
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006333 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006334 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006335
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006336 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006337 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006338 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6339}
6340
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006341TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006342 TEST_DESCRIPTION(
6343 "Attempt to update a descriptor with a non-sparse buffer "
6344 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006345 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006346 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006347 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6349 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006350
6351 ASSERT_NO_FATAL_FAILURE(InitState());
6352 ASSERT_NO_FATAL_FAILURE(InitViewport());
6353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6354
6355 VkDescriptorPoolSize ds_type_count = {};
6356 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6357 ds_type_count.descriptorCount = 1;
6358
6359 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6360 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6361 ds_pool_ci.pNext = NULL;
6362 ds_pool_ci.maxSets = 1;
6363 ds_pool_ci.poolSizeCount = 1;
6364 ds_pool_ci.pPoolSizes = &ds_type_count;
6365
6366 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006367 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006368 ASSERT_VK_SUCCESS(err);
6369
6370 VkDescriptorSetLayoutBinding dsl_binding = {};
6371 dsl_binding.binding = 0;
6372 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6373 dsl_binding.descriptorCount = 1;
6374 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6375 dsl_binding.pImmutableSamplers = NULL;
6376
6377 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6378 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6379 ds_layout_ci.pNext = NULL;
6380 ds_layout_ci.bindingCount = 1;
6381 ds_layout_ci.pBindings = &dsl_binding;
6382 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006383 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006384 ASSERT_VK_SUCCESS(err);
6385
6386 VkDescriptorSet descriptorSet;
6387 VkDescriptorSetAllocateInfo alloc_info = {};
6388 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6389 alloc_info.descriptorSetCount = 1;
6390 alloc_info.descriptorPool = ds_pool;
6391 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006392 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006393 ASSERT_VK_SUCCESS(err);
6394
6395 // Create a buffer to update the descriptor with
6396 uint32_t qfi = 0;
6397 VkBufferCreateInfo buffCI = {};
6398 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6399 buffCI.size = 1024;
6400 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6401 buffCI.queueFamilyIndexCount = 1;
6402 buffCI.pQueueFamilyIndices = &qfi;
6403
6404 VkBuffer dyub;
6405 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6406 ASSERT_VK_SUCCESS(err);
6407
6408 // Attempt to update descriptor without binding memory to it
6409 VkDescriptorBufferInfo buffInfo = {};
6410 buffInfo.buffer = dyub;
6411 buffInfo.offset = 0;
6412 buffInfo.range = 1024;
6413
6414 VkWriteDescriptorSet descriptor_write;
6415 memset(&descriptor_write, 0, sizeof(descriptor_write));
6416 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6417 descriptor_write.dstSet = descriptorSet;
6418 descriptor_write.dstBinding = 0;
6419 descriptor_write.descriptorCount = 1;
6420 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6421 descriptor_write.pBufferInfo = &buffInfo;
6422
6423 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6424 m_errorMonitor->VerifyFound();
6425
6426 vkDestroyBuffer(m_device->device(), dyub, NULL);
6427 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6428 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6429}
6430
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006431TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006432 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006433 ASSERT_NO_FATAL_FAILURE(InitState());
6434 ASSERT_NO_FATAL_FAILURE(InitViewport());
6435 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6436
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006437 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006438 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006439 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6440 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6441 pipeline_layout_ci.pushConstantRangeCount = 1;
6442 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6443
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006444 //
6445 // Check for invalid push constant ranges in pipeline layouts.
6446 //
6447 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006448 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006449 char const *msg;
6450 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006451
Karl Schultzc81037d2016-05-12 08:11:23 -06006452 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6453 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6454 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6455 "vkCreatePipelineLayout() call has push constants index 0 with "
6456 "size 0."},
6457 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6458 "vkCreatePipelineLayout() call has push constants index 0 with "
6459 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006460 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006461 "vkCreatePipelineLayout() call has push constants index 0 with "
6462 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006463 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006464 "vkCreatePipelineLayout() call has push constants index 0 with "
6465 "size 0."},
6466 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6467 "vkCreatePipelineLayout() call has push constants index 0 with "
6468 "offset 1. Offset must"},
6469 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6470 "vkCreatePipelineLayout() call has push constants index 0 "
6471 "with offset "},
6472 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6473 "vkCreatePipelineLayout() call has push constants "
6474 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006475 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006476 "vkCreatePipelineLayout() call has push constants index 0 "
6477 "with offset "},
6478 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6479 "vkCreatePipelineLayout() call has push "
6480 "constants index 0 with offset "},
6481 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6482 "vkCreatePipelineLayout() call has push "
6483 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006484 }};
6485
6486 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006487 for (const auto &iter : range_tests) {
6488 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006489 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6490 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006491 m_errorMonitor->VerifyFound();
6492 if (VK_SUCCESS == err) {
6493 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6494 }
6495 }
6496
6497 // Check for invalid stage flag
6498 pc_range.offset = 0;
6499 pc_range.size = 16;
6500 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006501 m_errorMonitor->SetDesiredFailureMsg(
6502 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6503 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006504 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006505 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006506 if (VK_SUCCESS == err) {
6507 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6508 }
6509
6510 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006511 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006512 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006513 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006514 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006515 };
6516
Karl Schultzc81037d2016-05-12 08:11:23 -06006517 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006518 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6519 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6520 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6521 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6522 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006523 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6524 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6525 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6526 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6527 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6528 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6529 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6530 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6531 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6532 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006533 {
6534 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6535 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6536 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6537 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6538 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006539 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006540 },
6541 {
6542 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6543 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6544 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6545 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6546 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006547 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006548 },
6549 {
6550 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6551 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6552 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6553 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6554 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006555 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006556 },
6557 {
6558 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6559 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6560 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6561 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6562 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006563 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6564 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6565 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6566 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006567 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006568
Karl Schultzc81037d2016-05-12 08:11:23 -06006569 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006570 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006571 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006573 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006574 m_errorMonitor->VerifyFound();
6575 if (VK_SUCCESS == err) {
6576 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6577 }
6578 }
6579
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006580 //
6581 // CmdPushConstants tests
6582 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006583 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006584
6585 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006586 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6587 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006588 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006589 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6590 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006591 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006592 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6593 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006594 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006595 "vkCmdPushConstants() call has push constants with offset 1. "
6596 "Offset must be a multiple of 4."},
6597 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6598 "vkCmdPushConstants() call has push constants with offset 1. "
6599 "Offset must be a multiple of 4."},
6600 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6601 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6602 "0x1 not within flag-matching ranges in pipeline layout"},
6603 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6604 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6605 "0x1 not within flag-matching ranges in pipeline layout"},
6606 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6607 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6608 "0x1 not within flag-matching ranges in pipeline layout"},
6609 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6610 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6611 "0x1 not within flag-matching ranges in pipeline layout"},
6612 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6613 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6614 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006615 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006616 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6617 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006618 }};
6619
Tony Barbour552f6c02016-12-21 14:34:07 -07006620 m_commandBuffer->BeginCommandBuffer();
6621 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006622
6623 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006624 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006625 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006626 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006627 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006628 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006629 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006630 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006631 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6633 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006634 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006635 m_errorMonitor->VerifyFound();
6636 }
6637
6638 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006639 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006640 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006641 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06006642 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006643
Karl Schultzc81037d2016-05-12 08:11:23 -06006644 // overlapping range tests with cmd
6645 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
6646 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6647 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6648 "0x1 not within flag-matching ranges in pipeline layout"},
6649 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6650 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
6651 "0x1 not within flag-matching ranges in pipeline layout"},
6652 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
6653 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
6654 "0x1 not within flag-matching ranges in pipeline layout"},
6655 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006656 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06006657 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006658 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
6659 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06006660 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006661 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06006662 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006663 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06006664 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006665 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6667 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006668 iter.range.size, dummy_values);
6669 m_errorMonitor->VerifyFound();
6670 }
Karl Schultzc81037d2016-05-12 08:11:23 -06006671 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6672
Tony Barbour552f6c02016-12-21 14:34:07 -07006673 m_commandBuffer->EndRenderPass();
6674 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006675}
6676
Karl Schultz6addd812016-02-02 17:17:23 -07006677TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07006678 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07006679 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006680
6681 ASSERT_NO_FATAL_FAILURE(InitState());
6682 ASSERT_NO_FATAL_FAILURE(InitViewport());
6683 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6684
6685 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
6686 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006687 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6688 ds_type_count[0].descriptorCount = 10;
6689 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
6690 ds_type_count[1].descriptorCount = 2;
6691 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6692 ds_type_count[2].descriptorCount = 2;
6693 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
6694 ds_type_count[3].descriptorCount = 5;
6695 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
6696 // type
6697 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
6698 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
6699 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006700
6701 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006702 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6703 ds_pool_ci.pNext = NULL;
6704 ds_pool_ci.maxSets = 5;
6705 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
6706 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006707
6708 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006709 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006710 ASSERT_VK_SUCCESS(err);
6711
6712 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
6713 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006714 dsl_binding[0].binding = 0;
6715 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6716 dsl_binding[0].descriptorCount = 5;
6717 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
6718 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006719
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006720 // Create layout identical to set0 layout but w/ different stageFlags
6721 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006722 dsl_fs_stage_only.binding = 0;
6723 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6724 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006725 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
6726 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07006727 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006728 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006729 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6730 ds_layout_ci.pNext = NULL;
6731 ds_layout_ci.bindingCount = 1;
6732 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006733 static const uint32_t NUM_LAYOUTS = 4;
6734 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006735 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006736 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
6737 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006739 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006740 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006741 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006742 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006743 dsl_binding[0].binding = 0;
6744 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006745 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07006746 dsl_binding[1].binding = 1;
6747 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6748 dsl_binding[1].descriptorCount = 2;
6749 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
6750 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07006751 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006752 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006753 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006754 ASSERT_VK_SUCCESS(err);
6755 dsl_binding[0].binding = 0;
6756 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006757 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006758 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006759 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006760 ASSERT_VK_SUCCESS(err);
6761 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006762 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006763 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006764 ASSERT_VK_SUCCESS(err);
6765
6766 static const uint32_t NUM_SETS = 4;
6767 VkDescriptorSet descriptorSet[NUM_SETS] = {};
6768 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006769 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006770 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006771 alloc_info.descriptorPool = ds_pool;
6772 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006774 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006775 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07006776 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006777 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006779 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006780
6781 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006782 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6783 pipeline_layout_ci.pNext = NULL;
6784 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
6785 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07006786
6787 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006788 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006789 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006790 // Create pipelineLayout with only one setLayout
6791 pipeline_layout_ci.setLayoutCount = 1;
6792 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006793 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006794 ASSERT_VK_SUCCESS(err);
6795 // Create pipelineLayout with 2 descriptor setLayout at index 0
6796 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
6797 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006798 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006799 ASSERT_VK_SUCCESS(err);
6800 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
6801 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
6802 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006803 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006804 ASSERT_VK_SUCCESS(err);
6805 // Create pipelineLayout with UB type, but stageFlags for FS only
6806 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
6807 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006808 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006809 ASSERT_VK_SUCCESS(err);
6810 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
6811 VkDescriptorSetLayout pl_bad_s0[2] = {};
6812 pl_bad_s0[0] = ds_layout_fs_only;
6813 pl_bad_s0[1] = ds_layout[1];
6814 pipeline_layout_ci.setLayoutCount = 2;
6815 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
6816 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006817 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006818 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006819
Tobin Ehlis88452832015-12-03 09:40:56 -07006820 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006821 char const *vsSource =
6822 "#version 450\n"
6823 "\n"
6824 "out gl_PerVertex {\n"
6825 " vec4 gl_Position;\n"
6826 "};\n"
6827 "void main(){\n"
6828 " gl_Position = vec4(1);\n"
6829 "}\n";
6830 char const *fsSource =
6831 "#version 450\n"
6832 "\n"
6833 "layout(location=0) out vec4 x;\n"
6834 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6835 "void main(){\n"
6836 " x = vec4(bar.y);\n"
6837 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07006838 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6839 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006840 VkPipelineObj pipe(m_device);
6841 pipe.AddShader(&vs);
6842 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07006843 pipe.AddColorAttachment();
6844 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07006845
Tony Barbour552f6c02016-12-21 14:34:07 -07006846 m_commandBuffer->BeginCommandBuffer();
6847 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07006848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006849 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006850 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
6851 // of PSO
6852 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
6853 // cmd_pipeline.c
6854 // due to the fact that cmd_alloc_dset_data() has not been called in
6855 // cmd_bind_graphics_pipeline()
6856 // TODO : Want to cause various binding incompatibility issues here to test
6857 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07006858 // First cause various verify_layout_compatibility() fails
6859 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006860 // verify_set_layout_compatibility fail cases:
6861 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006863 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
6864 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006865 m_errorMonitor->VerifyFound();
6866
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006867 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
6869 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
6870 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006871 m_errorMonitor->VerifyFound();
6872
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006873 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006874 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
6875 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
6877 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
6878 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006879 m_errorMonitor->VerifyFound();
6880
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006881 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
6882 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
6884 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
6885 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006886 m_errorMonitor->VerifyFound();
6887
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006888 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
6889 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6891 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
6892 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6893 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006894 m_errorMonitor->VerifyFound();
6895
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006896 // Cause INFO messages due to disturbing previously bound Sets
6897 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6899 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006900 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006901 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
6902 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6903 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006904 m_errorMonitor->VerifyFound();
6905
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006906 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6907 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006908 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
6910 " newly bound as set #0 so set #1 and "
6911 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006912 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
6913 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006914 m_errorMonitor->VerifyFound();
6915
Tobin Ehlis10fad692016-07-07 12:00:36 -06006916 // Now that we're done actively using the pipelineLayout that gfx pipeline
6917 // was created with, we should be able to delete it. Do that now to verify
6918 // that validation obeys pipelineLayout lifetime
6919 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
6920
Tobin Ehlis88452832015-12-03 09:40:56 -07006921 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07006922 // 1. Error due to not binding required set (we actually use same code as
6923 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006924 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6925 &descriptorSet[0], 0, NULL);
6926 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
6927 &descriptorSet[1], 0, NULL);
6928 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 -07006929
6930 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6931 VkRect2D scissor = {{0, 0}, {16, 16}};
6932 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6933 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6934
Tobin Ehlis88452832015-12-03 09:40:56 -07006935 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006936 m_errorMonitor->VerifyFound();
6937
Tobin Ehlis991d45a2016-01-06 08:48:41 -07006938 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07006939 // 2. Error due to bound set not being compatible with PSO's
6940 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006941 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
6942 &descriptorSet[0], 0, NULL);
6943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07006944 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006945 m_errorMonitor->VerifyFound();
6946
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006947 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07006948 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07006949 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
6950 }
6951 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07006952 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6953 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6954}
Tobin Ehlis559c6382015-11-05 09:52:49 -07006955
Karl Schultz6addd812016-02-02 17:17:23 -07006956TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6958 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006959
6960 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006961 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006962 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006963 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006964
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006965 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006966}
6967
Karl Schultz6addd812016-02-02 17:17:23 -07006968TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
6969 VkResult err;
6970 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006971
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006972 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006973
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006974 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006975
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006976 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006977 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006978 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006979 cmd.commandPool = m_commandPool;
6980 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006981 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06006982
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006983 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06006984 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006985
6986 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07006987 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07006988 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
6989
6990 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006991 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06006992 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006993 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 -07006994 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06006995
6996 // The error should be caught by validation of the BeginCommandBuffer call
6997 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
6998
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006999 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007000 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007001}
7002
Karl Schultz6addd812016-02-02 17:17:23 -07007003TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007004 // Cause error due to Begin while recording CB
7005 // Then cause 2 errors for attempting to reset CB w/o having
7006 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7007 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007009
7010 ASSERT_NO_FATAL_FAILURE(InitState());
7011
7012 // Calls AllocateCommandBuffers
7013 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7014
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007015 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007016 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007017 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7018 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007019 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7020 cmd_buf_info.pNext = NULL;
7021 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007022 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007023
7024 // Begin CB to transition to recording state
7025 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7026 // Can't re-begin. This should trigger error
7027 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007028 m_errorMonitor->VerifyFound();
7029
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007030 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007031 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007032 // Reset attempt will trigger error due to incorrect CommandPool state
7033 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007034 m_errorMonitor->VerifyFound();
7035
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007037 // Transition CB to RECORDED state
7038 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7039 // Now attempting to Begin will implicitly reset, which triggers error
7040 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007041 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007042}
7043
Karl Schultz6addd812016-02-02 17:17:23 -07007044TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007045 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007046 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007047
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7049 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007050
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007051 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007053
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007054 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007055 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7056 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007057
7058 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007059 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7060 ds_pool_ci.pNext = NULL;
7061 ds_pool_ci.maxSets = 1;
7062 ds_pool_ci.poolSizeCount = 1;
7063 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007064
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007065 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007066 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007067 ASSERT_VK_SUCCESS(err);
7068
Tony Barboureb254902015-07-15 12:50:33 -06007069 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007070 dsl_binding.binding = 0;
7071 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7072 dsl_binding.descriptorCount = 1;
7073 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7074 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007075
Tony Barboureb254902015-07-15 12:50:33 -06007076 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007077 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7078 ds_layout_ci.pNext = NULL;
7079 ds_layout_ci.bindingCount = 1;
7080 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007081
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007082 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007083 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007084 ASSERT_VK_SUCCESS(err);
7085
7086 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007087 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007088 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007089 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007090 alloc_info.descriptorPool = ds_pool;
7091 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007092 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007093 ASSERT_VK_SUCCESS(err);
7094
Tony Barboureb254902015-07-15 12:50:33 -06007095 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007096 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7097 pipeline_layout_ci.setLayoutCount = 1;
7098 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007099
7100 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007101 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007102 ASSERT_VK_SUCCESS(err);
7103
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007104 VkViewport vp = {}; // Just need dummy vp to point to
7105 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007106
7107 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007108 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7109 vp_state_ci.scissorCount = 1;
7110 vp_state_ci.pScissors = &sc;
7111 vp_state_ci.viewportCount = 1;
7112 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007113
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007114 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7115 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7116 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7117 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7118 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7119 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007120 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007121 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007122 rs_state_ci.lineWidth = 1.0f;
7123
7124 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7125 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7126 vi_ci.pNext = nullptr;
7127 vi_ci.vertexBindingDescriptionCount = 0;
7128 vi_ci.pVertexBindingDescriptions = nullptr;
7129 vi_ci.vertexAttributeDescriptionCount = 0;
7130 vi_ci.pVertexAttributeDescriptions = nullptr;
7131
7132 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7133 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7134 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7135
7136 VkPipelineShaderStageCreateInfo shaderStages[2];
7137 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7138
7139 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7140 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7141 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
7142 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007143
Tony Barboureb254902015-07-15 12:50:33 -06007144 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007145 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7146 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007147 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007148 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7149 gp_ci.layout = pipeline_layout;
7150 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007151 gp_ci.pVertexInputState = &vi_ci;
7152 gp_ci.pInputAssemblyState = &ia_ci;
7153
7154 gp_ci.stageCount = 1;
7155 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007156
7157 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007158 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7159 pc_ci.initialDataSize = 0;
7160 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007161
7162 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007163 VkPipelineCache pipelineCache;
7164
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007166 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007167 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007168 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007169
Chia-I Wuf7458c52015-10-26 21:10:41 +08007170 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7171 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7172 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7173 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007174}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007175
Tobin Ehlis912df022015-09-17 08:46:18 -06007176/*// TODO : This test should be good, but needs Tess support in compiler to run
7177TEST_F(VkLayerTest, InvalidPatchControlPoints)
7178{
7179 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007180 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007181
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007183 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7184primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007185
Tobin Ehlis912df022015-09-17 08:46:18 -06007186 ASSERT_NO_FATAL_FAILURE(InitState());
7187 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007188
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007189 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007190 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007191 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007192
7193 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7194 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7195 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007196 ds_pool_ci.poolSizeCount = 1;
7197 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007198
7199 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007200 err = vkCreateDescriptorPool(m_device->device(),
7201VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007202 ASSERT_VK_SUCCESS(err);
7203
7204 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007205 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007206 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007207 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007208 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7209 dsl_binding.pImmutableSamplers = NULL;
7210
7211 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007212 ds_layout_ci.sType =
7213VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007214 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007215 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007216 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007217
7218 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007219 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7220&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007221 ASSERT_VK_SUCCESS(err);
7222
7223 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007224 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7225VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007226 ASSERT_VK_SUCCESS(err);
7227
7228 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007229 pipeline_layout_ci.sType =
7230VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007231 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007232 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007233 pipeline_layout_ci.pSetLayouts = &ds_layout;
7234
7235 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007236 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7237&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007238 ASSERT_VK_SUCCESS(err);
7239
7240 VkPipelineShaderStageCreateInfo shaderStages[3];
7241 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7242
Karl Schultz6addd812016-02-02 17:17:23 -07007243 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7244this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007245 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007246 VkShaderObj
7247tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7248this);
7249 VkShaderObj
7250te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7251this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007252
Karl Schultz6addd812016-02-02 17:17:23 -07007253 shaderStages[0].sType =
7254VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007255 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007256 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007257 shaderStages[1].sType =
7258VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007259 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007260 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007261 shaderStages[2].sType =
7262VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007263 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007264 shaderStages[2].shader = te.handle();
7265
7266 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007267 iaCI.sType =
7268VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007269 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007270
7271 VkPipelineTessellationStateCreateInfo tsCI = {};
7272 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7273 tsCI.patchControlPoints = 0; // This will cause an error
7274
7275 VkGraphicsPipelineCreateInfo gp_ci = {};
7276 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7277 gp_ci.pNext = NULL;
7278 gp_ci.stageCount = 3;
7279 gp_ci.pStages = shaderStages;
7280 gp_ci.pVertexInputState = NULL;
7281 gp_ci.pInputAssemblyState = &iaCI;
7282 gp_ci.pTessellationState = &tsCI;
7283 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007284 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007285 gp_ci.pMultisampleState = NULL;
7286 gp_ci.pDepthStencilState = NULL;
7287 gp_ci.pColorBlendState = NULL;
7288 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7289 gp_ci.layout = pipeline_layout;
7290 gp_ci.renderPass = renderPass();
7291
7292 VkPipelineCacheCreateInfo pc_ci = {};
7293 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7294 pc_ci.pNext = NULL;
7295 pc_ci.initialSize = 0;
7296 pc_ci.initialData = 0;
7297 pc_ci.maxSize = 0;
7298
7299 VkPipeline pipeline;
7300 VkPipelineCache pipelineCache;
7301
Karl Schultz6addd812016-02-02 17:17:23 -07007302 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7303&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007304 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007305 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7306&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007307
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007308 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007309
Chia-I Wuf7458c52015-10-26 21:10:41 +08007310 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7311 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7312 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7313 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007314}
7315*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007316
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007317TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007318 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007319
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007320 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007321
Tobin Ehlise68360f2015-10-01 11:15:13 -06007322 ASSERT_NO_FATAL_FAILURE(InitState());
7323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007324
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007325 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007326 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7327 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007328
7329 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007330 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7331 ds_pool_ci.maxSets = 1;
7332 ds_pool_ci.poolSizeCount = 1;
7333 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007334
7335 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007337 ASSERT_VK_SUCCESS(err);
7338
7339 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007340 dsl_binding.binding = 0;
7341 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7342 dsl_binding.descriptorCount = 1;
7343 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007344
7345 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007346 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7347 ds_layout_ci.bindingCount = 1;
7348 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007349
7350 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007351 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007352 ASSERT_VK_SUCCESS(err);
7353
7354 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007355 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007356 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007357 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007358 alloc_info.descriptorPool = ds_pool;
7359 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007361 ASSERT_VK_SUCCESS(err);
7362
7363 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007364 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7365 pipeline_layout_ci.setLayoutCount = 1;
7366 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007367
7368 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007369 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007370 ASSERT_VK_SUCCESS(err);
7371
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007372 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007373 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007374 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007375 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007376 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007377 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007378
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007379 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7380 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7381 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7382 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7383 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7384 rs_state_ci.depthClampEnable = VK_FALSE;
7385 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7386 rs_state_ci.depthBiasEnable = VK_FALSE;
7387
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007388 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7389 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7390 vi_ci.pNext = nullptr;
7391 vi_ci.vertexBindingDescriptionCount = 0;
7392 vi_ci.pVertexBindingDescriptions = nullptr;
7393 vi_ci.vertexAttributeDescriptionCount = 0;
7394 vi_ci.pVertexAttributeDescriptions = nullptr;
7395
7396 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 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7401 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7402 pipe_ms_state_ci.pNext = NULL;
7403 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7404 pipe_ms_state_ci.sampleShadingEnable = 0;
7405 pipe_ms_state_ci.minSampleShading = 1.0;
7406 pipe_ms_state_ci.pSampleMask = NULL;
7407
Cody Northropeb3a6c12015-10-05 14:44:45 -06007408 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007409 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007410
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007411 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007412 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007413 shaderStages[0] = vs.GetStageCreateInfo();
7414 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007415
7416 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007417 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7418 gp_ci.stageCount = 2;
7419 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007420 gp_ci.pVertexInputState = &vi_ci;
7421 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007422 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007423 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007424 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007425 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7426 gp_ci.layout = pipeline_layout;
7427 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007428
7429 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007430 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007431
7432 VkPipeline pipeline;
7433 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007434 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007435 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007436
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007437 if (!m_device->phy().features().multiViewport) {
7438 printf("MultiViewport feature is disabled -- skipping enabled-state checks.\n");
7439
7440 // Check case where multiViewport is disabled and viewport count is not 1
7441 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7442 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7443 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7444 vp_state_ci.scissorCount = 0;
7445 vp_state_ci.viewportCount = 0;
7446 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7447 m_errorMonitor->VerifyFound();
7448 } else {
7449 if (m_device->props.limits.maxViewports == 1) {
7450 printf("Device limit maxViewports is 1, skipping tests that require higher limits.\n");
7451 } else {
7452 printf("MultiViewport feature is enabled -- skipping disabled-state checks.\n");
7453
7454 // Check is that viewportcount and scissorcount match
7455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7456 vp_state_ci.scissorCount = 1;
7457 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7458 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7459 m_errorMonitor->VerifyFound();
7460
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007461 // Check case where multiViewport is enabled and viewport count is greater than max
7462 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7463 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7465 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7466 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7467 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7468 m_errorMonitor->VerifyFound();
7469 }
7470 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007471
Chia-I Wuf7458c52015-10-26 21:10:41 +08007472 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7473 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7474 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7475 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007476}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007477
7478// 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
7479// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007480TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007481 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007482
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007483 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7484
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007486
Tobin Ehlise68360f2015-10-01 11:15:13 -06007487 ASSERT_NO_FATAL_FAILURE(InitState());
7488 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007489
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007490 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007491 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7492 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007493
7494 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007495 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7496 ds_pool_ci.maxSets = 1;
7497 ds_pool_ci.poolSizeCount = 1;
7498 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007499
7500 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007501 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007502 ASSERT_VK_SUCCESS(err);
7503
7504 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007505 dsl_binding.binding = 0;
7506 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7507 dsl_binding.descriptorCount = 1;
7508 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007509
7510 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007511 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7512 ds_layout_ci.bindingCount = 1;
7513 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007514
7515 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007516 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007517 ASSERT_VK_SUCCESS(err);
7518
7519 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007520 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007521 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007522 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007523 alloc_info.descriptorPool = ds_pool;
7524 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007525 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007526 ASSERT_VK_SUCCESS(err);
7527
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007528 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7529 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7530 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7531
7532 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7533 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7534 vi_ci.pNext = nullptr;
7535 vi_ci.vertexBindingDescriptionCount = 0;
7536 vi_ci.pVertexBindingDescriptions = nullptr;
7537 vi_ci.vertexAttributeDescriptionCount = 0;
7538 vi_ci.pVertexAttributeDescriptions = nullptr;
7539
7540 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7541 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7542 pipe_ms_state_ci.pNext = NULL;
7543 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7544 pipe_ms_state_ci.sampleShadingEnable = 0;
7545 pipe_ms_state_ci.minSampleShading = 1.0;
7546 pipe_ms_state_ci.pSampleMask = NULL;
7547
Tobin Ehlise68360f2015-10-01 11:15:13 -06007548 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007549 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7550 pipeline_layout_ci.setLayoutCount = 1;
7551 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007552
7553 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007554 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007555 ASSERT_VK_SUCCESS(err);
7556
7557 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7558 // Set scissor as dynamic to avoid second error
7559 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007560 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7561 dyn_state_ci.dynamicStateCount = 1;
7562 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007563
Cody Northropeb3a6c12015-10-05 14:44:45 -06007564 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007565 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007566
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007567 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007568 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7569 // 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 +08007570 shaderStages[0] = vs.GetStageCreateInfo();
7571 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007572
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007573 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7574 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7575 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7576 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7577 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7578 rs_state_ci.depthClampEnable = VK_FALSE;
7579 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7580 rs_state_ci.depthBiasEnable = VK_FALSE;
7581
Tobin Ehlise68360f2015-10-01 11:15:13 -06007582 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007583 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7584 gp_ci.stageCount = 2;
7585 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007586 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007587 // Not setting VP state w/o dynamic vp state should cause validation error
7588 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007589 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007590 gp_ci.pVertexInputState = &vi_ci;
7591 gp_ci.pInputAssemblyState = &ia_ci;
7592 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007593 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7594 gp_ci.layout = pipeline_layout;
7595 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007596
7597 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007598 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007599
7600 VkPipeline pipeline;
7601 VkPipelineCache pipelineCache;
7602
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007603 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007604 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007605 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007606
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007607 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007608
Chia-I Wuf7458c52015-10-26 21:10:41 +08007609 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7610 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7611 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7612 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007613}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007614
7615// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7616// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007617TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7618 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007619
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007620 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007621
Tobin Ehlise68360f2015-10-01 11:15:13 -06007622 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007623
7624 if (!m_device->phy().features().multiViewport) {
7625 printf("Device does not support multiple viewports/scissors; skipped.\n");
7626 return;
7627 }
7628
Tobin Ehlise68360f2015-10-01 11:15:13 -06007629 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007630
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007631 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007632 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7633 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007634
7635 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007636 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7637 ds_pool_ci.maxSets = 1;
7638 ds_pool_ci.poolSizeCount = 1;
7639 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007640
7641 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007642 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007643 ASSERT_VK_SUCCESS(err);
7644
7645 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007646 dsl_binding.binding = 0;
7647 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7648 dsl_binding.descriptorCount = 1;
7649 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007650
7651 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007652 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7653 ds_layout_ci.bindingCount = 1;
7654 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007655
7656 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007657 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007658 ASSERT_VK_SUCCESS(err);
7659
7660 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007661 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007662 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007663 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007664 alloc_info.descriptorPool = ds_pool;
7665 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007666 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007667 ASSERT_VK_SUCCESS(err);
7668
7669 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007670 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7671 pipeline_layout_ci.setLayoutCount = 1;
7672 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007673
7674 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007675 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007676 ASSERT_VK_SUCCESS(err);
7677
7678 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007679 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7680 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007681 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007682 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007683 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06007684
7685 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7686 // Set scissor as dynamic to avoid that error
7687 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007688 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7689 dyn_state_ci.dynamicStateCount = 1;
7690 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007692 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7693 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7694 pipe_ms_state_ci.pNext = NULL;
7695 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7696 pipe_ms_state_ci.sampleShadingEnable = 0;
7697 pipe_ms_state_ci.minSampleShading = 1.0;
7698 pipe_ms_state_ci.pSampleMask = NULL;
7699
Cody Northropeb3a6c12015-10-05 14:44:45 -06007700 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007701 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007702
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007703 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007704 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7705 // 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 +08007706 shaderStages[0] = vs.GetStageCreateInfo();
7707 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007708
Cody Northropf6622dc2015-10-06 10:33:21 -06007709 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7710 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7711 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007712 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007713 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007714 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06007715 vi_ci.pVertexAttributeDescriptions = nullptr;
7716
7717 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7718 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7719 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7720
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007721 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007722 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007723 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06007724 rs_ci.pNext = nullptr;
7725
Mark Youngc89c6312016-03-31 16:03:20 -06007726 VkPipelineColorBlendAttachmentState att = {};
7727 att.blendEnable = VK_FALSE;
7728 att.colorWriteMask = 0xf;
7729
Cody Northropf6622dc2015-10-06 10:33:21 -06007730 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7731 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7732 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007733 cb_ci.attachmentCount = 1;
7734 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06007735
Tobin Ehlise68360f2015-10-01 11:15:13 -06007736 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007737 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7738 gp_ci.stageCount = 2;
7739 gp_ci.pStages = shaderStages;
7740 gp_ci.pVertexInputState = &vi_ci;
7741 gp_ci.pInputAssemblyState = &ia_ci;
7742 gp_ci.pViewportState = &vp_state_ci;
7743 gp_ci.pRasterizationState = &rs_ci;
7744 gp_ci.pColorBlendState = &cb_ci;
7745 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007746 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007747 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7748 gp_ci.layout = pipeline_layout;
7749 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007750
7751 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007752 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007753
7754 VkPipeline pipeline;
7755 VkPipelineCache pipelineCache;
7756
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007757 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007758 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007759 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007760
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007761 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007762
Tobin Ehlisd332f282015-10-02 11:00:56 -06007763 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07007764 // First need to successfully create the PSO from above by setting
7765 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06007766 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 -07007767
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007768 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07007769 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007770 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007771 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007772 m_commandBuffer->BeginCommandBuffer();
7773 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007774 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007775 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07007776 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007777 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07007778 Draw(1, 0, 0, 0);
7779
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007780 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007781
7782 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7783 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7784 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7785 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007786 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007787}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007788
7789// 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 -07007790// viewportCount
7791TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
7792 VkResult err;
7793
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07007795
7796 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007797
7798 if (!m_device->phy().features().multiViewport) {
7799 printf("Device does not support multiple viewports/scissors; skipped.\n");
7800 return;
7801 }
7802
Karl Schultz6addd812016-02-02 17:17:23 -07007803 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7804
7805 VkDescriptorPoolSize ds_type_count = {};
7806 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7807 ds_type_count.descriptorCount = 1;
7808
7809 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7810 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7811 ds_pool_ci.maxSets = 1;
7812 ds_pool_ci.poolSizeCount = 1;
7813 ds_pool_ci.pPoolSizes = &ds_type_count;
7814
7815 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007816 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07007817 ASSERT_VK_SUCCESS(err);
7818
7819 VkDescriptorSetLayoutBinding dsl_binding = {};
7820 dsl_binding.binding = 0;
7821 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7822 dsl_binding.descriptorCount = 1;
7823 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7824
7825 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7826 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7827 ds_layout_ci.bindingCount = 1;
7828 ds_layout_ci.pBindings = &dsl_binding;
7829
7830 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007831 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007832 ASSERT_VK_SUCCESS(err);
7833
7834 VkDescriptorSet descriptorSet;
7835 VkDescriptorSetAllocateInfo alloc_info = {};
7836 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
7837 alloc_info.descriptorSetCount = 1;
7838 alloc_info.descriptorPool = ds_pool;
7839 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007840 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07007841 ASSERT_VK_SUCCESS(err);
7842
7843 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
7844 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7845 pipeline_layout_ci.setLayoutCount = 1;
7846 pipeline_layout_ci.pSetLayouts = &ds_layout;
7847
7848 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007849 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07007850 ASSERT_VK_SUCCESS(err);
7851
7852 VkPipelineViewportStateCreateInfo vp_state_ci = {};
7853 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7854 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007855 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007856 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007857 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07007858
7859 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
7860 // Set scissor as dynamic to avoid that error
7861 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
7862 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7863 dyn_state_ci.dynamicStateCount = 1;
7864 dyn_state_ci.pDynamicStates = &vp_state;
7865
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007866 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7867 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7868 pipe_ms_state_ci.pNext = NULL;
7869 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7870 pipe_ms_state_ci.sampleShadingEnable = 0;
7871 pipe_ms_state_ci.minSampleShading = 1.0;
7872 pipe_ms_state_ci.pSampleMask = NULL;
7873
Karl Schultz6addd812016-02-02 17:17:23 -07007874 VkPipelineShaderStageCreateInfo shaderStages[2];
7875 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7876
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007877 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007878 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7879 // 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 -07007880 shaderStages[0] = vs.GetStageCreateInfo();
7881 shaderStages[1] = fs.GetStageCreateInfo();
7882
7883 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7884 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7885 vi_ci.pNext = nullptr;
7886 vi_ci.vertexBindingDescriptionCount = 0;
7887 vi_ci.pVertexBindingDescriptions = nullptr;
7888 vi_ci.vertexAttributeDescriptionCount = 0;
7889 vi_ci.pVertexAttributeDescriptions = nullptr;
7890
7891 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7892 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7893 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7894
7895 VkPipelineRasterizationStateCreateInfo rs_ci = {};
7896 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007897 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07007898 rs_ci.pNext = nullptr;
7899
Mark Youngc89c6312016-03-31 16:03:20 -06007900 VkPipelineColorBlendAttachmentState att = {};
7901 att.blendEnable = VK_FALSE;
7902 att.colorWriteMask = 0xf;
7903
Karl Schultz6addd812016-02-02 17:17:23 -07007904 VkPipelineColorBlendStateCreateInfo cb_ci = {};
7905 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
7906 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06007907 cb_ci.attachmentCount = 1;
7908 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07007909
7910 VkGraphicsPipelineCreateInfo gp_ci = {};
7911 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7912 gp_ci.stageCount = 2;
7913 gp_ci.pStages = shaderStages;
7914 gp_ci.pVertexInputState = &vi_ci;
7915 gp_ci.pInputAssemblyState = &ia_ci;
7916 gp_ci.pViewportState = &vp_state_ci;
7917 gp_ci.pRasterizationState = &rs_ci;
7918 gp_ci.pColorBlendState = &cb_ci;
7919 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007920 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007921 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7922 gp_ci.layout = pipeline_layout;
7923 gp_ci.renderPass = renderPass();
7924
7925 VkPipelineCacheCreateInfo pc_ci = {};
7926 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7927
7928 VkPipeline pipeline;
7929 VkPipelineCache pipelineCache;
7930
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007931 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07007932 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007933 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07007934
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007935 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07007936
7937 // Now hit second fail case where we set scissor w/ different count than PSO
7938 // First need to successfully create the PSO from above by setting
7939 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7941 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007942
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007943 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06007944 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007945 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007946 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07007947 m_commandBuffer->BeginCommandBuffer();
7948 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007949 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07007950 VkViewport viewports[1] = {};
7951 viewports[0].width = 8;
7952 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06007953 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007954 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06007955 Draw(1, 0, 0, 0);
7956
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007957 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007958
Chia-I Wuf7458c52015-10-26 21:10:41 +08007959 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7960 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7961 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7962 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06007963 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007964}
7965
Mark Young7394fdd2016-03-31 14:56:43 -06007966TEST_F(VkLayerTest, PSOLineWidthInvalid) {
7967 VkResult err;
7968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06007970
7971 ASSERT_NO_FATAL_FAILURE(InitState());
7972 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7973
7974 VkDescriptorPoolSize ds_type_count = {};
7975 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7976 ds_type_count.descriptorCount = 1;
7977
7978 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7979 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7980 ds_pool_ci.maxSets = 1;
7981 ds_pool_ci.poolSizeCount = 1;
7982 ds_pool_ci.pPoolSizes = &ds_type_count;
7983
7984 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007985 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06007986 ASSERT_VK_SUCCESS(err);
7987
7988 VkDescriptorSetLayoutBinding dsl_binding = {};
7989 dsl_binding.binding = 0;
7990 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7991 dsl_binding.descriptorCount = 1;
7992 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7993
7994 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
7995 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7996 ds_layout_ci.bindingCount = 1;
7997 ds_layout_ci.pBindings = &dsl_binding;
7998
7999 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008000 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008001 ASSERT_VK_SUCCESS(err);
8002
8003 VkDescriptorSet descriptorSet;
8004 VkDescriptorSetAllocateInfo alloc_info = {};
8005 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8006 alloc_info.descriptorSetCount = 1;
8007 alloc_info.descriptorPool = ds_pool;
8008 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008009 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008010 ASSERT_VK_SUCCESS(err);
8011
8012 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8013 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8014 pipeline_layout_ci.setLayoutCount = 1;
8015 pipeline_layout_ci.pSetLayouts = &ds_layout;
8016
8017 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008018 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008019 ASSERT_VK_SUCCESS(err);
8020
8021 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8022 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8023 vp_state_ci.scissorCount = 1;
8024 vp_state_ci.pScissors = NULL;
8025 vp_state_ci.viewportCount = 1;
8026 vp_state_ci.pViewports = NULL;
8027
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008028 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008029 // Set scissor as dynamic to avoid that error
8030 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8031 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8032 dyn_state_ci.dynamicStateCount = 2;
8033 dyn_state_ci.pDynamicStates = dynamic_states;
8034
8035 VkPipelineShaderStageCreateInfo shaderStages[2];
8036 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8037
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008038 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8039 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008040 this); // TODO - We shouldn't need a fragment shader
8041 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008042 shaderStages[0] = vs.GetStageCreateInfo();
8043 shaderStages[1] = fs.GetStageCreateInfo();
8044
8045 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8046 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8047 vi_ci.pNext = nullptr;
8048 vi_ci.vertexBindingDescriptionCount = 0;
8049 vi_ci.pVertexBindingDescriptions = nullptr;
8050 vi_ci.vertexAttributeDescriptionCount = 0;
8051 vi_ci.pVertexAttributeDescriptions = nullptr;
8052
8053 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8054 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8055 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8056
8057 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8058 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8059 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008060 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008061
Mark Young47107952016-05-02 15:59:55 -06008062 // Check too low (line width of -1.0f).
8063 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008064
8065 VkPipelineColorBlendAttachmentState att = {};
8066 att.blendEnable = VK_FALSE;
8067 att.colorWriteMask = 0xf;
8068
8069 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8070 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8071 cb_ci.pNext = nullptr;
8072 cb_ci.attachmentCount = 1;
8073 cb_ci.pAttachments = &att;
8074
8075 VkGraphicsPipelineCreateInfo gp_ci = {};
8076 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8077 gp_ci.stageCount = 2;
8078 gp_ci.pStages = shaderStages;
8079 gp_ci.pVertexInputState = &vi_ci;
8080 gp_ci.pInputAssemblyState = &ia_ci;
8081 gp_ci.pViewportState = &vp_state_ci;
8082 gp_ci.pRasterizationState = &rs_ci;
8083 gp_ci.pColorBlendState = &cb_ci;
8084 gp_ci.pDynamicState = &dyn_state_ci;
8085 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8086 gp_ci.layout = pipeline_layout;
8087 gp_ci.renderPass = renderPass();
8088
8089 VkPipelineCacheCreateInfo pc_ci = {};
8090 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8091
8092 VkPipeline pipeline;
8093 VkPipelineCache pipelineCache;
8094
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008095 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008096 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008097 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008098
8099 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008100 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008101
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008103
8104 // Check too high (line width of 65536.0f).
8105 rs_ci.lineWidth = 65536.0f;
8106
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008107 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008108 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008109 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008110
8111 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008112 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008113
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008115
8116 dyn_state_ci.dynamicStateCount = 3;
8117
8118 rs_ci.lineWidth = 1.0f;
8119
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008120 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008121 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008122 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008123 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008124 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008125
8126 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008127 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008128 m_errorMonitor->VerifyFound();
8129
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008131
8132 // Check too high with dynamic setting.
8133 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8134 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008135 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008136
8137 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8138 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8139 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8140 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008141 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008142}
8143
Karl Schultz6addd812016-02-02 17:17:23 -07008144TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008145 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008146 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008147 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008148
8149 ASSERT_NO_FATAL_FAILURE(InitState());
8150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008151
Tony Barbour552f6c02016-12-21 14:34:07 -07008152 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008153 // Don't care about RenderPass handle b/c error should be flagged before
8154 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008155 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008156
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008157 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008158}
8159
Karl Schultz6addd812016-02-02 17:17:23 -07008160TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008161 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8163 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008164
8165 ASSERT_NO_FATAL_FAILURE(InitState());
8166 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008167
Tony Barbour552f6c02016-12-21 14:34:07 -07008168 m_commandBuffer->BeginCommandBuffer();
8169 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008170 // Just create a dummy Renderpass that's non-NULL so we can get to the
8171 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008172 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008173
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008174 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008175}
8176
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008177TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008178 TEST_DESCRIPTION(
8179 "Begin a renderPass where clearValueCount is less than"
8180 "the number of renderPass attachments that use loadOp"
8181 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008182
8183 ASSERT_NO_FATAL_FAILURE(InitState());
8184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8185
8186 // Create a renderPass with a single attachment that uses loadOp CLEAR
8187 VkAttachmentReference attach = {};
8188 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8189 VkSubpassDescription subpass = {};
8190 subpass.inputAttachmentCount = 1;
8191 subpass.pInputAttachments = &attach;
8192 VkRenderPassCreateInfo rpci = {};
8193 rpci.subpassCount = 1;
8194 rpci.pSubpasses = &subpass;
8195 rpci.attachmentCount = 1;
8196 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008197 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008198 // Set loadOp to CLEAR
8199 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8200 rpci.pAttachments = &attach_desc;
8201 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8202 VkRenderPass rp;
8203 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8204
8205 VkCommandBufferInheritanceInfo hinfo = {};
8206 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8207 hinfo.renderPass = VK_NULL_HANDLE;
8208 hinfo.subpass = 0;
8209 hinfo.framebuffer = VK_NULL_HANDLE;
8210 hinfo.occlusionQueryEnable = VK_FALSE;
8211 hinfo.queryFlags = 0;
8212 hinfo.pipelineStatistics = 0;
8213 VkCommandBufferBeginInfo info = {};
8214 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8215 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8216 info.pInheritanceInfo = &hinfo;
8217
8218 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8219 VkRenderPassBeginInfo rp_begin = {};
8220 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8221 rp_begin.pNext = NULL;
8222 rp_begin.renderPass = renderPass();
8223 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008224 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008225
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008227
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008228 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008229
8230 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008231
8232 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008233}
8234
Slawomir Cygan0808f392016-11-28 17:53:23 +01008235TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008236 TEST_DESCRIPTION(
8237 "Begin a renderPass where clearValueCount is greater than"
8238 "the number of renderPass attachments that use loadOp"
8239 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008240
8241 ASSERT_NO_FATAL_FAILURE(InitState());
8242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8243
8244 // Create a renderPass with a single attachment that uses loadOp CLEAR
8245 VkAttachmentReference attach = {};
8246 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8247 VkSubpassDescription subpass = {};
8248 subpass.inputAttachmentCount = 1;
8249 subpass.pInputAttachments = &attach;
8250 VkRenderPassCreateInfo rpci = {};
8251 rpci.subpassCount = 1;
8252 rpci.pSubpasses = &subpass;
8253 rpci.attachmentCount = 1;
8254 VkAttachmentDescription attach_desc = {};
8255 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8256 // Set loadOp to CLEAR
8257 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8258 rpci.pAttachments = &attach_desc;
8259 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8260 VkRenderPass rp;
8261 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8262
8263 VkCommandBufferBeginInfo info = {};
8264 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8265 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8266
8267 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8268 VkRenderPassBeginInfo rp_begin = {};
8269 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8270 rp_begin.pNext = NULL;
8271 rp_begin.renderPass = renderPass();
8272 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008273 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008274
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8276 " has a clearValueCount of"
8277 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008278
8279 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8280
8281 m_errorMonitor->VerifyFound();
8282
8283 vkDestroyRenderPass(m_device->device(), rp, NULL);
8284}
8285
Cody Northrop3bb4d962016-05-09 16:15:57 -06008286TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008287 TEST_DESCRIPTION("End a command buffer with an active render pass");
8288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8290 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008291
8292 ASSERT_NO_FATAL_FAILURE(InitState());
8293 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8294
Tony Barbour552f6c02016-12-21 14:34:07 -07008295 m_commandBuffer->BeginCommandBuffer();
8296 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8297 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008298
8299 m_errorMonitor->VerifyFound();
8300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008301 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8302 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008303}
8304
Karl Schultz6addd812016-02-02 17:17:23 -07008305TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008306 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8308 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008309
8310 ASSERT_NO_FATAL_FAILURE(InitState());
8311 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008312
Tony Barbour552f6c02016-12-21 14:34:07 -07008313 m_commandBuffer->BeginCommandBuffer();
8314 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008315
8316 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008317 vk_testing::Buffer dstBuffer;
8318 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008319
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008320 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008321
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008322 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008323}
8324
Karl Schultz6addd812016-02-02 17:17:23 -07008325TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008326 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8328 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008329
8330 ASSERT_NO_FATAL_FAILURE(InitState());
8331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008332
Tony Barbour552f6c02016-12-21 14:34:07 -07008333 m_commandBuffer->BeginCommandBuffer();
8334 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008335
8336 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008337 vk_testing::Buffer dstBuffer;
8338 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008339
Karl Schultz6addd812016-02-02 17:17:23 -07008340 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008341 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8342 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8343 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008344
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008345 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008346}
8347
Karl Schultz6addd812016-02-02 17:17:23 -07008348TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008349 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8351 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008352
8353 ASSERT_NO_FATAL_FAILURE(InitState());
8354 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008355
Tony Barbour552f6c02016-12-21 14:34:07 -07008356 m_commandBuffer->BeginCommandBuffer();
8357 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008358
Michael Lentine0a369f62016-02-03 16:51:46 -06008359 VkClearColorValue clear_color;
8360 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008361 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8362 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8363 const int32_t tex_width = 32;
8364 const int32_t tex_height = 32;
8365 VkImageCreateInfo image_create_info = {};
8366 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8367 image_create_info.pNext = NULL;
8368 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8369 image_create_info.format = tex_format;
8370 image_create_info.extent.width = tex_width;
8371 image_create_info.extent.height = tex_height;
8372 image_create_info.extent.depth = 1;
8373 image_create_info.mipLevels = 1;
8374 image_create_info.arrayLayers = 1;
8375 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8376 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8377 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008378
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008379 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008380 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008381
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008382 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008383
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008384 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008385
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008386 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008387}
8388
Karl Schultz6addd812016-02-02 17:17:23 -07008389TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008390 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8392 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008393
8394 ASSERT_NO_FATAL_FAILURE(InitState());
8395 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008396
Tony Barbour552f6c02016-12-21 14:34:07 -07008397 m_commandBuffer->BeginCommandBuffer();
8398 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008399
8400 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008401 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008402 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8403 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8404 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8405 image_create_info.extent.width = 64;
8406 image_create_info.extent.height = 64;
8407 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8408 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008409
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008410 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008411 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008412
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008413 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008414
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008415 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8416 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008417
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008418 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008419}
8420
Karl Schultz6addd812016-02-02 17:17:23 -07008421TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008422 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008423 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008424
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008425 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8426 "vkCmdClearAttachments(): This call "
8427 "must be issued inside an active "
8428 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008429
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008430 ASSERT_NO_FATAL_FAILURE(InitState());
8431 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008432
8433 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008434 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008435 ASSERT_VK_SUCCESS(err);
8436
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008437 VkClearAttachment color_attachment;
8438 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8439 color_attachment.clearValue.color.float32[0] = 0;
8440 color_attachment.clearValue.color.float32[1] = 0;
8441 color_attachment.clearValue.color.float32[2] = 0;
8442 color_attachment.clearValue.color.float32[3] = 0;
8443 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008444 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008445 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008446
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008447 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008448}
8449
Chris Forbes3b97e932016-09-07 11:29:24 +12008450TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008451 TEST_DESCRIPTION(
8452 "Test that an error is produced when CmdNextSubpass is "
8453 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008454
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008455 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8456 "vkCmdNextSubpass(): Attempted to advance "
8457 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008458
8459 ASSERT_NO_FATAL_FAILURE(InitState());
8460 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8461
Tony Barbour552f6c02016-12-21 14:34:07 -07008462 m_commandBuffer->BeginCommandBuffer();
8463 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008464
8465 // error here.
8466 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8467 m_errorMonitor->VerifyFound();
8468
Tony Barbour552f6c02016-12-21 14:34:07 -07008469 m_commandBuffer->EndRenderPass();
8470 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008471}
8472
Chris Forbes6d624702016-09-07 13:57:05 +12008473TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008474 TEST_DESCRIPTION(
8475 "Test that an error is produced when CmdEndRenderPass is "
8476 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008477
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8479 "vkCmdEndRenderPass(): Called before reaching "
8480 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008481
8482 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008483 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8484 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008485
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008486 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008487
8488 VkRenderPass rp;
8489 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8490 ASSERT_VK_SUCCESS(err);
8491
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008492 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008493
8494 VkFramebuffer fb;
8495 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8496 ASSERT_VK_SUCCESS(err);
8497
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008498 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008499
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008500 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 +12008501
8502 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8503
8504 // Error here.
8505 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8506 m_errorMonitor->VerifyFound();
8507
8508 // Clean up.
8509 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8510 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8511}
8512
Karl Schultz9e66a292016-04-21 15:57:51 -06008513TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8514 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8516 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008517
8518 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008519 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008520
8521 VkBufferMemoryBarrier buf_barrier = {};
8522 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8523 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8524 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8525 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8526 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8527 buf_barrier.buffer = VK_NULL_HANDLE;
8528 buf_barrier.offset = 0;
8529 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008530 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8531 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008532
8533 m_errorMonitor->VerifyFound();
8534}
8535
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008536TEST_F(VkLayerTest, InvalidBarriers) {
8537 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8538
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008540
8541 ASSERT_NO_FATAL_FAILURE(InitState());
8542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8543
8544 VkMemoryBarrier mem_barrier = {};
8545 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8546 mem_barrier.pNext = NULL;
8547 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8548 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008549 m_commandBuffer->BeginCommandBuffer();
8550 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008551 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008552 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008553 &mem_barrier, 0, nullptr, 0, nullptr);
8554 m_errorMonitor->VerifyFound();
8555
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008557 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008558 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 -06008559 ASSERT_TRUE(image.initialized());
8560 VkImageMemoryBarrier img_barrier = {};
8561 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8562 img_barrier.pNext = NULL;
8563 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8564 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8565 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8566 // New layout can't be UNDEFINED
8567 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8568 img_barrier.image = image.handle();
8569 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8570 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8571 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8572 img_barrier.subresourceRange.baseArrayLayer = 0;
8573 img_barrier.subresourceRange.baseMipLevel = 0;
8574 img_barrier.subresourceRange.layerCount = 1;
8575 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008576 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8577 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008578 m_errorMonitor->VerifyFound();
8579 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8580
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8582 "Subresource must have the sum of the "
8583 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008584 // baseArrayLayer + layerCount must be <= image's arrayLayers
8585 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008586 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8587 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008588 m_errorMonitor->VerifyFound();
8589 img_barrier.subresourceRange.baseArrayLayer = 0;
8590
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008592 // baseMipLevel + levelCount must be <= image's mipLevels
8593 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008594 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8595 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008596 m_errorMonitor->VerifyFound();
8597 img_barrier.subresourceRange.baseMipLevel = 0;
8598
Mike Weiblen7053aa32017-01-25 15:21:10 -07008599 // levelCount must be non-zero.
8600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8601 img_barrier.subresourceRange.levelCount = 0;
8602 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8603 nullptr, 0, nullptr, 1, &img_barrier);
8604 m_errorMonitor->VerifyFound();
8605 img_barrier.subresourceRange.levelCount = 1;
8606
8607 // layerCount must be non-zero.
8608 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8609 img_barrier.subresourceRange.layerCount = 0;
8610 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8611 nullptr, 0, nullptr, 1, &img_barrier);
8612 m_errorMonitor->VerifyFound();
8613 img_barrier.subresourceRange.layerCount = 1;
8614
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008615 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 -06008616 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008617 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8618 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008619 VkBufferMemoryBarrier buf_barrier = {};
8620 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8621 buf_barrier.pNext = NULL;
8622 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8623 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8624 buf_barrier.buffer = buffer.handle();
8625 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8626 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8627 buf_barrier.offset = 0;
8628 buf_barrier.size = VK_WHOLE_SIZE;
8629 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008630 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8631 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008632 m_errorMonitor->VerifyFound();
8633 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8634
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008636 buf_barrier.offset = 257;
8637 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008638 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8639 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008640 m_errorMonitor->VerifyFound();
8641 buf_barrier.offset = 0;
8642
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008644 buf_barrier.size = 257;
8645 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008646 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8647 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008648 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008649
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008650 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008651 m_errorMonitor->SetDesiredFailureMsg(
8652 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008653 "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 -06008654 VkDepthStencilObj ds_image(m_device);
8655 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8656 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008657 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8658 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008659 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008660
8661 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07008662 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008663 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8664 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008665 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07008666
8667 // Having anything other than DEPTH or STENCIL is an error
8668 m_errorMonitor->SetDesiredFailureMsg(
8669 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8670 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8671 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
8672 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8673 nullptr, 0, nullptr, 1, &img_barrier);
8674 m_errorMonitor->VerifyFound();
8675
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008676 // Now test depth-only
8677 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008678 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8679 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008680 VkDepthStencilObj d_image(m_device);
8681 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8682 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008683 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008684 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008685 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008686
8687 // DEPTH bit must be set
8688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8689 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07008690 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07008691 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8692 0, nullptr, 0, nullptr, 1, &img_barrier);
8693 m_errorMonitor->VerifyFound();
8694
8695 // No bits other than DEPTH may be set
8696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8697 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8698 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008699 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8700 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008701 m_errorMonitor->VerifyFound();
8702 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008703
8704 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008705 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8706 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8708 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008709 VkDepthStencilObj s_image(m_device);
8710 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8711 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008712 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008713 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008714 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008715 // Use of COLOR aspect on depth image is error
8716 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008717 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8718 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008719 m_errorMonitor->VerifyFound();
8720 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008721
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008722 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008723 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008724 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 -06008725 ASSERT_TRUE(c_image.initialized());
8726 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8727 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8728 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008729
8730 // COLOR bit must be set
8731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8732 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07008733 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07008734 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8735 nullptr, 0, nullptr, 1, &img_barrier);
8736 m_errorMonitor->VerifyFound();
8737
8738 // No bits other than COLOR may be set
8739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8740 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
8741 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008742 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8743 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008744 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008745
8746 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8747
8748 // Create command pool with incompatible queueflags
8749 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8750 uint32_t queue_family_index = UINT32_MAX;
8751 for (uint32_t i = 0; i < queue_props.size(); i++) {
8752 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8753 queue_family_index = i;
8754 break;
8755 }
8756 }
8757 if (queue_family_index == UINT32_MAX) {
8758 printf("No non-compute queue found; skipped.\n");
8759 return;
8760 }
8761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8762
8763 VkCommandPool command_pool;
8764 VkCommandPoolCreateInfo pool_create_info{};
8765 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8766 pool_create_info.queueFamilyIndex = queue_family_index;
8767 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8768 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8769
8770 // Allocate a command buffer
8771 VkCommandBuffer bad_command_buffer;
8772 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8773 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8774 command_buffer_allocate_info.commandPool = command_pool;
8775 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8776 command_buffer_allocate_info.commandBufferCount = 1;
8777 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8778
8779 VkCommandBufferBeginInfo cbbi = {};
8780 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8781 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8782 buf_barrier.offset = 0;
8783 buf_barrier.size = VK_WHOLE_SIZE;
8784 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8785 &buf_barrier, 0, nullptr);
8786 m_errorMonitor->VerifyFound();
8787
8788 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8789 vkEndCommandBuffer(bad_command_buffer);
8790 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8791 printf("The non-compute queue does not support graphics; skipped.\n");
8792 return;
8793 }
8794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8795 VkEvent event;
8796 VkEventCreateInfo event_create_info{};
8797 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8798 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8799 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8800 nullptr, 0, nullptr);
8801 m_errorMonitor->VerifyFound();
8802
8803 vkEndCommandBuffer(bad_command_buffer);
8804 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008805}
8806
Tony Barbour18ba25c2016-09-29 13:42:40 -06008807TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8808 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8809
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06008811 ASSERT_NO_FATAL_FAILURE(InitState());
8812 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008813 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 -06008814 ASSERT_TRUE(image.initialized());
8815
8816 VkImageMemoryBarrier barrier = {};
8817 VkImageSubresourceRange range;
8818 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8819 barrier.srcAccessMask = 0;
8820 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8821 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8822 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8823 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8824 barrier.image = image.handle();
8825 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8826 range.baseMipLevel = 0;
8827 range.levelCount = 1;
8828 range.baseArrayLayer = 0;
8829 range.layerCount = 1;
8830 barrier.subresourceRange = range;
8831 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8832 cmdbuf.BeginCommandBuffer();
8833 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8834 &barrier);
8835 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8836 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8837 barrier.srcAccessMask = 0;
8838 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8839 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8840 &barrier);
8841
8842 m_errorMonitor->VerifyFound();
8843}
8844
Karl Schultz6addd812016-02-02 17:17:23 -07008845TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008846 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008847 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008850
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008851 ASSERT_NO_FATAL_FAILURE(InitState());
8852 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008853 uint32_t qfi = 0;
8854 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008855 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8856 buffCI.size = 1024;
8857 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8858 buffCI.queueFamilyIndexCount = 1;
8859 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008860
8861 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008862 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008863 ASSERT_VK_SUCCESS(err);
8864
Tony Barbour552f6c02016-12-21 14:34:07 -07008865 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008866 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008867 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8868 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008869 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008870 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008871
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008872 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008873
Chia-I Wuf7458c52015-10-26 21:10:41 +08008874 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008875}
8876
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008877TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8878 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8880 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8881 "of the indices specified when the device was created, via the "
8882 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008883
8884 ASSERT_NO_FATAL_FAILURE(InitState());
8885 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8886 VkBufferCreateInfo buffCI = {};
8887 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8888 buffCI.size = 1024;
8889 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8890 buffCI.queueFamilyIndexCount = 1;
8891 // Introduce failure by specifying invalid queue_family_index
8892 uint32_t qfi = 777;
8893 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008894 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008895
8896 VkBuffer ib;
8897 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8898
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008899 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008900 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008901}
8902
Karl Schultz6addd812016-02-02 17:17:23 -07008903TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008904 TEST_DESCRIPTION(
8905 "Attempt vkCmdExecuteCommands with a primary command buffer"
8906 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008907
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008908 ASSERT_NO_FATAL_FAILURE(InitState());
8909 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008910
Chris Forbesf29a84f2016-10-06 18:39:28 +13008911 // An empty primary command buffer
8912 VkCommandBufferObj cb(m_device, m_commandPool);
8913 cb.BeginCommandBuffer();
8914 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008915
Chris Forbesf29a84f2016-10-06 18:39:28 +13008916 m_commandBuffer->BeginCommandBuffer();
8917 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8918 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008919
Chris Forbesf29a84f2016-10-06 18:39:28 +13008920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8921 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008922 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008923}
8924
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008925TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008926 TEST_DESCRIPTION(
8927 "Attempt to update descriptor sets for images and buffers "
8928 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008929 VkResult err;
8930
8931 ASSERT_NO_FATAL_FAILURE(InitState());
8932 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8933 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8934 ds_type_count[i].type = VkDescriptorType(i);
8935 ds_type_count[i].descriptorCount = 1;
8936 }
8937 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8938 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8939 ds_pool_ci.pNext = NULL;
8940 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8941 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8942 ds_pool_ci.pPoolSizes = ds_type_count;
8943
8944 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008945 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008946 ASSERT_VK_SUCCESS(err);
8947
8948 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008949 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008950 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8951 dsl_binding[i].binding = 0;
8952 dsl_binding[i].descriptorType = VkDescriptorType(i);
8953 dsl_binding[i].descriptorCount = 1;
8954 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8955 dsl_binding[i].pImmutableSamplers = NULL;
8956 }
8957
8958 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8959 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8960 ds_layout_ci.pNext = NULL;
8961 ds_layout_ci.bindingCount = 1;
8962 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8963 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8964 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008965 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008966 ASSERT_VK_SUCCESS(err);
8967 }
8968 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8969 VkDescriptorSetAllocateInfo alloc_info = {};
8970 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8971 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8972 alloc_info.descriptorPool = ds_pool;
8973 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008974 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008975 ASSERT_VK_SUCCESS(err);
8976
8977 // Create a buffer & bufferView to be used for invalid updates
8978 VkBufferCreateInfo buff_ci = {};
8979 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07008980 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008981 buff_ci.size = 256;
8982 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07008983 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008984 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8985 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07008986
8987 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
8988 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
8989 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
8990 ASSERT_VK_SUCCESS(err);
8991
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008992 VkMemoryRequirements mem_reqs;
8993 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8994 VkMemoryAllocateInfo mem_alloc_info = {};
8995 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8996 mem_alloc_info.pNext = NULL;
8997 mem_alloc_info.memoryTypeIndex = 0;
8998 mem_alloc_info.allocationSize = mem_reqs.size;
8999 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9000 if (!pass) {
9001 vkDestroyBuffer(m_device->device(), buffer, NULL);
9002 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9003 return;
9004 }
9005 VkDeviceMemory mem;
9006 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9007 ASSERT_VK_SUCCESS(err);
9008 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9009 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009010
9011 VkBufferViewCreateInfo buff_view_ci = {};
9012 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9013 buff_view_ci.buffer = buffer;
9014 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9015 buff_view_ci.range = VK_WHOLE_SIZE;
9016 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009017 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009018 ASSERT_VK_SUCCESS(err);
9019
Tony Barbour415497c2017-01-24 10:06:09 -07009020 // Now get resources / view for storage_texel_buffer
9021 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9022 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9023 if (!pass) {
9024 vkDestroyBuffer(m_device->device(), buffer, NULL);
9025 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9026 vkFreeMemory(m_device->device(), mem, NULL);
9027 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9028 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9029 return;
9030 }
9031 VkDeviceMemory storage_texel_buffer_mem;
9032 VkBufferView storage_texel_buffer_view;
9033 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9034 ASSERT_VK_SUCCESS(err);
9035 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9036 ASSERT_VK_SUCCESS(err);
9037 buff_view_ci.buffer = storage_texel_buffer;
9038 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9039 ASSERT_VK_SUCCESS(err);
9040
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009041 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009042 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009043 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009044 image_ci.format = VK_FORMAT_UNDEFINED;
9045 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9046 VkFormat format = static_cast<VkFormat>(f);
9047 VkFormatProperties fProps = m_device->format_properties(format);
9048 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9049 image_ci.format = format;
9050 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9051 break;
9052 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9053 image_ci.format = format;
9054 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9055 break;
9056 }
9057 }
9058 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9059 return;
9060 }
9061
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009062 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9063 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009064 image_ci.extent.width = 64;
9065 image_ci.extent.height = 64;
9066 image_ci.extent.depth = 1;
9067 image_ci.mipLevels = 1;
9068 image_ci.arrayLayers = 1;
9069 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009070 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009071 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009072 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9073 VkImage image;
9074 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9075 ASSERT_VK_SUCCESS(err);
9076 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009077 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009078
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009079 VkMemoryAllocateInfo mem_alloc = {};
9080 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9081 mem_alloc.pNext = NULL;
9082 mem_alloc.allocationSize = 0;
9083 mem_alloc.memoryTypeIndex = 0;
9084 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9085 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009086 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009087 ASSERT_TRUE(pass);
9088 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9089 ASSERT_VK_SUCCESS(err);
9090 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9091 ASSERT_VK_SUCCESS(err);
9092 // Now create view for image
9093 VkImageViewCreateInfo image_view_ci = {};
9094 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9095 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009096 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009097 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9098 image_view_ci.subresourceRange.layerCount = 1;
9099 image_view_ci.subresourceRange.baseArrayLayer = 0;
9100 image_view_ci.subresourceRange.levelCount = 1;
9101 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9102 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009103 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009104 ASSERT_VK_SUCCESS(err);
9105
9106 VkDescriptorBufferInfo buff_info = {};
9107 buff_info.buffer = buffer;
9108 VkDescriptorImageInfo img_info = {};
9109 img_info.imageView = image_view;
9110 VkWriteDescriptorSet descriptor_write = {};
9111 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9112 descriptor_write.dstBinding = 0;
9113 descriptor_write.descriptorCount = 1;
9114 descriptor_write.pTexelBufferView = &buff_view;
9115 descriptor_write.pBufferInfo = &buff_info;
9116 descriptor_write.pImageInfo = &img_info;
9117
9118 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009119 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009120 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9121 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9122 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9123 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9124 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9125 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9126 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9127 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9128 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9129 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9130 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009131 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009132 // Start loop at 1 as SAMPLER desc type has no usage bit error
9133 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009134 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9135 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9136 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9137 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009138 descriptor_write.descriptorType = VkDescriptorType(i);
9139 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009140 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009141
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009142 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009143
9144 m_errorMonitor->VerifyFound();
9145 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009146 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9147 descriptor_write.pTexelBufferView = &buff_view;
9148 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009149 }
Tony Barbour415497c2017-01-24 10:06:09 -07009150
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9152 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009153 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009154 vkDestroyImageView(m_device->device(), image_view, NULL);
9155 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009156 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009157 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009158 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009159 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009160 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009161 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9162}
9163
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009164TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009165 TEST_DESCRIPTION(
9166 "Attempt to update buffer descriptor set that has incorrect "
9167 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9168 "1. offset value greater than buffer size\n"
9169 "2. range value of 0\n"
9170 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009171 VkResult err;
9172
9173 ASSERT_NO_FATAL_FAILURE(InitState());
9174 VkDescriptorPoolSize ds_type_count = {};
9175 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9176 ds_type_count.descriptorCount = 1;
9177
9178 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9179 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9180 ds_pool_ci.pNext = NULL;
9181 ds_pool_ci.maxSets = 1;
9182 ds_pool_ci.poolSizeCount = 1;
9183 ds_pool_ci.pPoolSizes = &ds_type_count;
9184
9185 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009186 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009187 ASSERT_VK_SUCCESS(err);
9188
9189 // Create layout with single uniform buffer descriptor
9190 VkDescriptorSetLayoutBinding dsl_binding = {};
9191 dsl_binding.binding = 0;
9192 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9193 dsl_binding.descriptorCount = 1;
9194 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9195 dsl_binding.pImmutableSamplers = NULL;
9196
9197 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9198 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9199 ds_layout_ci.pNext = NULL;
9200 ds_layout_ci.bindingCount = 1;
9201 ds_layout_ci.pBindings = &dsl_binding;
9202 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009203 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009204 ASSERT_VK_SUCCESS(err);
9205
9206 VkDescriptorSet descriptor_set = {};
9207 VkDescriptorSetAllocateInfo alloc_info = {};
9208 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9209 alloc_info.descriptorSetCount = 1;
9210 alloc_info.descriptorPool = ds_pool;
9211 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009212 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009213 ASSERT_VK_SUCCESS(err);
9214
9215 // Create a buffer to be used for invalid updates
9216 VkBufferCreateInfo buff_ci = {};
9217 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9218 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9219 buff_ci.size = 256;
9220 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9221 VkBuffer buffer;
9222 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9223 ASSERT_VK_SUCCESS(err);
9224 // Have to bind memory to buffer before descriptor update
9225 VkMemoryAllocateInfo mem_alloc = {};
9226 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9227 mem_alloc.pNext = NULL;
9228 mem_alloc.allocationSize = 256;
9229 mem_alloc.memoryTypeIndex = 0;
9230
9231 VkMemoryRequirements mem_reqs;
9232 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009233 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009234 if (!pass) {
9235 vkDestroyBuffer(m_device->device(), buffer, NULL);
9236 return;
9237 }
9238
9239 VkDeviceMemory mem;
9240 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9241 ASSERT_VK_SUCCESS(err);
9242 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9243 ASSERT_VK_SUCCESS(err);
9244
9245 VkDescriptorBufferInfo buff_info = {};
9246 buff_info.buffer = buffer;
9247 // First make offset 1 larger than buffer size
9248 buff_info.offset = 257;
9249 buff_info.range = VK_WHOLE_SIZE;
9250 VkWriteDescriptorSet descriptor_write = {};
9251 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9252 descriptor_write.dstBinding = 0;
9253 descriptor_write.descriptorCount = 1;
9254 descriptor_write.pTexelBufferView = nullptr;
9255 descriptor_write.pBufferInfo = &buff_info;
9256 descriptor_write.pImageInfo = nullptr;
9257
9258 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9259 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009261
9262 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9263
9264 m_errorMonitor->VerifyFound();
9265 // Now cause error due to range of 0
9266 buff_info.offset = 0;
9267 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009269
9270 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9271
9272 m_errorMonitor->VerifyFound();
9273 // Now cause error due to range exceeding buffer size - offset
9274 buff_info.offset = 128;
9275 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009277
9278 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9279
9280 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009281 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009282 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9283 vkDestroyBuffer(m_device->device(), buffer, NULL);
9284 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9285 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9286}
9287
Tobin Ehlis845887e2017-02-02 19:01:44 -07009288TEST_F(VkLayerTest, DSBufferLimitErrors) {
9289 TEST_DESCRIPTION(
9290 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9291 "Test cases include:\n"
9292 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9293 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9294 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9295 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9296 VkResult err;
9297
9298 ASSERT_NO_FATAL_FAILURE(InitState());
9299 VkDescriptorPoolSize ds_type_count[2] = {};
9300 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9301 ds_type_count[0].descriptorCount = 1;
9302 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9303 ds_type_count[1].descriptorCount = 1;
9304
9305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9307 ds_pool_ci.pNext = NULL;
9308 ds_pool_ci.maxSets = 1;
9309 ds_pool_ci.poolSizeCount = 2;
9310 ds_pool_ci.pPoolSizes = ds_type_count;
9311
9312 VkDescriptorPool ds_pool;
9313 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9314 ASSERT_VK_SUCCESS(err);
9315
9316 // Create layout with single uniform buffer & single storage buffer descriptor
9317 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9318 dsl_binding[0].binding = 0;
9319 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9320 dsl_binding[0].descriptorCount = 1;
9321 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9322 dsl_binding[0].pImmutableSamplers = NULL;
9323 dsl_binding[1].binding = 1;
9324 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9325 dsl_binding[1].descriptorCount = 1;
9326 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9327 dsl_binding[1].pImmutableSamplers = NULL;
9328
9329 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9330 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9331 ds_layout_ci.pNext = NULL;
9332 ds_layout_ci.bindingCount = 2;
9333 ds_layout_ci.pBindings = dsl_binding;
9334 VkDescriptorSetLayout ds_layout;
9335 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9336 ASSERT_VK_SUCCESS(err);
9337
9338 VkDescriptorSet descriptor_set = {};
9339 VkDescriptorSetAllocateInfo alloc_info = {};
9340 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9341 alloc_info.descriptorSetCount = 1;
9342 alloc_info.descriptorPool = ds_pool;
9343 alloc_info.pSetLayouts = &ds_layout;
9344 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9345 ASSERT_VK_SUCCESS(err);
9346
9347 // Create a buffer to be used for invalid updates
9348 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9349 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9350 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9351 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9352 VkBufferCreateInfo ub_ci = {};
9353 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9354 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9355 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9356 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9357 VkBuffer uniform_buffer;
9358 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9359 ASSERT_VK_SUCCESS(err);
9360 VkBufferCreateInfo sb_ci = {};
9361 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9362 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9363 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9364 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9365 VkBuffer storage_buffer;
9366 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9367 ASSERT_VK_SUCCESS(err);
9368 // Have to bind memory to buffer before descriptor update
9369 VkMemoryAllocateInfo mem_alloc = {};
9370 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9371 mem_alloc.pNext = NULL;
9372 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9373 mem_alloc.memoryTypeIndex = 0;
9374
9375 VkMemoryRequirements mem_reqs;
9376 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9377 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9378 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9379 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9380 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009381 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009382 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009383 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9384 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009385 return;
9386 }
9387
9388 VkDeviceMemory mem;
9389 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009390 if (VK_SUCCESS != err) {
9391 printf("Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
9392 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9393 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9394 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9395 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9396 return;
9397 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009398 ASSERT_VK_SUCCESS(err);
9399 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9400 ASSERT_VK_SUCCESS(err);
9401 auto sb_offset = ub_ci.size + 1024;
9402 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9403 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9404 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9405 ASSERT_VK_SUCCESS(err);
9406
9407 VkDescriptorBufferInfo buff_info = {};
9408 buff_info.buffer = uniform_buffer;
9409 buff_info.range = ub_ci.size; // This will exceed limit
9410 VkWriteDescriptorSet descriptor_write = {};
9411 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9412 descriptor_write.dstBinding = 0;
9413 descriptor_write.descriptorCount = 1;
9414 descriptor_write.pTexelBufferView = nullptr;
9415 descriptor_write.pBufferInfo = &buff_info;
9416 descriptor_write.pImageInfo = nullptr;
9417
9418 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9419 descriptor_write.dstSet = descriptor_set;
9420 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9421 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9422 m_errorMonitor->VerifyFound();
9423
9424 // Reduce size of range to acceptable limit & cause offset error
9425 buff_info.range = max_ub_range;
9426 buff_info.offset = min_ub_align - 1;
9427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9428 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9429 m_errorMonitor->VerifyFound();
9430
9431 // Now break storage updates
9432 buff_info.buffer = storage_buffer;
9433 buff_info.range = sb_ci.size; // This will exceed limit
9434 buff_info.offset = 0; // Reset offset for this update
9435
9436 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9437 descriptor_write.dstBinding = 1;
9438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9439 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9440 m_errorMonitor->VerifyFound();
9441
9442 // Reduce size of range to acceptable limit & cause offset error
9443 buff_info.range = max_sb_range;
9444 buff_info.offset = min_sb_align - 1;
9445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9446 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9447 m_errorMonitor->VerifyFound();
9448
9449 vkFreeMemory(m_device->device(), mem, NULL);
9450 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9451 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9452 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9453 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9454}
9455
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009456TEST_F(VkLayerTest, DSAspectBitsErrors) {
9457 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9458 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009459 TEST_DESCRIPTION(
9460 "Attempt to update descriptor sets for images "
9461 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009462 VkResult err;
9463
9464 ASSERT_NO_FATAL_FAILURE(InitState());
9465 VkDescriptorPoolSize ds_type_count = {};
9466 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9467 ds_type_count.descriptorCount = 1;
9468
9469 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9470 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9471 ds_pool_ci.pNext = NULL;
9472 ds_pool_ci.maxSets = 5;
9473 ds_pool_ci.poolSizeCount = 1;
9474 ds_pool_ci.pPoolSizes = &ds_type_count;
9475
9476 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009477 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009478 ASSERT_VK_SUCCESS(err);
9479
9480 VkDescriptorSetLayoutBinding dsl_binding = {};
9481 dsl_binding.binding = 0;
9482 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9483 dsl_binding.descriptorCount = 1;
9484 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9485 dsl_binding.pImmutableSamplers = NULL;
9486
9487 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9488 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9489 ds_layout_ci.pNext = NULL;
9490 ds_layout_ci.bindingCount = 1;
9491 ds_layout_ci.pBindings = &dsl_binding;
9492 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009493 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009494 ASSERT_VK_SUCCESS(err);
9495
9496 VkDescriptorSet descriptor_set = {};
9497 VkDescriptorSetAllocateInfo alloc_info = {};
9498 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9499 alloc_info.descriptorSetCount = 1;
9500 alloc_info.descriptorPool = ds_pool;
9501 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009502 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009503 ASSERT_VK_SUCCESS(err);
9504
9505 // Create an image to be used for invalid updates
9506 VkImageCreateInfo image_ci = {};
9507 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9508 image_ci.imageType = VK_IMAGE_TYPE_2D;
9509 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9510 image_ci.extent.width = 64;
9511 image_ci.extent.height = 64;
9512 image_ci.extent.depth = 1;
9513 image_ci.mipLevels = 1;
9514 image_ci.arrayLayers = 1;
9515 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9516 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9517 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9518 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9519 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9520 VkImage image;
9521 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9522 ASSERT_VK_SUCCESS(err);
9523 // Bind memory to image
9524 VkMemoryRequirements mem_reqs;
9525 VkDeviceMemory image_mem;
9526 bool pass;
9527 VkMemoryAllocateInfo mem_alloc = {};
9528 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9529 mem_alloc.pNext = NULL;
9530 mem_alloc.allocationSize = 0;
9531 mem_alloc.memoryTypeIndex = 0;
9532 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9533 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009534 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009535 ASSERT_TRUE(pass);
9536 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9537 ASSERT_VK_SUCCESS(err);
9538 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9539 ASSERT_VK_SUCCESS(err);
9540 // Now create view for image
9541 VkImageViewCreateInfo image_view_ci = {};
9542 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9543 image_view_ci.image = image;
9544 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9545 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9546 image_view_ci.subresourceRange.layerCount = 1;
9547 image_view_ci.subresourceRange.baseArrayLayer = 0;
9548 image_view_ci.subresourceRange.levelCount = 1;
9549 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009550 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009551
9552 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009553 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009554 ASSERT_VK_SUCCESS(err);
9555
9556 VkDescriptorImageInfo img_info = {};
9557 img_info.imageView = image_view;
9558 VkWriteDescriptorSet descriptor_write = {};
9559 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9560 descriptor_write.dstBinding = 0;
9561 descriptor_write.descriptorCount = 1;
9562 descriptor_write.pTexelBufferView = NULL;
9563 descriptor_write.pBufferInfo = NULL;
9564 descriptor_write.pImageInfo = &img_info;
9565 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9566 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009567 const char *error_msg =
9568 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9569 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009571
9572 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9573
9574 m_errorMonitor->VerifyFound();
9575 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9576 vkDestroyImage(m_device->device(), image, NULL);
9577 vkFreeMemory(m_device->device(), image_mem, NULL);
9578 vkDestroyImageView(m_device->device(), image_view, NULL);
9579 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9580 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9581}
9582
Karl Schultz6addd812016-02-02 17:17:23 -07009583TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009584 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009585 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009586
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9588 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9589 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009590
Tobin Ehlis3b780662015-05-28 12:11:26 -06009591 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009592 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009593 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009594 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9595 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009596
9597 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009598 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9599 ds_pool_ci.pNext = NULL;
9600 ds_pool_ci.maxSets = 1;
9601 ds_pool_ci.poolSizeCount = 1;
9602 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009603
Tobin Ehlis3b780662015-05-28 12:11:26 -06009604 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009605 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009606 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009607 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009608 dsl_binding.binding = 0;
9609 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9610 dsl_binding.descriptorCount = 1;
9611 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9612 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009613
Tony Barboureb254902015-07-15 12:50:33 -06009614 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009615 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9616 ds_layout_ci.pNext = NULL;
9617 ds_layout_ci.bindingCount = 1;
9618 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009619
Tobin Ehlis3b780662015-05-28 12:11:26 -06009620 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009621 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009622 ASSERT_VK_SUCCESS(err);
9623
9624 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009625 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009626 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009627 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009628 alloc_info.descriptorPool = ds_pool;
9629 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009630 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009631 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009632
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009633 VkSamplerCreateInfo sampler_ci = {};
9634 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9635 sampler_ci.pNext = NULL;
9636 sampler_ci.magFilter = VK_FILTER_NEAREST;
9637 sampler_ci.minFilter = VK_FILTER_NEAREST;
9638 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9639 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9640 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9641 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9642 sampler_ci.mipLodBias = 1.0;
9643 sampler_ci.anisotropyEnable = VK_FALSE;
9644 sampler_ci.maxAnisotropy = 1;
9645 sampler_ci.compareEnable = VK_FALSE;
9646 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9647 sampler_ci.minLod = 1.0;
9648 sampler_ci.maxLod = 1.0;
9649 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9650 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9651 VkSampler sampler;
9652 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9653 ASSERT_VK_SUCCESS(err);
9654
9655 VkDescriptorImageInfo info = {};
9656 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009657
9658 VkWriteDescriptorSet descriptor_write;
9659 memset(&descriptor_write, 0, sizeof(descriptor_write));
9660 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009661 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009662 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009663 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009664 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009665 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009666
9667 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9668
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009669 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009670
Chia-I Wuf7458c52015-10-26 21:10:41 +08009671 vkDestroySampler(m_device->device(), sampler, NULL);
9672 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9673 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009674}
9675
Karl Schultz6addd812016-02-02 17:17:23 -07009676TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009677 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009678 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009679
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009681
Tobin Ehlis3b780662015-05-28 12:11:26 -06009682 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009683 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009684 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009685 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9686 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009687
9688 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009689 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9690 ds_pool_ci.pNext = NULL;
9691 ds_pool_ci.maxSets = 1;
9692 ds_pool_ci.poolSizeCount = 1;
9693 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009694
Tobin Ehlis3b780662015-05-28 12:11:26 -06009695 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009696 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009697 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009698
Tony Barboureb254902015-07-15 12:50:33 -06009699 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009700 dsl_binding.binding = 0;
9701 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9702 dsl_binding.descriptorCount = 1;
9703 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9704 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009705
9706 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009707 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9708 ds_layout_ci.pNext = NULL;
9709 ds_layout_ci.bindingCount = 1;
9710 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009711
Tobin Ehlis3b780662015-05-28 12:11:26 -06009712 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009713 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009714 ASSERT_VK_SUCCESS(err);
9715
9716 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009717 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009718 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009719 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009720 alloc_info.descriptorPool = ds_pool;
9721 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009722 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009723 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009724
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009725 // Correctly update descriptor to avoid "NOT_UPDATED" error
9726 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009727 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009728 buff_info.offset = 0;
9729 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009730
9731 VkWriteDescriptorSet descriptor_write;
9732 memset(&descriptor_write, 0, sizeof(descriptor_write));
9733 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009734 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009735 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009736 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009737 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9738 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009739
9740 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9741
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009742 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009743
Chia-I Wuf7458c52015-10-26 21:10:41 +08009744 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9745 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009746}
9747
Karl Schultz6addd812016-02-02 17:17:23 -07009748TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009749 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009750 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009751
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009752 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009753
Tobin Ehlis3b780662015-05-28 12:11:26 -06009754 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009755 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009756 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009757 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9758 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009759
9760 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009761 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9762 ds_pool_ci.pNext = NULL;
9763 ds_pool_ci.maxSets = 1;
9764 ds_pool_ci.poolSizeCount = 1;
9765 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009766
Tobin Ehlis3b780662015-05-28 12:11:26 -06009767 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009768 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009769 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009770
Tony Barboureb254902015-07-15 12:50:33 -06009771 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009772 dsl_binding.binding = 0;
9773 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9774 dsl_binding.descriptorCount = 1;
9775 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9776 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009777
9778 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009779 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9780 ds_layout_ci.pNext = NULL;
9781 ds_layout_ci.bindingCount = 1;
9782 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009783 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009784 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009785 ASSERT_VK_SUCCESS(err);
9786
9787 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009788 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009789 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009790 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009791 alloc_info.descriptorPool = ds_pool;
9792 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009793 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009794 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009795
Tony Barboureb254902015-07-15 12:50:33 -06009796 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009797 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9798 sampler_ci.pNext = NULL;
9799 sampler_ci.magFilter = VK_FILTER_NEAREST;
9800 sampler_ci.minFilter = VK_FILTER_NEAREST;
9801 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9802 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9803 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9804 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9805 sampler_ci.mipLodBias = 1.0;
9806 sampler_ci.anisotropyEnable = VK_FALSE;
9807 sampler_ci.maxAnisotropy = 1;
9808 sampler_ci.compareEnable = VK_FALSE;
9809 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9810 sampler_ci.minLod = 1.0;
9811 sampler_ci.maxLod = 1.0;
9812 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9813 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009814
Tobin Ehlis3b780662015-05-28 12:11:26 -06009815 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009816 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009817 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009818
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009819 VkDescriptorImageInfo info = {};
9820 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009821
9822 VkWriteDescriptorSet descriptor_write;
9823 memset(&descriptor_write, 0, sizeof(descriptor_write));
9824 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009825 descriptor_write.dstSet = descriptorSet;
9826 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009827 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009828 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009829 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009830 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009831
9832 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9833
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009834 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009835
Chia-I Wuf7458c52015-10-26 21:10:41 +08009836 vkDestroySampler(m_device->device(), sampler, NULL);
9837 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9838 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009839}
9840
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009841TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9842 // Create layout w/ empty binding and attempt to update it
9843 VkResult err;
9844
9845 ASSERT_NO_FATAL_FAILURE(InitState());
9846
9847 VkDescriptorPoolSize ds_type_count = {};
9848 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9849 ds_type_count.descriptorCount = 1;
9850
9851 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9852 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9853 ds_pool_ci.pNext = NULL;
9854 ds_pool_ci.maxSets = 1;
9855 ds_pool_ci.poolSizeCount = 1;
9856 ds_pool_ci.pPoolSizes = &ds_type_count;
9857
9858 VkDescriptorPool ds_pool;
9859 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9860 ASSERT_VK_SUCCESS(err);
9861
9862 VkDescriptorSetLayoutBinding dsl_binding = {};
9863 dsl_binding.binding = 0;
9864 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9865 dsl_binding.descriptorCount = 0;
9866 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9867 dsl_binding.pImmutableSamplers = NULL;
9868
9869 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9870 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9871 ds_layout_ci.pNext = NULL;
9872 ds_layout_ci.bindingCount = 1;
9873 ds_layout_ci.pBindings = &dsl_binding;
9874 VkDescriptorSetLayout ds_layout;
9875 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9876 ASSERT_VK_SUCCESS(err);
9877
9878 VkDescriptorSet descriptor_set;
9879 VkDescriptorSetAllocateInfo alloc_info = {};
9880 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9881 alloc_info.descriptorSetCount = 1;
9882 alloc_info.descriptorPool = ds_pool;
9883 alloc_info.pSetLayouts = &ds_layout;
9884 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9885 ASSERT_VK_SUCCESS(err);
9886
9887 VkSamplerCreateInfo sampler_ci = {};
9888 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9889 sampler_ci.magFilter = VK_FILTER_NEAREST;
9890 sampler_ci.minFilter = VK_FILTER_NEAREST;
9891 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9892 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9893 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9894 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9895 sampler_ci.mipLodBias = 1.0;
9896 sampler_ci.maxAnisotropy = 1;
9897 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9898 sampler_ci.minLod = 1.0;
9899 sampler_ci.maxLod = 1.0;
9900 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9901
9902 VkSampler sampler;
9903 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9904 ASSERT_VK_SUCCESS(err);
9905
9906 VkDescriptorImageInfo info = {};
9907 info.sampler = sampler;
9908
9909 VkWriteDescriptorSet descriptor_write;
9910 memset(&descriptor_write, 0, sizeof(descriptor_write));
9911 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9912 descriptor_write.dstSet = descriptor_set;
9913 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009914 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009915 // This is the wrong type, but empty binding error will be flagged first
9916 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9917 descriptor_write.pImageInfo = &info;
9918
9919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9920 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9921 m_errorMonitor->VerifyFound();
9922
9923 vkDestroySampler(m_device->device(), sampler, NULL);
9924 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9925 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9926}
9927
Karl Schultz6addd812016-02-02 17:17:23 -07009928TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9929 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9930 // types
9931 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009932
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009933 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 -06009934
Tobin Ehlis3b780662015-05-28 12:11:26 -06009935 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009936
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009937 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009938 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9939 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009940
9941 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009942 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9943 ds_pool_ci.pNext = NULL;
9944 ds_pool_ci.maxSets = 1;
9945 ds_pool_ci.poolSizeCount = 1;
9946 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009947
Tobin Ehlis3b780662015-05-28 12:11:26 -06009948 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009949 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009950 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009951 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009952 dsl_binding.binding = 0;
9953 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9954 dsl_binding.descriptorCount = 1;
9955 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9956 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009957
Tony Barboureb254902015-07-15 12:50:33 -06009958 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009959 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9960 ds_layout_ci.pNext = NULL;
9961 ds_layout_ci.bindingCount = 1;
9962 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009963
Tobin Ehlis3b780662015-05-28 12:11:26 -06009964 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009965 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009966 ASSERT_VK_SUCCESS(err);
9967
9968 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009969 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009970 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009971 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009972 alloc_info.descriptorPool = ds_pool;
9973 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009974 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009975 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009976
Tony Barboureb254902015-07-15 12:50:33 -06009977 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009978 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9979 sampler_ci.pNext = NULL;
9980 sampler_ci.magFilter = VK_FILTER_NEAREST;
9981 sampler_ci.minFilter = VK_FILTER_NEAREST;
9982 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9983 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9984 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9985 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9986 sampler_ci.mipLodBias = 1.0;
9987 sampler_ci.anisotropyEnable = VK_FALSE;
9988 sampler_ci.maxAnisotropy = 1;
9989 sampler_ci.compareEnable = VK_FALSE;
9990 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9991 sampler_ci.minLod = 1.0;
9992 sampler_ci.maxLod = 1.0;
9993 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9994 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009995 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009996 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009997 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009998
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009999 VkDescriptorImageInfo info = {};
10000 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010001
10002 VkWriteDescriptorSet descriptor_write;
10003 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010004 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010005 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010006 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010007 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010008 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010009 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010010
10011 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10012
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010013 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010014
Chia-I Wuf7458c52015-10-26 21:10:41 +080010015 vkDestroySampler(m_device->device(), sampler, NULL);
10016 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10017 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010018}
10019
Karl Schultz6addd812016-02-02 17:17:23 -070010020TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010021 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010022 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010023
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010025
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010026 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010027 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10028 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010029 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010030 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10031 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010032
10033 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010034 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10035 ds_pool_ci.pNext = NULL;
10036 ds_pool_ci.maxSets = 1;
10037 ds_pool_ci.poolSizeCount = 1;
10038 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010039
10040 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010041 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010042 ASSERT_VK_SUCCESS(err);
10043
10044 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010045 dsl_binding.binding = 0;
10046 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10047 dsl_binding.descriptorCount = 1;
10048 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10049 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010050
10051 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010052 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10053 ds_layout_ci.pNext = NULL;
10054 ds_layout_ci.bindingCount = 1;
10055 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010056 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010057 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010058 ASSERT_VK_SUCCESS(err);
10059
10060 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010061 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010062 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010063 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010064 alloc_info.descriptorPool = ds_pool;
10065 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010066 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010067 ASSERT_VK_SUCCESS(err);
10068
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010069 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010070
10071 VkDescriptorImageInfo descriptor_info;
10072 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10073 descriptor_info.sampler = sampler;
10074
10075 VkWriteDescriptorSet descriptor_write;
10076 memset(&descriptor_write, 0, sizeof(descriptor_write));
10077 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010078 descriptor_write.dstSet = descriptorSet;
10079 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010080 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010081 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10082 descriptor_write.pImageInfo = &descriptor_info;
10083
10084 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10085
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010086 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010087
Chia-I Wuf7458c52015-10-26 21:10:41 +080010088 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10089 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010090}
10091
Karl Schultz6addd812016-02-02 17:17:23 -070010092TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10093 // Create a single combined Image/Sampler descriptor and send it an invalid
10094 // imageView
10095 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010096
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010097 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010098
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010099 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010100 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010101 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10102 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010103
10104 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010105 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10106 ds_pool_ci.pNext = NULL;
10107 ds_pool_ci.maxSets = 1;
10108 ds_pool_ci.poolSizeCount = 1;
10109 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010110
10111 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010112 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010113 ASSERT_VK_SUCCESS(err);
10114
10115 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010116 dsl_binding.binding = 0;
10117 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10118 dsl_binding.descriptorCount = 1;
10119 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10120 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010121
10122 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010123 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10124 ds_layout_ci.pNext = NULL;
10125 ds_layout_ci.bindingCount = 1;
10126 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010127 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010128 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010129 ASSERT_VK_SUCCESS(err);
10130
10131 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010132 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010133 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010134 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010135 alloc_info.descriptorPool = ds_pool;
10136 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010137 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010138 ASSERT_VK_SUCCESS(err);
10139
10140 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010141 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10142 sampler_ci.pNext = NULL;
10143 sampler_ci.magFilter = VK_FILTER_NEAREST;
10144 sampler_ci.minFilter = VK_FILTER_NEAREST;
10145 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10146 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10147 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10148 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10149 sampler_ci.mipLodBias = 1.0;
10150 sampler_ci.anisotropyEnable = VK_FALSE;
10151 sampler_ci.maxAnisotropy = 1;
10152 sampler_ci.compareEnable = VK_FALSE;
10153 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10154 sampler_ci.minLod = 1.0;
10155 sampler_ci.maxLod = 1.0;
10156 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10157 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010158
10159 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010160 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010161 ASSERT_VK_SUCCESS(err);
10162
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010163 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010164
10165 VkDescriptorImageInfo descriptor_info;
10166 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10167 descriptor_info.sampler = sampler;
10168 descriptor_info.imageView = view;
10169
10170 VkWriteDescriptorSet descriptor_write;
10171 memset(&descriptor_write, 0, sizeof(descriptor_write));
10172 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010173 descriptor_write.dstSet = descriptorSet;
10174 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010175 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010176 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10177 descriptor_write.pImageInfo = &descriptor_info;
10178
10179 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10180
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010181 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010182
Chia-I Wuf7458c52015-10-26 21:10:41 +080010183 vkDestroySampler(m_device->device(), sampler, NULL);
10184 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10185 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010186}
10187
Karl Schultz6addd812016-02-02 17:17:23 -070010188TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10189 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10190 // into the other
10191 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010192
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10194 " binding #1 with type "
10195 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10196 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010197
Tobin Ehlis04356f92015-10-27 16:35:27 -060010198 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010199 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010200 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010201 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10202 ds_type_count[0].descriptorCount = 1;
10203 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10204 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010205
10206 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010207 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10208 ds_pool_ci.pNext = NULL;
10209 ds_pool_ci.maxSets = 1;
10210 ds_pool_ci.poolSizeCount = 2;
10211 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010212
10213 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010214 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010215 ASSERT_VK_SUCCESS(err);
10216 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010217 dsl_binding[0].binding = 0;
10218 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10219 dsl_binding[0].descriptorCount = 1;
10220 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10221 dsl_binding[0].pImmutableSamplers = NULL;
10222 dsl_binding[1].binding = 1;
10223 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10224 dsl_binding[1].descriptorCount = 1;
10225 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10226 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010227
10228 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010229 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10230 ds_layout_ci.pNext = NULL;
10231 ds_layout_ci.bindingCount = 2;
10232 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010233
10234 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010235 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010236 ASSERT_VK_SUCCESS(err);
10237
10238 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010239 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010240 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010241 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010242 alloc_info.descriptorPool = ds_pool;
10243 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010244 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010245 ASSERT_VK_SUCCESS(err);
10246
10247 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010248 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10249 sampler_ci.pNext = NULL;
10250 sampler_ci.magFilter = VK_FILTER_NEAREST;
10251 sampler_ci.minFilter = VK_FILTER_NEAREST;
10252 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10253 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10254 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10255 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10256 sampler_ci.mipLodBias = 1.0;
10257 sampler_ci.anisotropyEnable = VK_FALSE;
10258 sampler_ci.maxAnisotropy = 1;
10259 sampler_ci.compareEnable = VK_FALSE;
10260 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10261 sampler_ci.minLod = 1.0;
10262 sampler_ci.maxLod = 1.0;
10263 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10264 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010265
10266 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010267 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010268 ASSERT_VK_SUCCESS(err);
10269
10270 VkDescriptorImageInfo info = {};
10271 info.sampler = sampler;
10272
10273 VkWriteDescriptorSet descriptor_write;
10274 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10275 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010276 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010277 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010278 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010279 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10280 descriptor_write.pImageInfo = &info;
10281 // This write update should succeed
10282 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10283 // Now perform a copy update that fails due to type mismatch
10284 VkCopyDescriptorSet copy_ds_update;
10285 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10286 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10287 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010288 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010289 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010290 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10291 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010292 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10293
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010294 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010295 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010296 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 -060010297 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10298 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10299 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010300 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010301 copy_ds_update.dstSet = descriptorSet;
10302 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010303 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010304 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10305
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010306 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010307
Tobin Ehlis04356f92015-10-27 16:35:27 -060010308 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10310 " binding#1 with offset index of 1 plus "
10311 "update array offset of 0 and update of "
10312 "5 descriptors oversteps total number "
10313 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010314
Tobin Ehlis04356f92015-10-27 16:35:27 -060010315 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10316 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10317 copy_ds_update.srcSet = descriptorSet;
10318 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010319 copy_ds_update.dstSet = descriptorSet;
10320 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010321 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010322 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10323
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010324 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010325
Chia-I Wuf7458c52015-10-26 21:10:41 +080010326 vkDestroySampler(m_device->device(), sampler, NULL);
10327 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10328 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010329}
10330
Karl Schultz6addd812016-02-02 17:17:23 -070010331TEST_F(VkLayerTest, NumSamplesMismatch) {
10332 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10333 // sampleCount
10334 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010335
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010337
Tobin Ehlis3b780662015-05-28 12:11:26 -060010338 ASSERT_NO_FATAL_FAILURE(InitState());
10339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010340 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010341 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010342 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010343
10344 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010345 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10346 ds_pool_ci.pNext = NULL;
10347 ds_pool_ci.maxSets = 1;
10348 ds_pool_ci.poolSizeCount = 1;
10349 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010350
Tobin Ehlis3b780662015-05-28 12:11:26 -060010351 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010352 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010353 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010354
Tony Barboureb254902015-07-15 12:50:33 -060010355 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010356 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010357 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010358 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010359 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10360 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010361
Tony Barboureb254902015-07-15 12:50:33 -060010362 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10363 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10364 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010365 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010366 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010367
Tobin Ehlis3b780662015-05-28 12:11:26 -060010368 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010369 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010370 ASSERT_VK_SUCCESS(err);
10371
10372 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010373 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010374 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010375 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010376 alloc_info.descriptorPool = ds_pool;
10377 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010378 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010379 ASSERT_VK_SUCCESS(err);
10380
Tony Barboureb254902015-07-15 12:50:33 -060010381 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010382 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010383 pipe_ms_state_ci.pNext = NULL;
10384 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10385 pipe_ms_state_ci.sampleShadingEnable = 0;
10386 pipe_ms_state_ci.minSampleShading = 1.0;
10387 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010388
Tony Barboureb254902015-07-15 12:50:33 -060010389 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010390 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10391 pipeline_layout_ci.pNext = NULL;
10392 pipeline_layout_ci.setLayoutCount = 1;
10393 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010394
10395 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010396 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010397 ASSERT_VK_SUCCESS(err);
10398
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010399 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010400 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010401 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010402 VkPipelineObj pipe(m_device);
10403 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010404 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010405 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010406 pipe.SetMSAA(&pipe_ms_state_ci);
10407 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010408
Tony Barbour552f6c02016-12-21 14:34:07 -070010409 m_commandBuffer->BeginCommandBuffer();
10410 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010411 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010412
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010413 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10414 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10415 VkRect2D scissor = {{0, 0}, {16, 16}};
10416 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10417
Mark Young29927482016-05-04 14:38:51 -060010418 // Render triangle (the error should trigger on the attempt to draw).
10419 Draw(3, 1, 0, 0);
10420
10421 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010422 m_commandBuffer->EndRenderPass();
10423 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010424
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010425 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010426
Chia-I Wuf7458c52015-10-26 21:10:41 +080010427 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10428 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10429 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010430}
Mark Young29927482016-05-04 14:38:51 -060010431
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010432TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010433 TEST_DESCRIPTION(
10434 "Hit RenderPass incompatible cases. "
10435 "Initial case is drawing with an active renderpass that's "
10436 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010437 VkResult err;
10438
10439 ASSERT_NO_FATAL_FAILURE(InitState());
10440 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10441
10442 VkDescriptorSetLayoutBinding dsl_binding = {};
10443 dsl_binding.binding = 0;
10444 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10445 dsl_binding.descriptorCount = 1;
10446 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10447 dsl_binding.pImmutableSamplers = NULL;
10448
10449 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10450 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10451 ds_layout_ci.pNext = NULL;
10452 ds_layout_ci.bindingCount = 1;
10453 ds_layout_ci.pBindings = &dsl_binding;
10454
10455 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010456 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010457 ASSERT_VK_SUCCESS(err);
10458
10459 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10460 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10461 pipeline_layout_ci.pNext = NULL;
10462 pipeline_layout_ci.setLayoutCount = 1;
10463 pipeline_layout_ci.pSetLayouts = &ds_layout;
10464
10465 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010466 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010467 ASSERT_VK_SUCCESS(err);
10468
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010469 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010470 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010471 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010472 // Create a renderpass that will be incompatible with default renderpass
10473 VkAttachmentReference attach = {};
10474 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10475 VkAttachmentReference color_att = {};
10476 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10477 VkSubpassDescription subpass = {};
10478 subpass.inputAttachmentCount = 1;
10479 subpass.pInputAttachments = &attach;
10480 subpass.colorAttachmentCount = 1;
10481 subpass.pColorAttachments = &color_att;
10482 VkRenderPassCreateInfo rpci = {};
10483 rpci.subpassCount = 1;
10484 rpci.pSubpasses = &subpass;
10485 rpci.attachmentCount = 1;
10486 VkAttachmentDescription attach_desc = {};
10487 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010488 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10489 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010490 rpci.pAttachments = &attach_desc;
10491 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10492 VkRenderPass rp;
10493 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10494 VkPipelineObj pipe(m_device);
10495 pipe.AddShader(&vs);
10496 pipe.AddShader(&fs);
10497 pipe.AddColorAttachment();
10498 VkViewport view_port = {};
10499 m_viewports.push_back(view_port);
10500 pipe.SetViewport(m_viewports);
10501 VkRect2D rect = {};
10502 m_scissors.push_back(rect);
10503 pipe.SetScissor(m_scissors);
10504 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10505
10506 VkCommandBufferInheritanceInfo cbii = {};
10507 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10508 cbii.renderPass = rp;
10509 cbii.subpass = 0;
10510 VkCommandBufferBeginInfo cbbi = {};
10511 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10512 cbbi.pInheritanceInfo = &cbii;
10513 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10514 VkRenderPassBeginInfo rpbi = {};
10515 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10516 rpbi.framebuffer = m_framebuffer;
10517 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010518 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10519 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010522 // Render triangle (the error should trigger on the attempt to draw).
10523 Draw(3, 1, 0, 0);
10524
10525 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010526 m_commandBuffer->EndRenderPass();
10527 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010528
10529 m_errorMonitor->VerifyFound();
10530
10531 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10532 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10533 vkDestroyRenderPass(m_device->device(), rp, NULL);
10534}
10535
Mark Youngc89c6312016-03-31 16:03:20 -060010536TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10537 // Create Pipeline where the number of blend attachments doesn't match the
10538 // number of color attachments. In this case, we don't add any color
10539 // blend attachments even though we have a color attachment.
10540 VkResult err;
10541
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010543
10544 ASSERT_NO_FATAL_FAILURE(InitState());
10545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10546 VkDescriptorPoolSize ds_type_count = {};
10547 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10548 ds_type_count.descriptorCount = 1;
10549
10550 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10551 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10552 ds_pool_ci.pNext = NULL;
10553 ds_pool_ci.maxSets = 1;
10554 ds_pool_ci.poolSizeCount = 1;
10555 ds_pool_ci.pPoolSizes = &ds_type_count;
10556
10557 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010559 ASSERT_VK_SUCCESS(err);
10560
10561 VkDescriptorSetLayoutBinding dsl_binding = {};
10562 dsl_binding.binding = 0;
10563 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10564 dsl_binding.descriptorCount = 1;
10565 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10566 dsl_binding.pImmutableSamplers = NULL;
10567
10568 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10569 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10570 ds_layout_ci.pNext = NULL;
10571 ds_layout_ci.bindingCount = 1;
10572 ds_layout_ci.pBindings = &dsl_binding;
10573
10574 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010575 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010576 ASSERT_VK_SUCCESS(err);
10577
10578 VkDescriptorSet descriptorSet;
10579 VkDescriptorSetAllocateInfo alloc_info = {};
10580 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10581 alloc_info.descriptorSetCount = 1;
10582 alloc_info.descriptorPool = ds_pool;
10583 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010584 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010585 ASSERT_VK_SUCCESS(err);
10586
10587 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010588 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010589 pipe_ms_state_ci.pNext = NULL;
10590 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10591 pipe_ms_state_ci.sampleShadingEnable = 0;
10592 pipe_ms_state_ci.minSampleShading = 1.0;
10593 pipe_ms_state_ci.pSampleMask = NULL;
10594
10595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10596 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10597 pipeline_layout_ci.pNext = NULL;
10598 pipeline_layout_ci.setLayoutCount = 1;
10599 pipeline_layout_ci.pSetLayouts = &ds_layout;
10600
10601 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010602 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010603 ASSERT_VK_SUCCESS(err);
10604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010605 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010606 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010607 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010608 VkPipelineObj pipe(m_device);
10609 pipe.AddShader(&vs);
10610 pipe.AddShader(&fs);
10611 pipe.SetMSAA(&pipe_ms_state_ci);
10612 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010613 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010614
10615 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10616 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10617 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10618}
Mark Young29927482016-05-04 14:38:51 -060010619
Mark Muellerd4914412016-06-13 17:52:06 -060010620TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010621 TEST_DESCRIPTION(
10622 "Points to a wrong colorAttachment index in a VkClearAttachment "
10623 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010624 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010626
10627 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10628 m_errorMonitor->VerifyFound();
10629}
10630
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010631TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010632 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10633 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010634
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010635 ASSERT_NO_FATAL_FAILURE(InitState());
10636 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010637
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010638 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010639 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10640 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010641
10642 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010643 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10644 ds_pool_ci.pNext = NULL;
10645 ds_pool_ci.maxSets = 1;
10646 ds_pool_ci.poolSizeCount = 1;
10647 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010648
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010649 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010650 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010651 ASSERT_VK_SUCCESS(err);
10652
Tony Barboureb254902015-07-15 12:50:33 -060010653 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010654 dsl_binding.binding = 0;
10655 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10656 dsl_binding.descriptorCount = 1;
10657 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10658 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010659
Tony Barboureb254902015-07-15 12:50:33 -060010660 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010661 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10662 ds_layout_ci.pNext = NULL;
10663 ds_layout_ci.bindingCount = 1;
10664 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010665
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010666 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010667 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010668 ASSERT_VK_SUCCESS(err);
10669
10670 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010671 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010672 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010673 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010674 alloc_info.descriptorPool = ds_pool;
10675 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010676 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010677 ASSERT_VK_SUCCESS(err);
10678
Tony Barboureb254902015-07-15 12:50:33 -060010679 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010680 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010681 pipe_ms_state_ci.pNext = NULL;
10682 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10683 pipe_ms_state_ci.sampleShadingEnable = 0;
10684 pipe_ms_state_ci.minSampleShading = 1.0;
10685 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010686
Tony Barboureb254902015-07-15 12:50:33 -060010687 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010688 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10689 pipeline_layout_ci.pNext = NULL;
10690 pipeline_layout_ci.setLayoutCount = 1;
10691 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010692
10693 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010694 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010695 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010696
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010697 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010698 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010699 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010700 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010701
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010702 VkPipelineObj pipe(m_device);
10703 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010704 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010705 pipe.SetMSAA(&pipe_ms_state_ci);
10706 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010707
Tony Barbour552f6c02016-12-21 14:34:07 -070010708 m_commandBuffer->BeginCommandBuffer();
10709 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010710
Karl Schultz6addd812016-02-02 17:17:23 -070010711 // Main thing we care about for this test is that the VkImage obj we're
10712 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010713 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010714 VkClearAttachment color_attachment;
10715 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10716 color_attachment.clearValue.color.float32[0] = 1.0;
10717 color_attachment.clearValue.color.float32[1] = 1.0;
10718 color_attachment.clearValue.color.float32[2] = 1.0;
10719 color_attachment.clearValue.color.float32[3] = 1.0;
10720 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010721 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010722
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010723 // Call for full-sized FB Color attachment prior to issuing a Draw
10724 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070010725 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010726 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010727 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010728
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010729 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10730 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10732 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10733 m_errorMonitor->VerifyFound();
10734
10735 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10736 clear_rect.layerCount = 2;
10737 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10738 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010739 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010740
Chia-I Wuf7458c52015-10-26 21:10:41 +080010741 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10742 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10743 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010744}
10745
Karl Schultz6addd812016-02-02 17:17:23 -070010746TEST_F(VkLayerTest, VtxBufferBadIndex) {
10747 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010748
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10750 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010751
Tobin Ehlis502480b2015-06-24 15:53:07 -060010752 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010753 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010755
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010756 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010757 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10758 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010759
10760 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010761 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10762 ds_pool_ci.pNext = NULL;
10763 ds_pool_ci.maxSets = 1;
10764 ds_pool_ci.poolSizeCount = 1;
10765 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010766
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010767 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010768 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010769 ASSERT_VK_SUCCESS(err);
10770
Tony Barboureb254902015-07-15 12:50:33 -060010771 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010772 dsl_binding.binding = 0;
10773 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10774 dsl_binding.descriptorCount = 1;
10775 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10776 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010777
Tony Barboureb254902015-07-15 12:50:33 -060010778 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010779 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10780 ds_layout_ci.pNext = NULL;
10781 ds_layout_ci.bindingCount = 1;
10782 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010783
Tobin Ehlis502480b2015-06-24 15:53:07 -060010784 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010785 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010786 ASSERT_VK_SUCCESS(err);
10787
10788 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010789 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010790 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010791 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010792 alloc_info.descriptorPool = ds_pool;
10793 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010794 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010795 ASSERT_VK_SUCCESS(err);
10796
Tony Barboureb254902015-07-15 12:50:33 -060010797 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010798 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010799 pipe_ms_state_ci.pNext = NULL;
10800 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10801 pipe_ms_state_ci.sampleShadingEnable = 0;
10802 pipe_ms_state_ci.minSampleShading = 1.0;
10803 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010804
Tony Barboureb254902015-07-15 12:50:33 -060010805 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010806 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10807 pipeline_layout_ci.pNext = NULL;
10808 pipeline_layout_ci.setLayoutCount = 1;
10809 pipeline_layout_ci.pSetLayouts = &ds_layout;
10810 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010811
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010812 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010813 ASSERT_VK_SUCCESS(err);
10814
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010815 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010816 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this); // We shouldn't need a fragment shader
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010817 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010818 VkPipelineObj pipe(m_device);
10819 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010820 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010821 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010822 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010823 pipe.SetViewport(m_viewports);
10824 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010825 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010826
Tony Barbour552f6c02016-12-21 14:34:07 -070010827 m_commandBuffer->BeginCommandBuffer();
10828 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010829 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010830 // Don't care about actual data, just need to get to draw to flag error
10831 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010832 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010833 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010834 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010835
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010836 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010837
Chia-I Wuf7458c52015-10-26 21:10:41 +080010838 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10839 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10840 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010841}
Mark Muellerdfe37552016-07-07 14:47:42 -060010842
Mark Mueller2ee294f2016-08-04 12:59:48 -060010843TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010844 TEST_DESCRIPTION(
10845 "Use an invalid count in a vkEnumeratePhysicalDevices call."
10846 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010847 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010848
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010849 const char *invalid_queueFamilyIndex_message =
10850 "Invalid queue create request in vkCreateDevice(). Invalid "
10851 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010852
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010853 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010854
Mark Mueller880fce52016-08-17 15:23:23 -060010855 // The following test fails with recent NVidia drivers.
10856 // By the time core_validation is reached, the NVidia
10857 // driver has sanitized the invalid condition and core_validation
10858 // is not introduced to the failure condition. This is not the case
10859 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010860 // uint32_t count = static_cast<uint32_t>(~0);
10861 // VkPhysicalDevice physical_device;
10862 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10863 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010864
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010866 float queue_priority = 0.0;
10867
10868 VkDeviceQueueCreateInfo queue_create_info = {};
10869 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10870 queue_create_info.queueCount = 1;
10871 queue_create_info.pQueuePriorities = &queue_priority;
10872 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10873
10874 VkPhysicalDeviceFeatures features = m_device->phy().features();
10875 VkDevice testDevice;
10876 VkDeviceCreateInfo device_create_info = {};
10877 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10878 device_create_info.queueCreateInfoCount = 1;
10879 device_create_info.pQueueCreateInfos = &queue_create_info;
10880 device_create_info.pEnabledFeatures = &features;
10881 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10882 m_errorMonitor->VerifyFound();
10883
10884 queue_create_info.queueFamilyIndex = 1;
10885
10886 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10887 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10888 for (unsigned i = 0; i < feature_count; i++) {
10889 if (VK_FALSE == feature_array[i]) {
10890 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010892 device_create_info.pEnabledFeatures = &features;
10893 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10894 m_errorMonitor->VerifyFound();
10895 break;
10896 }
10897 }
10898}
10899
Tobin Ehlis16edf082016-11-21 12:33:49 -070010900TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10901 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10902
10903 ASSERT_NO_FATAL_FAILURE(InitState());
10904
10905 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10906 std::vector<VkDeviceQueueCreateInfo> queue_info;
10907 queue_info.reserve(queue_props.size());
10908 std::vector<std::vector<float>> queue_priorities;
10909 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10910 VkDeviceQueueCreateInfo qi{};
10911 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10912 qi.queueFamilyIndex = i;
10913 qi.queueCount = queue_props[i].queueCount;
10914 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10915 qi.pQueuePriorities = queue_priorities[i].data();
10916 queue_info.push_back(qi);
10917 }
10918
10919 std::vector<const char *> device_extension_names;
10920
10921 VkDevice local_device;
10922 VkDeviceCreateInfo device_create_info = {};
10923 auto features = m_device->phy().features();
10924 // Intentionally disable pipeline stats
10925 features.pipelineStatisticsQuery = VK_FALSE;
10926 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10927 device_create_info.pNext = NULL;
10928 device_create_info.queueCreateInfoCount = queue_info.size();
10929 device_create_info.pQueueCreateInfos = queue_info.data();
10930 device_create_info.enabledLayerCount = 0;
10931 device_create_info.ppEnabledLayerNames = NULL;
10932 device_create_info.pEnabledFeatures = &features;
10933 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10934 ASSERT_VK_SUCCESS(err);
10935
10936 VkQueryPoolCreateInfo qpci{};
10937 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10938 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10939 qpci.queryCount = 1;
10940 VkQueryPool query_pool;
10941
10942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10943 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10944 m_errorMonitor->VerifyFound();
10945
10946 vkDestroyDevice(local_device, nullptr);
10947}
10948
Mark Mueller2ee294f2016-08-04 12:59:48 -060010949TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010950 TEST_DESCRIPTION(
10951 "Use an invalid queue index in a vkCmdWaitEvents call."
10952 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060010953
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010954 const char *invalid_queue_index =
10955 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10956 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10957 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010958
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010959 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010962
10963 ASSERT_NO_FATAL_FAILURE(InitState());
10964
10965 VkEvent event;
10966 VkEventCreateInfo event_create_info{};
10967 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10968 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10969
Mark Mueller2ee294f2016-08-04 12:59:48 -060010970 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010971 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010972
Tony Barbour552f6c02016-12-21 14:34:07 -070010973 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010974
10975 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010976 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 -060010977 ASSERT_TRUE(image.initialized());
10978 VkImageMemoryBarrier img_barrier = {};
10979 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10980 img_barrier.pNext = NULL;
10981 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10982 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10983 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10984 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10985 img_barrier.image = image.handle();
10986 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010987
10988 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10989 // that layer validation catches the case when it is not.
10990 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010991 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10992 img_barrier.subresourceRange.baseArrayLayer = 0;
10993 img_barrier.subresourceRange.baseMipLevel = 0;
10994 img_barrier.subresourceRange.layerCount = 1;
10995 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010996 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10997 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010998 m_errorMonitor->VerifyFound();
10999
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011001
11002 VkQueryPool query_pool;
11003 VkQueryPoolCreateInfo query_pool_create_info = {};
11004 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11005 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11006 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011007 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011008
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011009 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011010 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11011
11012 vkEndCommandBuffer(m_commandBuffer->handle());
11013 m_errorMonitor->VerifyFound();
11014
11015 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11016 vkDestroyEvent(m_device->device(), event, nullptr);
11017}
11018
Mark Muellerdfe37552016-07-07 14:47:42 -060011019TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011020 TEST_DESCRIPTION(
11021 "Submit a command buffer using deleted vertex buffer, "
11022 "delete a buffer twice, use an invalid offset for each "
11023 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011024
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011025 const char *deleted_buffer_in_command_buffer =
11026 "Cannot submit cmd buffer "
11027 "using deleted buffer ";
11028 const char *invalid_offset_message =
11029 "vkBindBufferMemory(): "
11030 "memoryOffset is 0x";
11031 const char *invalid_storage_buffer_offset_message =
11032 "vkBindBufferMemory(): "
11033 "storage memoryOffset "
11034 "is 0x";
11035 const char *invalid_texel_buffer_offset_message =
11036 "vkBindBufferMemory(): "
11037 "texel memoryOffset "
11038 "is 0x";
11039 const char *invalid_uniform_buffer_offset_message =
11040 "vkBindBufferMemory(): "
11041 "uniform memoryOffset "
11042 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011043
11044 ASSERT_NO_FATAL_FAILURE(InitState());
11045 ASSERT_NO_FATAL_FAILURE(InitViewport());
11046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11047
11048 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011049 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011050 pipe_ms_state_ci.pNext = NULL;
11051 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11052 pipe_ms_state_ci.sampleShadingEnable = 0;
11053 pipe_ms_state_ci.minSampleShading = 1.0;
11054 pipe_ms_state_ci.pSampleMask = nullptr;
11055
11056 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11057 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11058 VkPipelineLayout pipeline_layout;
11059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011060 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011061 ASSERT_VK_SUCCESS(err);
11062
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011063 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11064 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011065 VkPipelineObj pipe(m_device);
11066 pipe.AddShader(&vs);
11067 pipe.AddShader(&fs);
11068 pipe.AddColorAttachment();
11069 pipe.SetMSAA(&pipe_ms_state_ci);
11070 pipe.SetViewport(m_viewports);
11071 pipe.SetScissor(m_scissors);
11072 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11073
Tony Barbour552f6c02016-12-21 14:34:07 -070011074 m_commandBuffer->BeginCommandBuffer();
11075 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011076 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011077
11078 {
11079 // Create and bind a vertex buffer in a reduced scope, which will cause
11080 // it to be deleted upon leaving this scope
11081 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011082 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011083 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11084 draw_verticies.AddVertexInputToPipe(pipe);
11085 }
11086
11087 Draw(1, 0, 0, 0);
11088
Tony Barbour552f6c02016-12-21 14:34:07 -070011089 m_commandBuffer->EndRenderPass();
11090 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011091
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011093 QueueCommandBuffer(false);
11094 m_errorMonitor->VerifyFound();
11095
11096 {
11097 // Create and bind a vertex buffer in a reduced scope, and delete it
11098 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011099 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011101 buffer_test.TestDoubleDestroy();
11102 }
11103 m_errorMonitor->VerifyFound();
11104
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011105 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011106 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
11108 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11109 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011110 m_errorMonitor->VerifyFound();
11111 }
11112
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011113 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11114 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011115 // Create and bind a memory buffer with an invalid offset again,
11116 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
11118 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11119 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011120 m_errorMonitor->VerifyFound();
11121 }
11122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011123 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011124 // Create and bind a memory buffer with an invalid offset again, but
11125 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
11127 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11128 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011129 m_errorMonitor->VerifyFound();
11130 }
11131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011132 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011133 // Create and bind a memory buffer with an invalid offset again, but
11134 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
11136 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11137 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011138 m_errorMonitor->VerifyFound();
11139 }
11140
11141 {
11142 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011144 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11145 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011146 m_errorMonitor->VerifyFound();
11147 }
11148
11149 {
11150 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011152 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11153 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011154 }
11155 m_errorMonitor->VerifyFound();
11156
11157 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11158}
11159
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011160// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11161TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011162 TEST_DESCRIPTION(
11163 "Hit all possible validation checks associated with the "
11164 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11165 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011166 // 3 in ValidateCmdBufImageLayouts
11167 // * -1 Attempt to submit cmd buf w/ deleted image
11168 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11169 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011170
11171 ASSERT_NO_FATAL_FAILURE(InitState());
11172 // Create src & dst images to use for copy operations
11173 VkImage src_image;
11174 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011175 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011176
11177 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11178 const int32_t tex_width = 32;
11179 const int32_t tex_height = 32;
11180
11181 VkImageCreateInfo image_create_info = {};
11182 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11183 image_create_info.pNext = NULL;
11184 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11185 image_create_info.format = tex_format;
11186 image_create_info.extent.width = tex_width;
11187 image_create_info.extent.height = tex_height;
11188 image_create_info.extent.depth = 1;
11189 image_create_info.mipLevels = 1;
11190 image_create_info.arrayLayers = 4;
11191 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11192 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11193 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011194 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011195 image_create_info.flags = 0;
11196
11197 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11198 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011199 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011200 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11201 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011202 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11203 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11204 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11205 ASSERT_VK_SUCCESS(err);
11206
11207 // Allocate memory
11208 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011209 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011210 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011211 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11212 mem_alloc.pNext = NULL;
11213 mem_alloc.allocationSize = 0;
11214 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011215
11216 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011217 mem_alloc.allocationSize = img_mem_reqs.size;
11218 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011219 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011220 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011221 ASSERT_VK_SUCCESS(err);
11222
11223 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011224 mem_alloc.allocationSize = img_mem_reqs.size;
11225 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011226 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011227 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011228 ASSERT_VK_SUCCESS(err);
11229
11230 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011231 mem_alloc.allocationSize = img_mem_reqs.size;
11232 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011233 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011234 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011235 ASSERT_VK_SUCCESS(err);
11236
11237 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11238 ASSERT_VK_SUCCESS(err);
11239 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11240 ASSERT_VK_SUCCESS(err);
11241 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11242 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011243
Tony Barbour552f6c02016-12-21 14:34:07 -070011244 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011245 VkImageCopy copy_region;
11246 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11247 copy_region.srcSubresource.mipLevel = 0;
11248 copy_region.srcSubresource.baseArrayLayer = 0;
11249 copy_region.srcSubresource.layerCount = 1;
11250 copy_region.srcOffset.x = 0;
11251 copy_region.srcOffset.y = 0;
11252 copy_region.srcOffset.z = 0;
11253 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11254 copy_region.dstSubresource.mipLevel = 0;
11255 copy_region.dstSubresource.baseArrayLayer = 0;
11256 copy_region.dstSubresource.layerCount = 1;
11257 copy_region.dstOffset.x = 0;
11258 copy_region.dstOffset.y = 0;
11259 copy_region.dstOffset.z = 0;
11260 copy_region.extent.width = 1;
11261 copy_region.extent.height = 1;
11262 copy_region.extent.depth = 1;
11263
11264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11265 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
11266 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 -060011267 m_errorMonitor->VerifyFound();
11268 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11270 "Cannot copy from an image whose source layout is "
11271 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11272 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011273 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 -060011274 m_errorMonitor->VerifyFound();
11275 // Final src error is due to bad layout type
11276 m_errorMonitor->SetDesiredFailureMsg(
11277 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11278 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011279 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 -060011280 m_errorMonitor->VerifyFound();
11281 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011282 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11283 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011284 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 -060011285 m_errorMonitor->VerifyFound();
11286 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11288 "Cannot copy from an image whose dest layout is "
11289 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11290 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011291 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 -060011292 m_errorMonitor->VerifyFound();
11293 m_errorMonitor->SetDesiredFailureMsg(
11294 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11295 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011296 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 -060011297 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011298
Cort3b021012016-12-07 12:00:57 -080011299 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11300 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11301 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11302 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11303 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11304 transfer_dst_image_barrier[0].srcAccessMask = 0;
11305 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11306 transfer_dst_image_barrier[0].image = dst_image;
11307 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11308 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11309 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11310 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11311 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11312 transfer_dst_image_barrier[0].image = depth_image;
11313 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11314 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11315 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11316
11317 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011318 VkClearColorValue color_clear_value = {};
11319 VkImageSubresourceRange clear_range;
11320 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11321 clear_range.baseMipLevel = 0;
11322 clear_range.baseArrayLayer = 0;
11323 clear_range.layerCount = 1;
11324 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011325
Cort3b021012016-12-07 12:00:57 -080011326 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11327 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011330 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011331 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011332 // Fail due to provided layout not matching actual current layout for color clear.
11333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011334 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011335 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011336
Cort530cf382016-12-08 09:59:47 -080011337 VkClearDepthStencilValue depth_clear_value = {};
11338 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011339
11340 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11341 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11342 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011344 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011345 m_errorMonitor->VerifyFound();
11346 // Fail due to provided layout not matching actual current layout for depth clear.
11347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011348 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011349 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011350
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011351 // Now cause error due to bad image layout transition in PipelineBarrier
11352 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011353 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011354 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011355 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011356 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011357 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11358 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011359 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11361 "You cannot transition the layout of aspect 1 from "
11362 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11363 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011364 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11365 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011366 m_errorMonitor->VerifyFound();
11367
11368 // Finally some layout errors at RenderPass create time
11369 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11370 VkAttachmentReference attach = {};
11371 // perf warning for GENERAL layout w/ non-DS input attachment
11372 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11373 VkSubpassDescription subpass = {};
11374 subpass.inputAttachmentCount = 1;
11375 subpass.pInputAttachments = &attach;
11376 VkRenderPassCreateInfo rpci = {};
11377 rpci.subpassCount = 1;
11378 rpci.pSubpasses = &subpass;
11379 rpci.attachmentCount = 1;
11380 VkAttachmentDescription attach_desc = {};
11381 attach_desc.format = VK_FORMAT_UNDEFINED;
11382 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011383 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011384 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11386 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011387 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11388 m_errorMonitor->VerifyFound();
11389 // error w/ non-general layout
11390 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11391
11392 m_errorMonitor->SetDesiredFailureMsg(
11393 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11394 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11395 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11396 m_errorMonitor->VerifyFound();
11397 subpass.inputAttachmentCount = 0;
11398 subpass.colorAttachmentCount = 1;
11399 subpass.pColorAttachments = &attach;
11400 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11401 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11403 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011404 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11405 m_errorMonitor->VerifyFound();
11406 // error w/ non-color opt or GENERAL layout for color attachment
11407 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11408 m_errorMonitor->SetDesiredFailureMsg(
11409 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11410 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11411 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11412 m_errorMonitor->VerifyFound();
11413 subpass.colorAttachmentCount = 0;
11414 subpass.pDepthStencilAttachment = &attach;
11415 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11416 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11418 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011419 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11420 m_errorMonitor->VerifyFound();
11421 // error w/ non-ds opt or GENERAL layout for color attachment
11422 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11424 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11425 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011426 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11427 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011428 // For this error we need a valid renderpass so create default one
11429 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11430 attach.attachment = 0;
11431 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11432 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11433 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11434 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11435 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11436 // Can't do a CLEAR load on READ_ONLY initialLayout
11437 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11438 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11439 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11441 " with invalid first layout "
11442 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11443 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011444 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11445 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011446
Cort3b021012016-12-07 12:00:57 -080011447 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11448 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11449 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011450 vkDestroyImage(m_device->device(), src_image, NULL);
11451 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011452 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011453}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011454
Tobin Ehlise0936662016-10-11 08:10:51 -060011455TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11456 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11457 VkResult err;
11458
11459 ASSERT_NO_FATAL_FAILURE(InitState());
11460
11461 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11462 VkImageTiling tiling;
11463 VkFormatProperties format_properties;
11464 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11465 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11466 tiling = VK_IMAGE_TILING_LINEAR;
11467 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11468 tiling = VK_IMAGE_TILING_OPTIMAL;
11469 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011470 printf(
11471 "Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11472 "skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011473 return;
11474 }
11475
11476 VkDescriptorPoolSize ds_type = {};
11477 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11478 ds_type.descriptorCount = 1;
11479
11480 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11481 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11482 ds_pool_ci.maxSets = 1;
11483 ds_pool_ci.poolSizeCount = 1;
11484 ds_pool_ci.pPoolSizes = &ds_type;
11485 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11486
11487 VkDescriptorPool ds_pool;
11488 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11489 ASSERT_VK_SUCCESS(err);
11490
11491 VkDescriptorSetLayoutBinding dsl_binding = {};
11492 dsl_binding.binding = 0;
11493 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11494 dsl_binding.descriptorCount = 1;
11495 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11496 dsl_binding.pImmutableSamplers = NULL;
11497
11498 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11499 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11500 ds_layout_ci.pNext = NULL;
11501 ds_layout_ci.bindingCount = 1;
11502 ds_layout_ci.pBindings = &dsl_binding;
11503
11504 VkDescriptorSetLayout ds_layout;
11505 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11506 ASSERT_VK_SUCCESS(err);
11507
11508 VkDescriptorSetAllocateInfo alloc_info = {};
11509 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11510 alloc_info.descriptorSetCount = 1;
11511 alloc_info.descriptorPool = ds_pool;
11512 alloc_info.pSetLayouts = &ds_layout;
11513 VkDescriptorSet descriptor_set;
11514 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11515 ASSERT_VK_SUCCESS(err);
11516
11517 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11518 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11519 pipeline_layout_ci.pNext = NULL;
11520 pipeline_layout_ci.setLayoutCount = 1;
11521 pipeline_layout_ci.pSetLayouts = &ds_layout;
11522 VkPipelineLayout pipeline_layout;
11523 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11524 ASSERT_VK_SUCCESS(err);
11525
11526 VkImageObj image(m_device);
11527 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11528 ASSERT_TRUE(image.initialized());
11529 VkImageView view = image.targetView(tex_format);
11530
11531 VkDescriptorImageInfo image_info = {};
11532 image_info.imageView = view;
11533 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11534
11535 VkWriteDescriptorSet descriptor_write = {};
11536 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11537 descriptor_write.dstSet = descriptor_set;
11538 descriptor_write.dstBinding = 0;
11539 descriptor_write.descriptorCount = 1;
11540 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11541 descriptor_write.pImageInfo = &image_info;
11542
11543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11544 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11545 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11546 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11547 m_errorMonitor->VerifyFound();
11548
11549 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11550 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11551 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11552 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11553}
11554
Mark Mueller93b938f2016-08-18 10:27:40 -060011555TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011556 TEST_DESCRIPTION(
11557 "Use vkCmdExecuteCommands with invalid state "
11558 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011559
11560 ASSERT_NO_FATAL_FAILURE(InitState());
11561 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11562
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011563 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011564 const char *simultaneous_use_message2 =
11565 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11566 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011567
11568 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011569 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011570 command_buffer_allocate_info.commandPool = m_commandPool;
11571 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11572 command_buffer_allocate_info.commandBufferCount = 1;
11573
11574 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011575 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011576 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11577 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011578 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011579 command_buffer_inheritance_info.renderPass = m_renderPass;
11580 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011581
Mark Mueller93b938f2016-08-18 10:27:40 -060011582 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011583 command_buffer_begin_info.flags =
11584 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011585 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11586
11587 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11588 vkEndCommandBuffer(secondary_command_buffer);
11589
Mark Mueller93b938f2016-08-18 10:27:40 -060011590 VkSubmitInfo submit_info = {};
11591 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11592 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011593 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011594
Mark Mueller4042b652016-09-05 22:52:21 -060011595 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011596 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11597 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11598 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011599 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011600 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011601 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11602 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011603
Dave Houltonfbf52152017-01-06 12:55:29 -070011604 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011605 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011606 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011607
Mark Mueller4042b652016-09-05 22:52:21 -060011608 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011609 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011610 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011611
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11613 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011614 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011615 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11616 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011617
11618 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011619}
11620
Tobin Ehlisb093da82017-01-19 12:05:27 -070011621TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011622 TEST_DESCRIPTION(
11623 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11624 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070011625
11626 ASSERT_NO_FATAL_FAILURE(InitState());
11627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11628
11629 std::vector<const char *> device_extension_names;
11630 auto features = m_device->phy().features();
11631 // Make sure gs & ts are disabled
11632 features.geometryShader = false;
11633 features.tessellationShader = false;
11634 // The sacrificial device object
11635 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11636
11637 VkCommandPoolCreateInfo pool_create_info{};
11638 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11639 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11640
11641 VkCommandPool command_pool;
11642 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11643
11644 VkCommandBufferAllocateInfo cmd = {};
11645 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11646 cmd.pNext = NULL;
11647 cmd.commandPool = command_pool;
11648 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11649 cmd.commandBufferCount = 1;
11650
11651 VkCommandBuffer cmd_buffer;
11652 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11653 ASSERT_VK_SUCCESS(err);
11654
11655 VkEvent event;
11656 VkEventCreateInfo evci = {};
11657 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11658 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11659 ASSERT_VK_SUCCESS(result);
11660
11661 VkCommandBufferBeginInfo cbbi = {};
11662 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11663 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11665 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11666 m_errorMonitor->VerifyFound();
11667
11668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11669 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11670 m_errorMonitor->VerifyFound();
11671
11672 vkDestroyEvent(test_device.handle(), event, NULL);
11673 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11674}
11675
Mark Mueller917f6bc2016-08-30 10:57:19 -060011676TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011677 TEST_DESCRIPTION(
11678 "Use vkCmdExecuteCommands with invalid state "
11679 "in primary and secondary command buffers. "
11680 "Delete objects that are inuse. Call VkQueueSubmit "
11681 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011682
11683 ASSERT_NO_FATAL_FAILURE(InitState());
11684 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11685
Tony Barbour552f6c02016-12-21 14:34:07 -070011686 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011687
11688 VkEvent event;
11689 VkEventCreateInfo event_create_info = {};
11690 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11691 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011692 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011693
Tony Barbour552f6c02016-12-21 14:34:07 -070011694 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011695 vkDestroyEvent(m_device->device(), event, nullptr);
11696
11697 VkSubmitInfo submit_info = {};
11698 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11699 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011700 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070011701 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
11702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You are submitting command buffer 0x");
Mark Muellerc8d441e2016-08-23 17:36:00 -060011703 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11704 m_errorMonitor->VerifyFound();
11705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011706 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011707 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11708
11709 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11710
Mark Mueller917f6bc2016-08-30 10:57:19 -060011711 VkSemaphoreCreateInfo semaphore_create_info = {};
11712 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11713 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011714 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011715 VkFenceCreateInfo fence_create_info = {};
11716 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11717 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011718 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011719
11720 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011721 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011722 descriptor_pool_type_count.descriptorCount = 1;
11723
11724 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11725 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11726 descriptor_pool_create_info.maxSets = 1;
11727 descriptor_pool_create_info.poolSizeCount = 1;
11728 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011729 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011730
11731 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011732 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011733
11734 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011735 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011736 descriptorset_layout_binding.descriptorCount = 1;
11737 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11738
11739 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011740 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011741 descriptorset_layout_create_info.bindingCount = 1;
11742 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11743
11744 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011745 ASSERT_VK_SUCCESS(
11746 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011747
11748 VkDescriptorSet descriptorset;
11749 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011750 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011751 descriptorset_allocate_info.descriptorSetCount = 1;
11752 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11753 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011754 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011755
Mark Mueller4042b652016-09-05 22:52:21 -060011756 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11757
11758 VkDescriptorBufferInfo buffer_info = {};
11759 buffer_info.buffer = buffer_test.GetBuffer();
11760 buffer_info.offset = 0;
11761 buffer_info.range = 1024;
11762
11763 VkWriteDescriptorSet write_descriptor_set = {};
11764 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11765 write_descriptor_set.dstSet = descriptorset;
11766 write_descriptor_set.descriptorCount = 1;
11767 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11768 write_descriptor_set.pBufferInfo = &buffer_info;
11769
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011770 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011771
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011772 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11773 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011774
11775 VkPipelineObj pipe(m_device);
11776 pipe.AddColorAttachment();
11777 pipe.AddShader(&vs);
11778 pipe.AddShader(&fs);
11779
11780 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011781 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011782 pipeline_layout_create_info.setLayoutCount = 1;
11783 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11784
11785 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011786 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011787
11788 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11789
Tony Barbour552f6c02016-12-21 14:34:07 -070011790 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011791 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011792
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011793 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11794 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11795 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011796
Tony Barbour552f6c02016-12-21 14:34:07 -070011797 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011798
Mark Mueller917f6bc2016-08-30 10:57:19 -060011799 submit_info.signalSemaphoreCount = 1;
11800 submit_info.pSignalSemaphores = &semaphore;
11801 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011802 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011803
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011804 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011805 vkDestroyEvent(m_device->device(), event, nullptr);
11806 m_errorMonitor->VerifyFound();
11807
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011809 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11810 m_errorMonitor->VerifyFound();
11811
Jeremy Hayes08369882017-02-02 10:31:06 -070011812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011813 vkDestroyFence(m_device->device(), fence, nullptr);
11814 m_errorMonitor->VerifyFound();
11815
Tobin Ehlis122207b2016-09-01 08:50:06 -070011816 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011817 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11818 vkDestroyFence(m_device->device(), fence, nullptr);
11819 vkDestroyEvent(m_device->device(), event, nullptr);
11820 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011821 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011822 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11823}
11824
Tobin Ehlis2adda372016-09-01 08:51:06 -070011825TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11826 TEST_DESCRIPTION("Delete in-use query pool.");
11827
11828 ASSERT_NO_FATAL_FAILURE(InitState());
11829 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11830
11831 VkQueryPool query_pool;
11832 VkQueryPoolCreateInfo query_pool_ci{};
11833 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11834 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11835 query_pool_ci.queryCount = 1;
11836 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011837 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011838 // Reset query pool to create binding with cmd buffer
11839 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11840
Tony Barbour552f6c02016-12-21 14:34:07 -070011841 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011842
11843 VkSubmitInfo submit_info = {};
11844 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11845 submit_info.commandBufferCount = 1;
11846 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11847 // Submit cmd buffer and then destroy query pool while in-flight
11848 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11849
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011851 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11852 m_errorMonitor->VerifyFound();
11853
11854 vkQueueWaitIdle(m_device->m_queue);
11855 // Now that cmd buffer done we can safely destroy query_pool
11856 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11857}
11858
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011859TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11860 TEST_DESCRIPTION("Delete in-use pipeline.");
11861
11862 ASSERT_NO_FATAL_FAILURE(InitState());
11863 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11864
11865 // Empty pipeline layout used for binding PSO
11866 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11867 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11868 pipeline_layout_ci.setLayoutCount = 0;
11869 pipeline_layout_ci.pSetLayouts = NULL;
11870
11871 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011872 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011873 ASSERT_VK_SUCCESS(err);
11874
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011876 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011877 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11878 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011879 // Store pipeline handle so we can actually delete it before test finishes
11880 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011881 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011882 VkPipelineObj pipe(m_device);
11883 pipe.AddShader(&vs);
11884 pipe.AddShader(&fs);
11885 pipe.AddColorAttachment();
11886 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11887 delete_this_pipeline = pipe.handle();
11888
Tony Barbour552f6c02016-12-21 14:34:07 -070011889 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011890 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011891 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011892
Tony Barbour552f6c02016-12-21 14:34:07 -070011893 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011894
11895 VkSubmitInfo submit_info = {};
11896 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11897 submit_info.commandBufferCount = 1;
11898 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11899 // Submit cmd buffer and then pipeline destroyed while in-flight
11900 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011901 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011902 m_errorMonitor->VerifyFound();
11903 // Make sure queue finished and then actually delete pipeline
11904 vkQueueWaitIdle(m_device->m_queue);
11905 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11906 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11907}
11908
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011909TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11910 TEST_DESCRIPTION("Delete in-use imageView.");
11911
11912 ASSERT_NO_FATAL_FAILURE(InitState());
11913 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11914
11915 VkDescriptorPoolSize ds_type_count;
11916 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11917 ds_type_count.descriptorCount = 1;
11918
11919 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11920 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11921 ds_pool_ci.maxSets = 1;
11922 ds_pool_ci.poolSizeCount = 1;
11923 ds_pool_ci.pPoolSizes = &ds_type_count;
11924
11925 VkDescriptorPool ds_pool;
11926 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11927 ASSERT_VK_SUCCESS(err);
11928
11929 VkSamplerCreateInfo sampler_ci = {};
11930 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11931 sampler_ci.pNext = NULL;
11932 sampler_ci.magFilter = VK_FILTER_NEAREST;
11933 sampler_ci.minFilter = VK_FILTER_NEAREST;
11934 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11935 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11936 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11937 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11938 sampler_ci.mipLodBias = 1.0;
11939 sampler_ci.anisotropyEnable = VK_FALSE;
11940 sampler_ci.maxAnisotropy = 1;
11941 sampler_ci.compareEnable = VK_FALSE;
11942 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11943 sampler_ci.minLod = 1.0;
11944 sampler_ci.maxLod = 1.0;
11945 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11946 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11947 VkSampler sampler;
11948
11949 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11950 ASSERT_VK_SUCCESS(err);
11951
11952 VkDescriptorSetLayoutBinding layout_binding;
11953 layout_binding.binding = 0;
11954 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11955 layout_binding.descriptorCount = 1;
11956 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11957 layout_binding.pImmutableSamplers = NULL;
11958
11959 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11960 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11961 ds_layout_ci.bindingCount = 1;
11962 ds_layout_ci.pBindings = &layout_binding;
11963 VkDescriptorSetLayout ds_layout;
11964 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11965 ASSERT_VK_SUCCESS(err);
11966
11967 VkDescriptorSetAllocateInfo alloc_info = {};
11968 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11969 alloc_info.descriptorSetCount = 1;
11970 alloc_info.descriptorPool = ds_pool;
11971 alloc_info.pSetLayouts = &ds_layout;
11972 VkDescriptorSet descriptor_set;
11973 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11974 ASSERT_VK_SUCCESS(err);
11975
11976 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11977 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11978 pipeline_layout_ci.pNext = NULL;
11979 pipeline_layout_ci.setLayoutCount = 1;
11980 pipeline_layout_ci.pSetLayouts = &ds_layout;
11981
11982 VkPipelineLayout pipeline_layout;
11983 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11984 ASSERT_VK_SUCCESS(err);
11985
11986 VkImageObj image(m_device);
11987 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11988 ASSERT_TRUE(image.initialized());
11989
11990 VkImageView view;
11991 VkImageViewCreateInfo ivci = {};
11992 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11993 ivci.image = image.handle();
11994 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11995 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11996 ivci.subresourceRange.layerCount = 1;
11997 ivci.subresourceRange.baseMipLevel = 0;
11998 ivci.subresourceRange.levelCount = 1;
11999 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12000
12001 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12002 ASSERT_VK_SUCCESS(err);
12003
12004 VkDescriptorImageInfo image_info{};
12005 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12006 image_info.imageView = view;
12007 image_info.sampler = sampler;
12008
12009 VkWriteDescriptorSet descriptor_write = {};
12010 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12011 descriptor_write.dstSet = descriptor_set;
12012 descriptor_write.dstBinding = 0;
12013 descriptor_write.descriptorCount = 1;
12014 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12015 descriptor_write.pImageInfo = &image_info;
12016
12017 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12018
12019 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012020 char const *vsSource =
12021 "#version 450\n"
12022 "\n"
12023 "out gl_PerVertex { \n"
12024 " vec4 gl_Position;\n"
12025 "};\n"
12026 "void main(){\n"
12027 " gl_Position = vec4(1);\n"
12028 "}\n";
12029 char const *fsSource =
12030 "#version 450\n"
12031 "\n"
12032 "layout(set=0, binding=0) uniform sampler2D s;\n"
12033 "layout(location=0) out vec4 x;\n"
12034 "void main(){\n"
12035 " x = texture(s, vec2(1));\n"
12036 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12039 VkPipelineObj pipe(m_device);
12040 pipe.AddShader(&vs);
12041 pipe.AddShader(&fs);
12042 pipe.AddColorAttachment();
12043 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12044
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012045 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012046
Tony Barbour552f6c02016-12-21 14:34:07 -070012047 m_commandBuffer->BeginCommandBuffer();
12048 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012049 // Bind pipeline to cmd buffer
12050 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12051 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12052 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012053
12054 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12055 VkRect2D scissor = {{0, 0}, {16, 16}};
12056 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12057 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12058
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012059 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012060 m_commandBuffer->EndRenderPass();
12061 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012062 // Submit cmd buffer then destroy sampler
12063 VkSubmitInfo submit_info = {};
12064 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12065 submit_info.commandBufferCount = 1;
12066 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12067 // Submit cmd buffer and then destroy imageView while in-flight
12068 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12069
12070 vkDestroyImageView(m_device->device(), view, nullptr);
12071 m_errorMonitor->VerifyFound();
12072 vkQueueWaitIdle(m_device->m_queue);
12073 // Now we can actually destroy imageView
12074 vkDestroyImageView(m_device->device(), view, NULL);
12075 vkDestroySampler(m_device->device(), sampler, nullptr);
12076 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12077 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12078 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12079}
12080
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012081TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12082 TEST_DESCRIPTION("Delete in-use bufferView.");
12083
12084 ASSERT_NO_FATAL_FAILURE(InitState());
12085 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12086
12087 VkDescriptorPoolSize ds_type_count;
12088 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12089 ds_type_count.descriptorCount = 1;
12090
12091 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12092 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12093 ds_pool_ci.maxSets = 1;
12094 ds_pool_ci.poolSizeCount = 1;
12095 ds_pool_ci.pPoolSizes = &ds_type_count;
12096
12097 VkDescriptorPool ds_pool;
12098 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12099 ASSERT_VK_SUCCESS(err);
12100
12101 VkDescriptorSetLayoutBinding layout_binding;
12102 layout_binding.binding = 0;
12103 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12104 layout_binding.descriptorCount = 1;
12105 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12106 layout_binding.pImmutableSamplers = NULL;
12107
12108 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12109 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12110 ds_layout_ci.bindingCount = 1;
12111 ds_layout_ci.pBindings = &layout_binding;
12112 VkDescriptorSetLayout ds_layout;
12113 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12114 ASSERT_VK_SUCCESS(err);
12115
12116 VkDescriptorSetAllocateInfo alloc_info = {};
12117 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12118 alloc_info.descriptorSetCount = 1;
12119 alloc_info.descriptorPool = ds_pool;
12120 alloc_info.pSetLayouts = &ds_layout;
12121 VkDescriptorSet descriptor_set;
12122 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12123 ASSERT_VK_SUCCESS(err);
12124
12125 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12126 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12127 pipeline_layout_ci.pNext = NULL;
12128 pipeline_layout_ci.setLayoutCount = 1;
12129 pipeline_layout_ci.pSetLayouts = &ds_layout;
12130
12131 VkPipelineLayout pipeline_layout;
12132 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12133 ASSERT_VK_SUCCESS(err);
12134
12135 VkBuffer buffer;
12136 uint32_t queue_family_index = 0;
12137 VkBufferCreateInfo buffer_create_info = {};
12138 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12139 buffer_create_info.size = 1024;
12140 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12141 buffer_create_info.queueFamilyIndexCount = 1;
12142 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12143
12144 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12145 ASSERT_VK_SUCCESS(err);
12146
12147 VkMemoryRequirements memory_reqs;
12148 VkDeviceMemory buffer_memory;
12149
12150 VkMemoryAllocateInfo memory_info = {};
12151 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12152 memory_info.allocationSize = 0;
12153 memory_info.memoryTypeIndex = 0;
12154
12155 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12156 memory_info.allocationSize = memory_reqs.size;
12157 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12158 ASSERT_TRUE(pass);
12159
12160 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12161 ASSERT_VK_SUCCESS(err);
12162 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12163 ASSERT_VK_SUCCESS(err);
12164
12165 VkBufferView view;
12166 VkBufferViewCreateInfo bvci = {};
12167 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12168 bvci.buffer = buffer;
12169 bvci.format = VK_FORMAT_R8_UNORM;
12170 bvci.range = VK_WHOLE_SIZE;
12171
12172 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12173 ASSERT_VK_SUCCESS(err);
12174
12175 VkWriteDescriptorSet descriptor_write = {};
12176 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12177 descriptor_write.dstSet = descriptor_set;
12178 descriptor_write.dstBinding = 0;
12179 descriptor_write.descriptorCount = 1;
12180 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12181 descriptor_write.pTexelBufferView = &view;
12182
12183 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12184
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012185 char const *vsSource =
12186 "#version 450\n"
12187 "\n"
12188 "out gl_PerVertex { \n"
12189 " vec4 gl_Position;\n"
12190 "};\n"
12191 "void main(){\n"
12192 " gl_Position = vec4(1);\n"
12193 "}\n";
12194 char const *fsSource =
12195 "#version 450\n"
12196 "\n"
12197 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12198 "layout(location=0) out vec4 x;\n"
12199 "void main(){\n"
12200 " x = imageLoad(s, 0);\n"
12201 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012202 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12203 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12204 VkPipelineObj pipe(m_device);
12205 pipe.AddShader(&vs);
12206 pipe.AddShader(&fs);
12207 pipe.AddColorAttachment();
12208 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12209
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012211
Tony Barbour552f6c02016-12-21 14:34:07 -070012212 m_commandBuffer->BeginCommandBuffer();
12213 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012214 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12215 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12216 VkRect2D scissor = {{0, 0}, {16, 16}};
12217 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12218 // Bind pipeline to cmd buffer
12219 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12220 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12221 &descriptor_set, 0, nullptr);
12222 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012223 m_commandBuffer->EndRenderPass();
12224 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012225
12226 VkSubmitInfo submit_info = {};
12227 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12228 submit_info.commandBufferCount = 1;
12229 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12230 // Submit cmd buffer and then destroy bufferView while in-flight
12231 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12232
12233 vkDestroyBufferView(m_device->device(), view, nullptr);
12234 m_errorMonitor->VerifyFound();
12235 vkQueueWaitIdle(m_device->m_queue);
12236 // Now we can actually destroy bufferView
12237 vkDestroyBufferView(m_device->device(), view, NULL);
12238 vkDestroyBuffer(m_device->device(), buffer, NULL);
12239 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12240 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12241 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12242 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12243}
12244
Tobin Ehlis209532e2016-09-07 13:52:18 -060012245TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12246 TEST_DESCRIPTION("Delete in-use sampler.");
12247
12248 ASSERT_NO_FATAL_FAILURE(InitState());
12249 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12250
12251 VkDescriptorPoolSize ds_type_count;
12252 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12253 ds_type_count.descriptorCount = 1;
12254
12255 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12256 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12257 ds_pool_ci.maxSets = 1;
12258 ds_pool_ci.poolSizeCount = 1;
12259 ds_pool_ci.pPoolSizes = &ds_type_count;
12260
12261 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012262 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012263 ASSERT_VK_SUCCESS(err);
12264
12265 VkSamplerCreateInfo sampler_ci = {};
12266 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12267 sampler_ci.pNext = NULL;
12268 sampler_ci.magFilter = VK_FILTER_NEAREST;
12269 sampler_ci.minFilter = VK_FILTER_NEAREST;
12270 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12271 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12272 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12273 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12274 sampler_ci.mipLodBias = 1.0;
12275 sampler_ci.anisotropyEnable = VK_FALSE;
12276 sampler_ci.maxAnisotropy = 1;
12277 sampler_ci.compareEnable = VK_FALSE;
12278 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12279 sampler_ci.minLod = 1.0;
12280 sampler_ci.maxLod = 1.0;
12281 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12282 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12283 VkSampler sampler;
12284
12285 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12286 ASSERT_VK_SUCCESS(err);
12287
12288 VkDescriptorSetLayoutBinding layout_binding;
12289 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012290 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012291 layout_binding.descriptorCount = 1;
12292 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12293 layout_binding.pImmutableSamplers = NULL;
12294
12295 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12296 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12297 ds_layout_ci.bindingCount = 1;
12298 ds_layout_ci.pBindings = &layout_binding;
12299 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012300 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012301 ASSERT_VK_SUCCESS(err);
12302
12303 VkDescriptorSetAllocateInfo alloc_info = {};
12304 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12305 alloc_info.descriptorSetCount = 1;
12306 alloc_info.descriptorPool = ds_pool;
12307 alloc_info.pSetLayouts = &ds_layout;
12308 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012309 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012310 ASSERT_VK_SUCCESS(err);
12311
12312 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12313 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12314 pipeline_layout_ci.pNext = NULL;
12315 pipeline_layout_ci.setLayoutCount = 1;
12316 pipeline_layout_ci.pSetLayouts = &ds_layout;
12317
12318 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012319 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012320 ASSERT_VK_SUCCESS(err);
12321
12322 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012323 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 -060012324 ASSERT_TRUE(image.initialized());
12325
12326 VkImageView view;
12327 VkImageViewCreateInfo ivci = {};
12328 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12329 ivci.image = image.handle();
12330 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12331 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12332 ivci.subresourceRange.layerCount = 1;
12333 ivci.subresourceRange.baseMipLevel = 0;
12334 ivci.subresourceRange.levelCount = 1;
12335 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12336
12337 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12338 ASSERT_VK_SUCCESS(err);
12339
12340 VkDescriptorImageInfo image_info{};
12341 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12342 image_info.imageView = view;
12343 image_info.sampler = sampler;
12344
12345 VkWriteDescriptorSet descriptor_write = {};
12346 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12347 descriptor_write.dstSet = descriptor_set;
12348 descriptor_write.dstBinding = 0;
12349 descriptor_write.descriptorCount = 1;
12350 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12351 descriptor_write.pImageInfo = &image_info;
12352
12353 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12354
12355 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012356 char const *vsSource =
12357 "#version 450\n"
12358 "\n"
12359 "out gl_PerVertex { \n"
12360 " vec4 gl_Position;\n"
12361 "};\n"
12362 "void main(){\n"
12363 " gl_Position = vec4(1);\n"
12364 "}\n";
12365 char const *fsSource =
12366 "#version 450\n"
12367 "\n"
12368 "layout(set=0, binding=0) uniform sampler2D s;\n"
12369 "layout(location=0) out vec4 x;\n"
12370 "void main(){\n"
12371 " x = texture(s, vec2(1));\n"
12372 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012373 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12374 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12375 VkPipelineObj pipe(m_device);
12376 pipe.AddShader(&vs);
12377 pipe.AddShader(&fs);
12378 pipe.AddColorAttachment();
12379 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12380
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012382
Tony Barbour552f6c02016-12-21 14:34:07 -070012383 m_commandBuffer->BeginCommandBuffer();
12384 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012385 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012386 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12387 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12388 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012389
12390 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12391 VkRect2D scissor = {{0, 0}, {16, 16}};
12392 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12393 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12394
Tobin Ehlis209532e2016-09-07 13:52:18 -060012395 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012396 m_commandBuffer->EndRenderPass();
12397 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012398 // Submit cmd buffer then destroy sampler
12399 VkSubmitInfo submit_info = {};
12400 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12401 submit_info.commandBufferCount = 1;
12402 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12403 // Submit cmd buffer and then destroy sampler while in-flight
12404 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12405
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012406 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012407 m_errorMonitor->VerifyFound();
12408 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012409
Tobin Ehlis209532e2016-09-07 13:52:18 -060012410 // Now we can actually destroy sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012411 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012412 vkDestroyImageView(m_device->device(), view, NULL);
12413 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12414 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12415 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12416}
12417
Mark Mueller1cd9f412016-08-25 13:23:52 -060012418TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012419 TEST_DESCRIPTION(
12420 "Call VkQueueSubmit with a semaphore that is already "
12421 "signaled but not waited on by the queue. Wait on a "
12422 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012423
12424 ASSERT_NO_FATAL_FAILURE(InitState());
12425 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12426
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012427 const char *queue_forward_progress_message = " that has already been signaled but not waited on by queue 0x";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012428 const char *invalid_fence_wait_message =
12429 " which has not been submitted on a Queue or during "
12430 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012431
Tony Barbour552f6c02016-12-21 14:34:07 -070012432 m_commandBuffer->BeginCommandBuffer();
12433 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012434
12435 VkSemaphoreCreateInfo semaphore_create_info = {};
12436 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12437 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012438 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012439 VkSubmitInfo submit_info = {};
12440 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12441 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012442 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012443 submit_info.signalSemaphoreCount = 1;
12444 submit_info.pSignalSemaphores = &semaphore;
12445 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012446 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012447 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012448 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012449 m_commandBuffer->BeginCommandBuffer();
12450 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012452 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12453 m_errorMonitor->VerifyFound();
12454
Mark Mueller1cd9f412016-08-25 13:23:52 -060012455 VkFenceCreateInfo fence_create_info = {};
12456 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12457 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012458 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012459
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012461 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12462 m_errorMonitor->VerifyFound();
12463
Mark Mueller4042b652016-09-05 22:52:21 -060012464 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012465 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012466 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12467}
12468
Tobin Ehlis4af23302016-07-19 10:50:30 -060012469TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012470 TEST_DESCRIPTION(
12471 "Bind a secondary command buffer with with a framebuffer "
12472 "that does not match the framebuffer for the active "
12473 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012474 ASSERT_NO_FATAL_FAILURE(InitState());
12475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12476
12477 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012478 VkAttachmentDescription attachment = {0,
12479 VK_FORMAT_B8G8R8A8_UNORM,
12480 VK_SAMPLE_COUNT_1_BIT,
12481 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12482 VK_ATTACHMENT_STORE_OP_STORE,
12483 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12484 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12485 VK_IMAGE_LAYOUT_UNDEFINED,
12486 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012487
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012488 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012490 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012492 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012493
12494 VkRenderPass rp;
12495 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12496 ASSERT_VK_SUCCESS(err);
12497
12498 // A compatible framebuffer.
12499 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012500 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 -060012501 ASSERT_TRUE(image.initialized());
12502
12503 VkImageViewCreateInfo ivci = {
12504 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12505 nullptr,
12506 0,
12507 image.handle(),
12508 VK_IMAGE_VIEW_TYPE_2D,
12509 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012510 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12511 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012512 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12513 };
12514 VkImageView view;
12515 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12516 ASSERT_VK_SUCCESS(err);
12517
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012518 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012519 VkFramebuffer fb;
12520 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12521 ASSERT_VK_SUCCESS(err);
12522
12523 VkCommandBufferAllocateInfo cbai = {};
12524 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12525 cbai.commandPool = m_commandPool;
12526 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12527 cbai.commandBufferCount = 1;
12528
12529 VkCommandBuffer sec_cb;
12530 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12531 ASSERT_VK_SUCCESS(err);
12532 VkCommandBufferBeginInfo cbbi = {};
12533 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012534 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012535 cbii.renderPass = renderPass();
12536 cbii.framebuffer = fb;
12537 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12538 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012539 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 -060012540 cbbi.pInheritanceInfo = &cbii;
12541 vkBeginCommandBuffer(sec_cb, &cbbi);
12542 vkEndCommandBuffer(sec_cb);
12543
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012544 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120012545 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12546 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012549 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012550 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12551 m_errorMonitor->VerifyFound();
12552 // Cleanup
12553 vkDestroyImageView(m_device->device(), view, NULL);
12554 vkDestroyRenderPass(m_device->device(), rp, NULL);
12555 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12556}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012557
12558TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012559 TEST_DESCRIPTION(
12560 "If logicOp is available on the device, set it to an "
12561 "invalid value. If logicOp is not available, attempt to "
12562 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012563 ASSERT_NO_FATAL_FAILURE(InitState());
12564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12565
12566 auto features = m_device->phy().features();
12567 // Set the expected error depending on whether or not logicOp available
12568 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12570 "If logic operations feature not "
12571 "enabled, logicOpEnable must be "
12572 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012573 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012575 }
12576 // Create a pipeline using logicOp
12577 VkResult err;
12578
12579 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12580 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12581
12582 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012583 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012584 ASSERT_VK_SUCCESS(err);
12585
12586 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12587 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12588 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012589 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012590 vp_state_ci.pViewports = &vp;
12591 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012592 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012593 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012594
12595 VkPipelineShaderStageCreateInfo shaderStages[2];
12596 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12597
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012598 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12599 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012600 shaderStages[0] = vs.GetStageCreateInfo();
12601 shaderStages[1] = fs.GetStageCreateInfo();
12602
12603 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12604 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12605
12606 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12607 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12608 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12609
12610 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12611 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012612 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012613
12614 VkPipelineColorBlendAttachmentState att = {};
12615 att.blendEnable = VK_FALSE;
12616 att.colorWriteMask = 0xf;
12617
12618 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12619 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12620 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12621 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012622 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012623 cb_ci.attachmentCount = 1;
12624 cb_ci.pAttachments = &att;
12625
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012626 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12627 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12628 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12629
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012630 VkGraphicsPipelineCreateInfo gp_ci = {};
12631 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12632 gp_ci.stageCount = 2;
12633 gp_ci.pStages = shaderStages;
12634 gp_ci.pVertexInputState = &vi_ci;
12635 gp_ci.pInputAssemblyState = &ia_ci;
12636 gp_ci.pViewportState = &vp_state_ci;
12637 gp_ci.pRasterizationState = &rs_ci;
12638 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012639 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012640 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12641 gp_ci.layout = pipeline_layout;
12642 gp_ci.renderPass = renderPass();
12643
12644 VkPipelineCacheCreateInfo pc_ci = {};
12645 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12646
12647 VkPipeline pipeline;
12648 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012649 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012650 ASSERT_VK_SUCCESS(err);
12651
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012652 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012653 m_errorMonitor->VerifyFound();
12654 if (VK_SUCCESS == err) {
12655 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12656 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012657 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12658 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12659}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012660
Mike Stroyanaccf7692015-05-12 16:00:45 -060012661#if GTEST_IS_THREADSAFE
12662struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012663 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012664 VkEvent event;
12665 bool bailout;
12666};
12667
Karl Schultz6addd812016-02-02 17:17:23 -070012668extern "C" void *AddToCommandBuffer(void *arg) {
12669 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012670
Mike Stroyana6d14942016-07-13 15:10:05 -060012671 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012672 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012673 if (data->bailout) {
12674 break;
12675 }
12676 }
12677 return NULL;
12678}
12679
Karl Schultz6addd812016-02-02 17:17:23 -070012680TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012681 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012682
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012684
Mike Stroyanaccf7692015-05-12 16:00:45 -060012685 ASSERT_NO_FATAL_FAILURE(InitState());
12686 ASSERT_NO_FATAL_FAILURE(InitViewport());
12687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12688
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012689 // Calls AllocateCommandBuffers
12690 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012691
12692 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012693 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012694
12695 VkEventCreateInfo event_info;
12696 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012697 VkResult err;
12698
12699 memset(&event_info, 0, sizeof(event_info));
12700 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12701
Chia-I Wuf7458c52015-10-26 21:10:41 +080012702 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012703 ASSERT_VK_SUCCESS(err);
12704
Mike Stroyanaccf7692015-05-12 16:00:45 -060012705 err = vkResetEvent(device(), event);
12706 ASSERT_VK_SUCCESS(err);
12707
12708 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012709 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012710 data.event = event;
12711 data.bailout = false;
12712 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012713
12714 // First do some correct operations using multiple threads.
12715 // Add many entries to command buffer from another thread.
12716 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12717 // Make non-conflicting calls from this thread at the same time.
12718 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012719 uint32_t count;
12720 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012721 }
12722 test_platform_thread_join(thread, NULL);
12723
12724 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012725 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012726 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012727 // Add many entries to command buffer from this thread at the same time.
12728 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012729
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012730 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012731 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012732
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012733 m_errorMonitor->SetBailout(NULL);
12734
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012735 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012736
Chia-I Wuf7458c52015-10-26 21:10:41 +080012737 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012738}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012739#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012740
Karl Schultz6addd812016-02-02 17:17:23 -070012741TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012742 TEST_DESCRIPTION(
12743 "Test that an error is produced for a spirv module "
12744 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120012745
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012747
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012748 ASSERT_NO_FATAL_FAILURE(InitState());
12749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12750
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012751 VkShaderModule module;
12752 VkShaderModuleCreateInfo moduleCreateInfo;
12753 struct icd_spv_header spv;
12754
12755 spv.magic = ICD_SPV_MAGIC;
12756 spv.version = ICD_SPV_VERSION;
12757 spv.gen_magic = 0;
12758
12759 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12760 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012761 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012762 moduleCreateInfo.codeSize = 4;
12763 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012764 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012765
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012766 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012767}
12768
Karl Schultz6addd812016-02-02 17:17:23 -070012769TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012770 TEST_DESCRIPTION(
12771 "Test that an error is produced for a spirv module "
12772 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120012773
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012775
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012776 ASSERT_NO_FATAL_FAILURE(InitState());
12777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12778
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012779 VkShaderModule module;
12780 VkShaderModuleCreateInfo moduleCreateInfo;
12781 struct icd_spv_header spv;
12782
12783 spv.magic = ~ICD_SPV_MAGIC;
12784 spv.version = ICD_SPV_VERSION;
12785 spv.gen_magic = 0;
12786
12787 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12788 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012789 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012790 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12791 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012792 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012793
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012794 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012795}
12796
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012797#if 0
12798// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012799TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012801 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012802
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012803 ASSERT_NO_FATAL_FAILURE(InitState());
12804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12805
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012806 VkShaderModule module;
12807 VkShaderModuleCreateInfo moduleCreateInfo;
12808 struct icd_spv_header spv;
12809
12810 spv.magic = ICD_SPV_MAGIC;
12811 spv.version = ~ICD_SPV_VERSION;
12812 spv.gen_magic = 0;
12813
12814 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12815 moduleCreateInfo.pNext = NULL;
12816
Karl Schultz6addd812016-02-02 17:17:23 -070012817 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012818 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12819 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012820 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012821
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012822 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012823}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012824#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012825
Karl Schultz6addd812016-02-02 17:17:23 -070012826TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012827 TEST_DESCRIPTION(
12828 "Test that a warning is produced for a vertex output that "
12829 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012831
Chris Forbes9f7ff632015-05-25 11:13:08 +120012832 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012834
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012835 char const *vsSource =
12836 "#version 450\n"
12837 "\n"
12838 "layout(location=0) out float x;\n"
12839 "out gl_PerVertex {\n"
12840 " vec4 gl_Position;\n"
12841 "};\n"
12842 "void main(){\n"
12843 " gl_Position = vec4(1);\n"
12844 " x = 0;\n"
12845 "}\n";
12846 char const *fsSource =
12847 "#version 450\n"
12848 "\n"
12849 "layout(location=0) out vec4 color;\n"
12850 "void main(){\n"
12851 " color = vec4(1);\n"
12852 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012853
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012854 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12855 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012856
12857 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012858 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012859 pipe.AddShader(&vs);
12860 pipe.AddShader(&fs);
12861
Chris Forbes9f7ff632015-05-25 11:13:08 +120012862 VkDescriptorSetObj descriptorSet(m_device);
12863 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012864 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012865
Tony Barbour5781e8f2015-08-04 16:23:11 -060012866 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012867
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012868 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012869}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012870
Mark Mueller098c9cb2016-09-08 09:01:57 -060012871TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12872 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12873
12874 ASSERT_NO_FATAL_FAILURE(InitState());
12875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12876
12877 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012878 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012879
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012880 char const *vsSource =
12881 "#version 450\n"
12882 "\n"
12883 "out gl_PerVertex {\n"
12884 " vec4 gl_Position;\n"
12885 "};\n"
12886 "void main(){\n"
12887 " gl_Position = vec4(1);\n"
12888 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012889
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012890 char const *fsSource =
12891 "#version 450\n"
12892 "\n"
12893 "layout (constant_id = 0) const float r = 0.0f;\n"
12894 "layout(location = 0) out vec4 uFragColor;\n"
12895 "void main(){\n"
12896 " uFragColor = vec4(r,1,0,1);\n"
12897 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012898
12899 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12900 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12901
12902 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12903 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12904
12905 VkPipelineLayout pipeline_layout;
12906 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12907
12908 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12909 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12910 vp_state_create_info.viewportCount = 1;
12911 VkViewport viewport = {};
12912 vp_state_create_info.pViewports = &viewport;
12913 vp_state_create_info.scissorCount = 1;
12914 VkRect2D scissors = {};
12915 vp_state_create_info.pScissors = &scissors;
12916
12917 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12918
12919 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12920 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12921 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12922 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12923
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012924 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060012925
12926 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12927 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12928
12929 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12930 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12931 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12932
12933 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12934 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12935 rasterization_state_create_info.pNext = nullptr;
12936 rasterization_state_create_info.lineWidth = 1.0f;
12937 rasterization_state_create_info.rasterizerDiscardEnable = true;
12938
12939 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12940 color_blend_attachment_state.blendEnable = VK_FALSE;
12941 color_blend_attachment_state.colorWriteMask = 0xf;
12942
12943 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12944 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12945 color_blend_state_create_info.attachmentCount = 1;
12946 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12947
12948 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12949 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12950 graphicspipe_create_info.stageCount = 2;
12951 graphicspipe_create_info.pStages = shader_stage_create_info;
12952 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12953 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12954 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12955 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12956 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12957 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12958 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12959 graphicspipe_create_info.layout = pipeline_layout;
12960 graphicspipe_create_info.renderPass = renderPass();
12961
12962 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12963 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12964
12965 VkPipelineCache pipelineCache;
12966 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12967
12968 // This structure maps constant ids to data locations.
12969 const VkSpecializationMapEntry entry =
12970 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012971 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060012972
12973 uint32_t data = 1;
12974
12975 // Set up the info describing spec map and data
12976 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012977 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060012978 };
12979 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12980
12981 VkPipeline pipeline;
12982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12983 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12984 m_errorMonitor->VerifyFound();
12985
12986 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12987 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12988}
12989
12990TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12991 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12992
12993 ASSERT_NO_FATAL_FAILURE(InitState());
12994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12995
12996 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12997
12998 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
12999 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13000 descriptor_pool_type_count[0].descriptorCount = 1;
13001 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13002 descriptor_pool_type_count[1].descriptorCount = 1;
13003
13004 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13005 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13006 descriptor_pool_create_info.maxSets = 1;
13007 descriptor_pool_create_info.poolSizeCount = 2;
13008 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13009 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13010
13011 VkDescriptorPool descriptorset_pool;
13012 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13013
13014 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13015 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13016 descriptorset_layout_binding.descriptorCount = 1;
13017 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13018
13019 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13020 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13021 descriptorset_layout_create_info.bindingCount = 1;
13022 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13023
13024 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013025 ASSERT_VK_SUCCESS(
13026 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013027
13028 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13029 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13030 descriptorset_allocate_info.descriptorSetCount = 1;
13031 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13032 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13033 VkDescriptorSet descriptorset;
13034 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13035
13036 // Challenge core_validation with a non uniform buffer type.
13037 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13038
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013039 char const *vsSource =
13040 "#version 450\n"
13041 "\n"
13042 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13043 " mat4 mvp;\n"
13044 "} ubuf;\n"
13045 "out gl_PerVertex {\n"
13046 " vec4 gl_Position;\n"
13047 "};\n"
13048 "void main(){\n"
13049 " gl_Position = ubuf.mvp * vec4(1);\n"
13050 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013051
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013052 char const *fsSource =
13053 "#version 450\n"
13054 "\n"
13055 "layout(location = 0) out vec4 uFragColor;\n"
13056 "void main(){\n"
13057 " uFragColor = vec4(0,1,0,1);\n"
13058 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013059
13060 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13061 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13062
13063 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13064 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13065 pipeline_layout_create_info.setLayoutCount = 1;
13066 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13067
13068 VkPipelineLayout pipeline_layout;
13069 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13070
13071 VkPipelineObj pipe(m_device);
13072 pipe.AddColorAttachment();
13073 pipe.AddShader(&vs);
13074 pipe.AddShader(&fs);
13075
13076 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13077 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13078 m_errorMonitor->VerifyFound();
13079
13080 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13081 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13082 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13083}
13084
13085TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13086 TEST_DESCRIPTION(
13087 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13088
13089 ASSERT_NO_FATAL_FAILURE(InitState());
13090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13091
13092 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13093
13094 VkDescriptorPoolSize descriptor_pool_type_count = {};
13095 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13096 descriptor_pool_type_count.descriptorCount = 1;
13097
13098 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13099 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13100 descriptor_pool_create_info.maxSets = 1;
13101 descriptor_pool_create_info.poolSizeCount = 1;
13102 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13103 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13104
13105 VkDescriptorPool descriptorset_pool;
13106 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13107
13108 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13109 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13110 descriptorset_layout_binding.descriptorCount = 1;
13111 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13112 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13113
13114 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13115 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13116 descriptorset_layout_create_info.bindingCount = 1;
13117 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13118
13119 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013120 ASSERT_VK_SUCCESS(
13121 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013122
13123 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13124 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13125 descriptorset_allocate_info.descriptorSetCount = 1;
13126 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13127 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13128 VkDescriptorSet descriptorset;
13129 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13130
13131 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13132
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013133 char const *vsSource =
13134 "#version 450\n"
13135 "\n"
13136 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13137 " mat4 mvp;\n"
13138 "} ubuf;\n"
13139 "out gl_PerVertex {\n"
13140 " vec4 gl_Position;\n"
13141 "};\n"
13142 "void main(){\n"
13143 " gl_Position = ubuf.mvp * vec4(1);\n"
13144 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013145
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013146 char const *fsSource =
13147 "#version 450\n"
13148 "\n"
13149 "layout(location = 0) out vec4 uFragColor;\n"
13150 "void main(){\n"
13151 " uFragColor = vec4(0,1,0,1);\n"
13152 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013153
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 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13158 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13159 pipeline_layout_create_info.setLayoutCount = 1;
13160 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13161
13162 VkPipelineLayout pipeline_layout;
13163 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13164
13165 VkPipelineObj pipe(m_device);
13166 pipe.AddColorAttachment();
13167 pipe.AddShader(&vs);
13168 pipe.AddShader(&fs);
13169
13170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13171 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13172 m_errorMonitor->VerifyFound();
13173
13174 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13175 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13176 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13177}
13178
13179TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013180 TEST_DESCRIPTION(
13181 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13182 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013183
13184 ASSERT_NO_FATAL_FAILURE(InitState());
13185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13186
13187 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013188 "Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013189
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013190 char const *vsSource =
13191 "#version 450\n"
13192 "\n"
13193 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13194 "out gl_PerVertex {\n"
13195 " vec4 gl_Position;\n"
13196 "};\n"
13197 "void main(){\n"
13198 " gl_Position = vec4(consts.x);\n"
13199 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013200
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013201 char const *fsSource =
13202 "#version 450\n"
13203 "\n"
13204 "layout(location = 0) out vec4 uFragColor;\n"
13205 "void main(){\n"
13206 " uFragColor = vec4(0,1,0,1);\n"
13207 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013208
13209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13210 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13211
13212 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13213 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13214
13215 // Set up a push constant range
13216 VkPushConstantRange push_constant_ranges = {};
13217 // Set to the wrong stage to challenge core_validation
13218 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13219 push_constant_ranges.size = 4;
13220
13221 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13222 pipeline_layout_create_info.pushConstantRangeCount = 1;
13223
13224 VkPipelineLayout pipeline_layout;
13225 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13226
13227 VkPipelineObj pipe(m_device);
13228 pipe.AddColorAttachment();
13229 pipe.AddShader(&vs);
13230 pipe.AddShader(&fs);
13231
13232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13233 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13234 m_errorMonitor->VerifyFound();
13235
13236 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13237}
13238
13239TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13240 TEST_DESCRIPTION(
13241 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13242
13243 ASSERT_NO_FATAL_FAILURE(InitState());
13244 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13245
13246 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013247 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013248
13249 // Some awkward steps are required to test with custom device features.
13250 std::vector<const char *> device_extension_names;
13251 auto features = m_device->phy().features();
13252 // Disable support for 64 bit floats
13253 features.shaderFloat64 = false;
13254 // The sacrificial device object
13255 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13256
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013257 char const *vsSource =
13258 "#version 450\n"
13259 "\n"
13260 "out gl_PerVertex {\n"
13261 " vec4 gl_Position;\n"
13262 "};\n"
13263 "void main(){\n"
13264 " gl_Position = vec4(1);\n"
13265 "}\n";
13266 char const *fsSource =
13267 "#version 450\n"
13268 "\n"
13269 "layout(location=0) out vec4 color;\n"
13270 "void main(){\n"
13271 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13272 " color = vec4(green);\n"
13273 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013274
13275 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13276 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13277
13278 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013279
13280 VkPipelineObj pipe(&test_device);
13281 pipe.AddColorAttachment();
13282 pipe.AddShader(&vs);
13283 pipe.AddShader(&fs);
13284
13285 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13286 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13287 VkPipelineLayout pipeline_layout;
13288 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13289
13290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13291 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13292 m_errorMonitor->VerifyFound();
13293
13294 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13295}
13296
13297TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13298 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13299
13300 ASSERT_NO_FATAL_FAILURE(InitState());
13301 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13302
13303 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13304
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013305 char const *vsSource =
13306 "#version 450\n"
13307 "\n"
13308 "out gl_PerVertex {\n"
13309 " vec4 gl_Position;\n"
13310 "};\n"
13311 "layout(xfb_buffer = 1) out;"
13312 "void main(){\n"
13313 " gl_Position = vec4(1);\n"
13314 "}\n";
13315 char const *fsSource =
13316 "#version 450\n"
13317 "\n"
13318 "layout(location=0) out vec4 color;\n"
13319 "void main(){\n"
13320 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13321 " color = vec4(green);\n"
13322 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013323
13324 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13325 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13326
13327 VkPipelineObj pipe(m_device);
13328 pipe.AddColorAttachment();
13329 pipe.AddShader(&vs);
13330 pipe.AddShader(&fs);
13331
13332 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13333 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13334 VkPipelineLayout pipeline_layout;
13335 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13336
13337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13338 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13339 m_errorMonitor->VerifyFound();
13340
13341 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13342}
13343
Karl Schultz6addd812016-02-02 17:17:23 -070013344TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013345 TEST_DESCRIPTION(
13346 "Test that an error is produced for a fragment shader input "
13347 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013350
Chris Forbes59cb88d2015-05-25 11:13:13 +120013351 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013353
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013354 char const *vsSource =
13355 "#version 450\n"
13356 "\n"
13357 "out gl_PerVertex {\n"
13358 " vec4 gl_Position;\n"
13359 "};\n"
13360 "void main(){\n"
13361 " gl_Position = vec4(1);\n"
13362 "}\n";
13363 char const *fsSource =
13364 "#version 450\n"
13365 "\n"
13366 "layout(location=0) in float x;\n"
13367 "layout(location=0) out vec4 color;\n"
13368 "void main(){\n"
13369 " color = vec4(x);\n"
13370 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013371
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013372 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13373 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013374
13375 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013376 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013377 pipe.AddShader(&vs);
13378 pipe.AddShader(&fs);
13379
Chris Forbes59cb88d2015-05-25 11:13:13 +120013380 VkDescriptorSetObj descriptorSet(m_device);
13381 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013382 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013383
Tony Barbour5781e8f2015-08-04 16:23:11 -060013384 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013385
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013386 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013387}
13388
Karl Schultz6addd812016-02-02 17:17:23 -070013389TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013390 TEST_DESCRIPTION(
13391 "Test that an error is produced for a fragment shader input "
13392 "within an interace block, which is not present in the outputs "
13393 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013395
13396 ASSERT_NO_FATAL_FAILURE(InitState());
13397 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13398
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013399 char const *vsSource =
13400 "#version 450\n"
13401 "\n"
13402 "out gl_PerVertex {\n"
13403 " vec4 gl_Position;\n"
13404 "};\n"
13405 "void main(){\n"
13406 " gl_Position = vec4(1);\n"
13407 "}\n";
13408 char const *fsSource =
13409 "#version 450\n"
13410 "\n"
13411 "in block { layout(location=0) float x; } ins;\n"
13412 "layout(location=0) out vec4 color;\n"
13413 "void main(){\n"
13414 " color = vec4(ins.x);\n"
13415 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013416
13417 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13418 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13419
13420 VkPipelineObj pipe(m_device);
13421 pipe.AddColorAttachment();
13422 pipe.AddShader(&vs);
13423 pipe.AddShader(&fs);
13424
13425 VkDescriptorSetObj descriptorSet(m_device);
13426 descriptorSet.AppendDummy();
13427 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13428
13429 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13430
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013431 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013432}
13433
Karl Schultz6addd812016-02-02 17:17:23 -070013434TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013435 TEST_DESCRIPTION(
13436 "Test that an error is produced for mismatched array sizes "
13437 "across the vertex->fragment shader interface");
13438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13439 "Type mismatch on location 0.0: 'ptr to "
13440 "output arr[2] of float32' vs 'ptr to "
13441 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013442
13443 ASSERT_NO_FATAL_FAILURE(InitState());
13444 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13445
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013446 char const *vsSource =
13447 "#version 450\n"
13448 "\n"
13449 "layout(location=0) out float x[2];\n"
13450 "out gl_PerVertex {\n"
13451 " vec4 gl_Position;\n"
13452 "};\n"
13453 "void main(){\n"
13454 " x[0] = 0; x[1] = 0;\n"
13455 " gl_Position = vec4(1);\n"
13456 "}\n";
13457 char const *fsSource =
13458 "#version 450\n"
13459 "\n"
13460 "layout(location=0) in float x[1];\n"
13461 "layout(location=0) out vec4 color;\n"
13462 "void main(){\n"
13463 " color = vec4(x[0]);\n"
13464 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013465
13466 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13467 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13468
13469 VkPipelineObj pipe(m_device);
13470 pipe.AddColorAttachment();
13471 pipe.AddShader(&vs);
13472 pipe.AddShader(&fs);
13473
13474 VkDescriptorSetObj descriptorSet(m_device);
13475 descriptorSet.AppendDummy();
13476 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13477
13478 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13479
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013480 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013481}
13482
Karl Schultz6addd812016-02-02 17:17:23 -070013483TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013484 TEST_DESCRIPTION(
13485 "Test that an error is produced for mismatched types across "
13486 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013488
Chris Forbesb56af562015-05-25 11:13:17 +120013489 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013490 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013491
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013492 char const *vsSource =
13493 "#version 450\n"
13494 "\n"
13495 "layout(location=0) out int x;\n"
13496 "out gl_PerVertex {\n"
13497 " vec4 gl_Position;\n"
13498 "};\n"
13499 "void main(){\n"
13500 " x = 0;\n"
13501 " gl_Position = vec4(1);\n"
13502 "}\n";
13503 char const *fsSource =
13504 "#version 450\n"
13505 "\n"
13506 "layout(location=0) in float x;\n" /* VS writes int */
13507 "layout(location=0) out vec4 color;\n"
13508 "void main(){\n"
13509 " color = vec4(x);\n"
13510 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013511
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013512 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13513 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013514
13515 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013516 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013517 pipe.AddShader(&vs);
13518 pipe.AddShader(&fs);
13519
Chris Forbesb56af562015-05-25 11:13:17 +120013520 VkDescriptorSetObj descriptorSet(m_device);
13521 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013522 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013523
Tony Barbour5781e8f2015-08-04 16:23:11 -060013524 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013525
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013526 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013527}
13528
Karl Schultz6addd812016-02-02 17:17:23 -070013529TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013530 TEST_DESCRIPTION(
13531 "Test that an error is produced for mismatched types across "
13532 "the vertex->fragment shader interface, when the variable is contained within "
13533 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013535
13536 ASSERT_NO_FATAL_FAILURE(InitState());
13537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13538
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013539 char const *vsSource =
13540 "#version 450\n"
13541 "\n"
13542 "out block { layout(location=0) int x; } outs;\n"
13543 "out gl_PerVertex {\n"
13544 " vec4 gl_Position;\n"
13545 "};\n"
13546 "void main(){\n"
13547 " outs.x = 0;\n"
13548 " gl_Position = vec4(1);\n"
13549 "}\n";
13550 char const *fsSource =
13551 "#version 450\n"
13552 "\n"
13553 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13554 "layout(location=0) out vec4 color;\n"
13555 "void main(){\n"
13556 " color = vec4(ins.x);\n"
13557 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013558
13559 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13560 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13561
13562 VkPipelineObj pipe(m_device);
13563 pipe.AddColorAttachment();
13564 pipe.AddShader(&vs);
13565 pipe.AddShader(&fs);
13566
13567 VkDescriptorSetObj descriptorSet(m_device);
13568 descriptorSet.AppendDummy();
13569 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13570
13571 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13572
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013573 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013574}
13575
13576TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013577 TEST_DESCRIPTION(
13578 "Test that an error is produced for location mismatches across "
13579 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
13580 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013581 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 +130013582
13583 ASSERT_NO_FATAL_FAILURE(InitState());
13584 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13585
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013586 char const *vsSource =
13587 "#version 450\n"
13588 "\n"
13589 "out block { layout(location=1) float x; } outs;\n"
13590 "out gl_PerVertex {\n"
13591 " vec4 gl_Position;\n"
13592 "};\n"
13593 "void main(){\n"
13594 " outs.x = 0;\n"
13595 " gl_Position = vec4(1);\n"
13596 "}\n";
13597 char const *fsSource =
13598 "#version 450\n"
13599 "\n"
13600 "in block { layout(location=0) float x; } ins;\n"
13601 "layout(location=0) out vec4 color;\n"
13602 "void main(){\n"
13603 " color = vec4(ins.x);\n"
13604 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013605
13606 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13607 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13608
13609 VkPipelineObj pipe(m_device);
13610 pipe.AddColorAttachment();
13611 pipe.AddShader(&vs);
13612 pipe.AddShader(&fs);
13613
13614 VkDescriptorSetObj descriptorSet(m_device);
13615 descriptorSet.AppendDummy();
13616 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13617
13618 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13619
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013620 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013621}
13622
13623TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013624 TEST_DESCRIPTION(
13625 "Test that an error is produced for component mismatches across the "
13626 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
13627 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013628 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 +130013629
13630 ASSERT_NO_FATAL_FAILURE(InitState());
13631 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13632
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013633 char const *vsSource =
13634 "#version 450\n"
13635 "\n"
13636 "out block { layout(location=0, component=0) float x; } outs;\n"
13637 "out gl_PerVertex {\n"
13638 " vec4 gl_Position;\n"
13639 "};\n"
13640 "void main(){\n"
13641 " outs.x = 0;\n"
13642 " gl_Position = vec4(1);\n"
13643 "}\n";
13644 char const *fsSource =
13645 "#version 450\n"
13646 "\n"
13647 "in block { layout(location=0, component=1) float x; } ins;\n"
13648 "layout(location=0) out vec4 color;\n"
13649 "void main(){\n"
13650 " color = vec4(ins.x);\n"
13651 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013652
13653 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13654 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13655
13656 VkPipelineObj pipe(m_device);
13657 pipe.AddColorAttachment();
13658 pipe.AddShader(&vs);
13659 pipe.AddShader(&fs);
13660
13661 VkDescriptorSetObj descriptorSet(m_device);
13662 descriptorSet.AppendDummy();
13663 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13664
13665 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13666
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013667 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013668}
13669
Chris Forbes1f3b0152016-11-30 12:48:40 +130013670TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13671 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13672
13673 ASSERT_NO_FATAL_FAILURE(InitState());
13674 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13675
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013676 char const *vsSource =
13677 "#version 450\n"
13678 "layout(location=0) out mediump float x;\n"
13679 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13680 char const *fsSource =
13681 "#version 450\n"
13682 "layout(location=0) in highp float x;\n"
13683 "layout(location=0) out vec4 color;\n"
13684 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130013685
13686 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13687 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13688
13689 VkPipelineObj pipe(m_device);
13690 pipe.AddColorAttachment();
13691 pipe.AddShader(&vs);
13692 pipe.AddShader(&fs);
13693
13694 VkDescriptorSetObj descriptorSet(m_device);
13695 descriptorSet.AppendDummy();
13696 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13697
13698 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13699
13700 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13701
13702 m_errorMonitor->VerifyFound();
13703}
13704
Chris Forbes870a39e2016-11-30 12:55:56 +130013705TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13706 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13707
13708 ASSERT_NO_FATAL_FAILURE(InitState());
13709 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13710
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013711 char const *vsSource =
13712 "#version 450\n"
13713 "out block { layout(location=0) mediump float x; };\n"
13714 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13715 char const *fsSource =
13716 "#version 450\n"
13717 "in block { layout(location=0) highp float x; };\n"
13718 "layout(location=0) out vec4 color;\n"
13719 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130013720
13721 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13722 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13723
13724 VkPipelineObj pipe(m_device);
13725 pipe.AddColorAttachment();
13726 pipe.AddShader(&vs);
13727 pipe.AddShader(&fs);
13728
13729 VkDescriptorSetObj descriptorSet(m_device);
13730 descriptorSet.AppendDummy();
13731 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13732
13733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13734
13735 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13736
13737 m_errorMonitor->VerifyFound();
13738}
13739
Karl Schultz6addd812016-02-02 17:17:23 -070013740TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013741 TEST_DESCRIPTION(
13742 "Test that a warning is produced for a vertex attribute which is "
13743 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013744 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013745
Chris Forbesde136e02015-05-25 11:13:28 +120013746 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013747 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013748
13749 VkVertexInputBindingDescription input_binding;
13750 memset(&input_binding, 0, sizeof(input_binding));
13751
13752 VkVertexInputAttributeDescription input_attrib;
13753 memset(&input_attrib, 0, sizeof(input_attrib));
13754 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13755
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013756 char const *vsSource =
13757 "#version 450\n"
13758 "\n"
13759 "out gl_PerVertex {\n"
13760 " vec4 gl_Position;\n"
13761 "};\n"
13762 "void main(){\n"
13763 " gl_Position = vec4(1);\n"
13764 "}\n";
13765 char const *fsSource =
13766 "#version 450\n"
13767 "\n"
13768 "layout(location=0) out vec4 color;\n"
13769 "void main(){\n"
13770 " color = vec4(1);\n"
13771 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013772
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013773 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13774 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013775
13776 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013777 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013778 pipe.AddShader(&vs);
13779 pipe.AddShader(&fs);
13780
13781 pipe.AddVertexInputBindings(&input_binding, 1);
13782 pipe.AddVertexInputAttribs(&input_attrib, 1);
13783
Chris Forbesde136e02015-05-25 11:13:28 +120013784 VkDescriptorSetObj descriptorSet(m_device);
13785 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013786 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013787
Tony Barbour5781e8f2015-08-04 16:23:11 -060013788 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013789
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013790 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013791}
13792
Karl Schultz6addd812016-02-02 17:17:23 -070013793TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013794 TEST_DESCRIPTION(
13795 "Test that a warning is produced for a location mismatch on "
13796 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013798
13799 ASSERT_NO_FATAL_FAILURE(InitState());
13800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13801
13802 VkVertexInputBindingDescription input_binding;
13803 memset(&input_binding, 0, sizeof(input_binding));
13804
13805 VkVertexInputAttributeDescription input_attrib;
13806 memset(&input_attrib, 0, sizeof(input_attrib));
13807 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13808
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013809 char const *vsSource =
13810 "#version 450\n"
13811 "\n"
13812 "layout(location=1) in float x;\n"
13813 "out gl_PerVertex {\n"
13814 " vec4 gl_Position;\n"
13815 "};\n"
13816 "void main(){\n"
13817 " gl_Position = vec4(x);\n"
13818 "}\n";
13819 char const *fsSource =
13820 "#version 450\n"
13821 "\n"
13822 "layout(location=0) out vec4 color;\n"
13823 "void main(){\n"
13824 " color = vec4(1);\n"
13825 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013826
13827 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13828 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13829
13830 VkPipelineObj pipe(m_device);
13831 pipe.AddColorAttachment();
13832 pipe.AddShader(&vs);
13833 pipe.AddShader(&fs);
13834
13835 pipe.AddVertexInputBindings(&input_binding, 1);
13836 pipe.AddVertexInputAttribs(&input_attrib, 1);
13837
13838 VkDescriptorSetObj descriptorSet(m_device);
13839 descriptorSet.AppendDummy();
13840 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13841
13842 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13843
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013844 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013845}
13846
Karl Schultz6addd812016-02-02 17:17:23 -070013847TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013848 TEST_DESCRIPTION(
13849 "Test that an error is produced for a vertex shader input which is not "
13850 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13852 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013853
Chris Forbes62e8e502015-05-25 11:13:29 +120013854 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013856
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013857 char const *vsSource =
13858 "#version 450\n"
13859 "\n"
13860 "layout(location=0) in vec4 x;\n" /* not provided */
13861 "out gl_PerVertex {\n"
13862 " vec4 gl_Position;\n"
13863 "};\n"
13864 "void main(){\n"
13865 " gl_Position = x;\n"
13866 "}\n";
13867 char const *fsSource =
13868 "#version 450\n"
13869 "\n"
13870 "layout(location=0) out vec4 color;\n"
13871 "void main(){\n"
13872 " color = vec4(1);\n"
13873 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013874
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013875 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13876 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013877
13878 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013879 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013880 pipe.AddShader(&vs);
13881 pipe.AddShader(&fs);
13882
Chris Forbes62e8e502015-05-25 11:13:29 +120013883 VkDescriptorSetObj descriptorSet(m_device);
13884 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013885 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013886
Tony Barbour5781e8f2015-08-04 16:23:11 -060013887 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013888
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013889 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013890}
13891
Karl Schultz6addd812016-02-02 17:17:23 -070013892TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013893 TEST_DESCRIPTION(
13894 "Test that an error is produced for a mismatch between the "
13895 "fundamental type (float/int/uint) of an attribute and the "
13896 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013897 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 -060013898
Chris Forbesc97d98e2015-05-25 11:13:31 +120013899 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013900 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013901
13902 VkVertexInputBindingDescription input_binding;
13903 memset(&input_binding, 0, sizeof(input_binding));
13904
13905 VkVertexInputAttributeDescription input_attrib;
13906 memset(&input_attrib, 0, sizeof(input_attrib));
13907 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13908
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013909 char const *vsSource =
13910 "#version 450\n"
13911 "\n"
13912 "layout(location=0) in int x;\n" /* attrib provided float */
13913 "out gl_PerVertex {\n"
13914 " vec4 gl_Position;\n"
13915 "};\n"
13916 "void main(){\n"
13917 " gl_Position = vec4(x);\n"
13918 "}\n";
13919 char const *fsSource =
13920 "#version 450\n"
13921 "\n"
13922 "layout(location=0) out vec4 color;\n"
13923 "void main(){\n"
13924 " color = vec4(1);\n"
13925 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013926
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013927 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13928 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013929
13930 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013931 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013932 pipe.AddShader(&vs);
13933 pipe.AddShader(&fs);
13934
13935 pipe.AddVertexInputBindings(&input_binding, 1);
13936 pipe.AddVertexInputAttribs(&input_attrib, 1);
13937
Chris Forbesc97d98e2015-05-25 11:13:31 +120013938 VkDescriptorSetObj descriptorSet(m_device);
13939 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013940 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013941
Tony Barbour5781e8f2015-08-04 16:23:11 -060013942 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013943
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013944 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013945}
13946
Chris Forbesc68b43c2016-04-06 11:18:47 +120013947TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013948 TEST_DESCRIPTION(
13949 "Test that an error is produced for a pipeline containing multiple "
13950 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13952 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013953
13954 ASSERT_NO_FATAL_FAILURE(InitState());
13955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13956
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013957 char const *vsSource =
13958 "#version 450\n"
13959 "\n"
13960 "out gl_PerVertex {\n"
13961 " vec4 gl_Position;\n"
13962 "};\n"
13963 "void main(){\n"
13964 " gl_Position = vec4(1);\n"
13965 "}\n";
13966 char const *fsSource =
13967 "#version 450\n"
13968 "\n"
13969 "layout(location=0) out vec4 color;\n"
13970 "void main(){\n"
13971 " color = vec4(1);\n"
13972 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013973
13974 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13975 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13976
13977 VkPipelineObj pipe(m_device);
13978 pipe.AddColorAttachment();
13979 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013980 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013981 pipe.AddShader(&fs);
13982
13983 VkDescriptorSetObj descriptorSet(m_device);
13984 descriptorSet.AppendDummy();
13985 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13986
13987 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13988
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013989 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013990}
13991
Chris Forbes82ff92a2016-09-09 10:50:24 +120013992TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120013994
13995 ASSERT_NO_FATAL_FAILURE(InitState());
13996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13997
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013998 char const *vsSource =
13999 "#version 450\n"
14000 "out gl_PerVertex {\n"
14001 " vec4 gl_Position;\n"
14002 "};\n"
14003 "void main(){\n"
14004 " gl_Position = vec4(0);\n"
14005 "}\n";
14006 char const *fsSource =
14007 "#version 450\n"
14008 "\n"
14009 "layout(location=0) out vec4 color;\n"
14010 "void main(){\n"
14011 " color = vec4(1);\n"
14012 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014013
14014 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14015 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14016
14017 VkPipelineObj pipe(m_device);
14018 pipe.AddColorAttachment();
14019 pipe.AddShader(&vs);
14020 pipe.AddShader(&fs);
14021
14022 VkDescriptorSetObj descriptorSet(m_device);
14023 descriptorSet.AppendDummy();
14024 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14025
14026 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14027
14028 m_errorMonitor->VerifyFound();
14029}
14030
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014031TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014032 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14033 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14034 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014035
14036 ASSERT_NO_FATAL_FAILURE(InitState());
14037 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14038
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014039 char const *vsSource =
14040 "#version 450\n"
14041 "void main(){ gl_Position = vec4(0); }\n";
14042 char const *fsSource =
14043 "#version 450\n"
14044 "\n"
14045 "layout(location=0) out vec4 color;\n"
14046 "void main(){\n"
14047 " color = vec4(1);\n"
14048 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014049
14050 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14051 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14052
14053 VkPipelineObj pipe(m_device);
14054 pipe.AddColorAttachment();
14055 pipe.AddShader(&vs);
14056 pipe.AddShader(&fs);
14057
14058 VkDescriptorSetObj descriptorSet(m_device);
14059 descriptorSet.AppendDummy();
14060 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14061
14062 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014063 {
14064 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14065 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14066 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014067 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014068 {
14069 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14070 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14071 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014072 },
14073 };
14074 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014075 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014076 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014077 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14078 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014079 VkRenderPass rp;
14080 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14081 ASSERT_VK_SUCCESS(err);
14082
14083 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14084
14085 m_errorMonitor->VerifyFound();
14086
14087 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14088}
14089
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014090TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014091 TEST_DESCRIPTION(
14092 "Test that an error is produced for a variable output from "
14093 "the TCS without the patch decoration, but consumed in the TES "
14094 "with the decoration.");
14095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14096 "is per-vertex in tessellation control shader stage "
14097 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014098
14099 ASSERT_NO_FATAL_FAILURE(InitState());
14100 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14101
Chris Forbesc1e852d2016-04-04 19:26:42 +120014102 if (!m_device->phy().features().tessellationShader) {
14103 printf("Device does not support tessellation shaders; skipped.\n");
14104 return;
14105 }
14106
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014107 char const *vsSource =
14108 "#version 450\n"
14109 "void main(){}\n";
14110 char const *tcsSource =
14111 "#version 450\n"
14112 "layout(location=0) out int x[];\n"
14113 "layout(vertices=3) out;\n"
14114 "void main(){\n"
14115 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14116 " gl_TessLevelInner[0] = 1;\n"
14117 " x[gl_InvocationID] = gl_InvocationID;\n"
14118 "}\n";
14119 char const *tesSource =
14120 "#version 450\n"
14121 "layout(triangles, equal_spacing, cw) in;\n"
14122 "layout(location=0) patch in int x;\n"
14123 "out gl_PerVertex { vec4 gl_Position; };\n"
14124 "void main(){\n"
14125 " gl_Position.xyz = gl_TessCoord;\n"
14126 " gl_Position.w = x;\n"
14127 "}\n";
14128 char const *fsSource =
14129 "#version 450\n"
14130 "layout(location=0) out vec4 color;\n"
14131 "void main(){\n"
14132 " color = vec4(1);\n"
14133 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014134
14135 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14136 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14137 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14138 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14139
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014140 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14141 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014143 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014144
14145 VkPipelineObj pipe(m_device);
14146 pipe.SetInputAssembly(&iasci);
14147 pipe.SetTessellation(&tsci);
14148 pipe.AddColorAttachment();
14149 pipe.AddShader(&vs);
14150 pipe.AddShader(&tcs);
14151 pipe.AddShader(&tes);
14152 pipe.AddShader(&fs);
14153
14154 VkDescriptorSetObj descriptorSet(m_device);
14155 descriptorSet.AppendDummy();
14156 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14157
14158 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14159
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014160 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014161}
14162
Karl Schultz6addd812016-02-02 17:17:23 -070014163TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014164 TEST_DESCRIPTION(
14165 "Test that an error is produced for a vertex attribute setup where multiple "
14166 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14168 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014169
Chris Forbes280ba2c2015-06-12 11:16:41 +120014170 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014171 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014172
14173 /* Two binding descriptions for binding 0 */
14174 VkVertexInputBindingDescription input_bindings[2];
14175 memset(input_bindings, 0, sizeof(input_bindings));
14176
14177 VkVertexInputAttributeDescription input_attrib;
14178 memset(&input_attrib, 0, sizeof(input_attrib));
14179 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14180
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014181 char const *vsSource =
14182 "#version 450\n"
14183 "\n"
14184 "layout(location=0) in float x;\n" /* attrib provided float */
14185 "out gl_PerVertex {\n"
14186 " vec4 gl_Position;\n"
14187 "};\n"
14188 "void main(){\n"
14189 " gl_Position = vec4(x);\n"
14190 "}\n";
14191 char const *fsSource =
14192 "#version 450\n"
14193 "\n"
14194 "layout(location=0) out vec4 color;\n"
14195 "void main(){\n"
14196 " color = vec4(1);\n"
14197 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014198
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014199 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14200 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014201
14202 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014203 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014204 pipe.AddShader(&vs);
14205 pipe.AddShader(&fs);
14206
14207 pipe.AddVertexInputBindings(input_bindings, 2);
14208 pipe.AddVertexInputAttribs(&input_attrib, 1);
14209
Chris Forbes280ba2c2015-06-12 11:16:41 +120014210 VkDescriptorSetObj descriptorSet(m_device);
14211 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014212 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014213
Tony Barbour5781e8f2015-08-04 16:23:11 -060014214 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014215
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014216 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014217}
Chris Forbes8f68b562015-05-25 11:13:32 +120014218
Karl Schultz6addd812016-02-02 17:17:23 -070014219TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014220 TEST_DESCRIPTION(
14221 "Test that an error is produced for a fragment shader which does not "
14222 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014224
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014225 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014226
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014227 char const *vsSource =
14228 "#version 450\n"
14229 "\n"
14230 "out gl_PerVertex {\n"
14231 " vec4 gl_Position;\n"
14232 "};\n"
14233 "void main(){\n"
14234 " gl_Position = vec4(1);\n"
14235 "}\n";
14236 char const *fsSource =
14237 "#version 450\n"
14238 "\n"
14239 "void main(){\n"
14240 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014241
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014242 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14243 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014244
14245 VkPipelineObj pipe(m_device);
14246 pipe.AddShader(&vs);
14247 pipe.AddShader(&fs);
14248
Chia-I Wu08accc62015-07-07 11:50:03 +080014249 /* set up CB 0, not written */
14250 pipe.AddColorAttachment();
14251 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014252
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014253 VkDescriptorSetObj descriptorSet(m_device);
14254 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014255 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014256
Tony Barbour5781e8f2015-08-04 16:23:11 -060014257 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014258
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014259 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014260}
14261
Karl Schultz6addd812016-02-02 17:17:23 -070014262TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014263 TEST_DESCRIPTION(
14264 "Test that a warning is produced for a fragment shader which provides a spurious "
14265 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014267 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014268
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014269 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014270
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014271 char const *vsSource =
14272 "#version 450\n"
14273 "\n"
14274 "out gl_PerVertex {\n"
14275 " vec4 gl_Position;\n"
14276 "};\n"
14277 "void main(){\n"
14278 " gl_Position = vec4(1);\n"
14279 "}\n";
14280 char const *fsSource =
14281 "#version 450\n"
14282 "\n"
14283 "layout(location=0) out vec4 x;\n"
14284 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14285 "void main(){\n"
14286 " x = vec4(1);\n"
14287 " y = vec4(1);\n"
14288 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014289
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014290 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14291 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014292
14293 VkPipelineObj pipe(m_device);
14294 pipe.AddShader(&vs);
14295 pipe.AddShader(&fs);
14296
Chia-I Wu08accc62015-07-07 11:50:03 +080014297 /* set up CB 0, not written */
14298 pipe.AddColorAttachment();
14299 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014300 /* FS writes CB 1, but we don't configure it */
14301
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014302 VkDescriptorSetObj descriptorSet(m_device);
14303 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014304 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014305
Tony Barbour5781e8f2015-08-04 16:23:11 -060014306 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014307
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014308 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014309}
14310
Karl Schultz6addd812016-02-02 17:17:23 -070014311TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014312 TEST_DESCRIPTION(
14313 "Test that an error is produced for a mismatch between the fundamental "
14314 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014316
Chris Forbesa36d69e2015-05-25 11:13:44 +120014317 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014318
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014319 char const *vsSource =
14320 "#version 450\n"
14321 "\n"
14322 "out gl_PerVertex {\n"
14323 " vec4 gl_Position;\n"
14324 "};\n"
14325 "void main(){\n"
14326 " gl_Position = vec4(1);\n"
14327 "}\n";
14328 char const *fsSource =
14329 "#version 450\n"
14330 "\n"
14331 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14332 "void main(){\n"
14333 " x = ivec4(1);\n"
14334 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014335
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014336 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14337 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014338
14339 VkPipelineObj pipe(m_device);
14340 pipe.AddShader(&vs);
14341 pipe.AddShader(&fs);
14342
Chia-I Wu08accc62015-07-07 11:50:03 +080014343 /* set up CB 0; type is UNORM by default */
14344 pipe.AddColorAttachment();
14345 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014346
Chris Forbesa36d69e2015-05-25 11:13:44 +120014347 VkDescriptorSetObj descriptorSet(m_device);
14348 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014349 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014350
Tony Barbour5781e8f2015-08-04 16:23:11 -060014351 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014352
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014353 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014354}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014355
Karl Schultz6addd812016-02-02 17:17:23 -070014356TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014357 TEST_DESCRIPTION(
14358 "Test that an error is produced for a shader consuming a uniform "
14359 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014361
Chris Forbes556c76c2015-08-14 12:04:59 +120014362 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014363
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014364 char const *vsSource =
14365 "#version 450\n"
14366 "\n"
14367 "out gl_PerVertex {\n"
14368 " vec4 gl_Position;\n"
14369 "};\n"
14370 "void main(){\n"
14371 " gl_Position = vec4(1);\n"
14372 "}\n";
14373 char const *fsSource =
14374 "#version 450\n"
14375 "\n"
14376 "layout(location=0) out vec4 x;\n"
14377 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14378 "void main(){\n"
14379 " x = vec4(bar.y);\n"
14380 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014381
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014382 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14383 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014384
Chris Forbes556c76c2015-08-14 12:04:59 +120014385 VkPipelineObj pipe(m_device);
14386 pipe.AddShader(&vs);
14387 pipe.AddShader(&fs);
14388
14389 /* set up CB 0; type is UNORM by default */
14390 pipe.AddColorAttachment();
14391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14392
14393 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014394 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014395
14396 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14397
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014398 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014399}
14400
Chris Forbes5c59e902016-02-26 16:56:09 +130014401TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014402 TEST_DESCRIPTION(
14403 "Test that an error is produced for a shader consuming push constants "
14404 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014406
14407 ASSERT_NO_FATAL_FAILURE(InitState());
14408
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014409 char const *vsSource =
14410 "#version 450\n"
14411 "\n"
14412 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14413 "out gl_PerVertex {\n"
14414 " vec4 gl_Position;\n"
14415 "};\n"
14416 "void main(){\n"
14417 " gl_Position = vec4(consts.x);\n"
14418 "}\n";
14419 char const *fsSource =
14420 "#version 450\n"
14421 "\n"
14422 "layout(location=0) out vec4 x;\n"
14423 "void main(){\n"
14424 " x = vec4(1);\n"
14425 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014426
14427 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14428 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14429
14430 VkPipelineObj pipe(m_device);
14431 pipe.AddShader(&vs);
14432 pipe.AddShader(&fs);
14433
14434 /* set up CB 0; type is UNORM by default */
14435 pipe.AddColorAttachment();
14436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14437
14438 VkDescriptorSetObj descriptorSet(m_device);
14439 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14440
14441 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14442
14443 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014444 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014445}
14446
Chris Forbes3fb17902016-08-22 14:57:55 +120014447TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014448 TEST_DESCRIPTION(
14449 "Test that an error is produced for a shader consuming an input attachment "
14450 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14452 "consumes input attachment index 0 but not provided in subpass");
14453
14454 ASSERT_NO_FATAL_FAILURE(InitState());
14455
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014456 char const *vsSource =
14457 "#version 450\n"
14458 "\n"
14459 "out gl_PerVertex {\n"
14460 " vec4 gl_Position;\n"
14461 "};\n"
14462 "void main(){\n"
14463 " gl_Position = vec4(1);\n"
14464 "}\n";
14465 char const *fsSource =
14466 "#version 450\n"
14467 "\n"
14468 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14469 "layout(location=0) out vec4 color;\n"
14470 "void main() {\n"
14471 " color = subpassLoad(x);\n"
14472 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014473
14474 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14475 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14476
14477 VkPipelineObj pipe(m_device);
14478 pipe.AddShader(&vs);
14479 pipe.AddShader(&fs);
14480 pipe.AddColorAttachment();
14481 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14482
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014483 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14484 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014485 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014486 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014487 ASSERT_VK_SUCCESS(err);
14488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014489 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014490 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014491 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014492 ASSERT_VK_SUCCESS(err);
14493
14494 // error here.
14495 pipe.CreateVKPipeline(pl, renderPass());
14496
14497 m_errorMonitor->VerifyFound();
14498
14499 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14500 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14501}
14502
Chris Forbes5a9a0472016-08-22 16:02:09 +120014503TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014504 TEST_DESCRIPTION(
14505 "Test that an error is produced for a shader consuming an input attachment "
14506 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14508 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14509
14510 ASSERT_NO_FATAL_FAILURE(InitState());
14511
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014512 char const *vsSource =
14513 "#version 450\n"
14514 "\n"
14515 "out gl_PerVertex {\n"
14516 " vec4 gl_Position;\n"
14517 "};\n"
14518 "void main(){\n"
14519 " gl_Position = vec4(1);\n"
14520 "}\n";
14521 char const *fsSource =
14522 "#version 450\n"
14523 "\n"
14524 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14525 "layout(location=0) out vec4 color;\n"
14526 "void main() {\n"
14527 " color = subpassLoad(x);\n"
14528 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014529
14530 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14531 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14532
14533 VkPipelineObj pipe(m_device);
14534 pipe.AddShader(&vs);
14535 pipe.AddShader(&fs);
14536 pipe.AddColorAttachment();
14537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14538
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014539 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14540 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014541 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014542 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014543 ASSERT_VK_SUCCESS(err);
14544
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014545 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014546 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014547 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014548 ASSERT_VK_SUCCESS(err);
14549
14550 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014551 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14552 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14553 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14554 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14555 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 +120014556 };
14557 VkAttachmentReference color = {
14558 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14559 };
14560 VkAttachmentReference input = {
14561 1, VK_IMAGE_LAYOUT_GENERAL,
14562 };
14563
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014564 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014565
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014566 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014567 VkRenderPass rp;
14568 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14569 ASSERT_VK_SUCCESS(err);
14570
14571 // error here.
14572 pipe.CreateVKPipeline(pl, rp);
14573
14574 m_errorMonitor->VerifyFound();
14575
14576 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14577 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14578 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14579}
14580
Chris Forbes541f7b02016-08-22 15:30:27 +120014581TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014582 TEST_DESCRIPTION(
14583 "Test that an error is produced for a shader consuming an input attachment "
14584 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120014585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014586 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014587
14588 ASSERT_NO_FATAL_FAILURE(InitState());
14589
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014590 char const *vsSource =
14591 "#version 450\n"
14592 "\n"
14593 "out gl_PerVertex {\n"
14594 " vec4 gl_Position;\n"
14595 "};\n"
14596 "void main(){\n"
14597 " gl_Position = vec4(1);\n"
14598 "}\n";
14599 char const *fsSource =
14600 "#version 450\n"
14601 "\n"
14602 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
14603 "layout(location=0) out vec4 color;\n"
14604 "void main() {\n"
14605 " color = subpassLoad(xs[0]);\n"
14606 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014607
14608 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14609 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14610
14611 VkPipelineObj pipe(m_device);
14612 pipe.AddShader(&vs);
14613 pipe.AddShader(&fs);
14614 pipe.AddColorAttachment();
14615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014617 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14618 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014619 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014620 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014621 ASSERT_VK_SUCCESS(err);
14622
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014623 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014624 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014625 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014626 ASSERT_VK_SUCCESS(err);
14627
14628 // error here.
14629 pipe.CreateVKPipeline(pl, renderPass());
14630
14631 m_errorMonitor->VerifyFound();
14632
14633 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14634 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14635}
14636
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014637TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014638 TEST_DESCRIPTION(
14639 "Test that an error is produced for a compute pipeline consuming a "
14640 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014642
14643 ASSERT_NO_FATAL_FAILURE(InitState());
14644
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014645 char const *csSource =
14646 "#version 450\n"
14647 "\n"
14648 "layout(local_size_x=1) in;\n"
14649 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14650 "void main(){\n"
14651 " x = vec4(1);\n"
14652 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014653
14654 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14655
14656 VkDescriptorSetObj descriptorSet(m_device);
14657 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14658
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014659 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14660 nullptr,
14661 0,
14662 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14663 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14664 descriptorSet.GetPipelineLayout(),
14665 VK_NULL_HANDLE,
14666 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014667
14668 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014669 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014670
14671 m_errorMonitor->VerifyFound();
14672
14673 if (err == VK_SUCCESS) {
14674 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14675 }
14676}
14677
Chris Forbes22a9b092016-07-19 14:34:05 +120014678TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014679 TEST_DESCRIPTION(
14680 "Test that an error is produced for a pipeline consuming a "
14681 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14683 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014684
14685 ASSERT_NO_FATAL_FAILURE(InitState());
14686
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014687 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14688 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014689 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014690 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014691 ASSERT_VK_SUCCESS(err);
14692
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014693 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014694 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014695 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014696 ASSERT_VK_SUCCESS(err);
14697
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014698 char const *csSource =
14699 "#version 450\n"
14700 "\n"
14701 "layout(local_size_x=1) in;\n"
14702 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14703 "void main() {\n"
14704 " x.x = 1.0f;\n"
14705 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014706 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14707
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014708 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14709 nullptr,
14710 0,
14711 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14712 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14713 pl,
14714 VK_NULL_HANDLE,
14715 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014716
14717 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014718 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014719
14720 m_errorMonitor->VerifyFound();
14721
14722 if (err == VK_SUCCESS) {
14723 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14724 }
14725
14726 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14727 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14728}
14729
Chris Forbes50020592016-07-27 13:52:41 +120014730TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014731 TEST_DESCRIPTION(
14732 "Test that an error is produced when an image view type "
14733 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120014734
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014735 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 +120014736
14737 ASSERT_NO_FATAL_FAILURE(InitState());
14738 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14739
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014740 char const *vsSource =
14741 "#version 450\n"
14742 "\n"
14743 "out gl_PerVertex { vec4 gl_Position; };\n"
14744 "void main() { gl_Position = vec4(0); }\n";
14745 char const *fsSource =
14746 "#version 450\n"
14747 "\n"
14748 "layout(set=0, binding=0) uniform sampler3D s;\n"
14749 "layout(location=0) out vec4 color;\n"
14750 "void main() {\n"
14751 " color = texture(s, vec3(0));\n"
14752 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014753 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14754 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14755
14756 VkPipelineObj pipe(m_device);
14757 pipe.AddShader(&vs);
14758 pipe.AddShader(&fs);
14759 pipe.AddColorAttachment();
14760
14761 VkTextureObj texture(m_device, nullptr);
14762 VkSamplerObj sampler(m_device);
14763
14764 VkDescriptorSetObj descriptorSet(m_device);
14765 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14766 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14767
14768 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14769 ASSERT_VK_SUCCESS(err);
14770
Tony Barbour552f6c02016-12-21 14:34:07 -070014771 m_commandBuffer->BeginCommandBuffer();
14772 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014773
14774 m_commandBuffer->BindPipeline(pipe);
14775 m_commandBuffer->BindDescriptorSet(descriptorSet);
14776
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014777 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014778 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014779 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014780 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14781
14782 // error produced here.
14783 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14784
14785 m_errorMonitor->VerifyFound();
14786
Tony Barbour552f6c02016-12-21 14:34:07 -070014787 m_commandBuffer->EndRenderPass();
14788 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014789}
14790
Chris Forbes5533bfc2016-07-27 14:12:34 +120014791TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014792 TEST_DESCRIPTION(
14793 "Test that an error is produced when a multisampled images "
14794 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014795
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014797
14798 ASSERT_NO_FATAL_FAILURE(InitState());
14799 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14800
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014801 char const *vsSource =
14802 "#version 450\n"
14803 "\n"
14804 "out gl_PerVertex { vec4 gl_Position; };\n"
14805 "void main() { gl_Position = vec4(0); }\n";
14806 char const *fsSource =
14807 "#version 450\n"
14808 "\n"
14809 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14810 "layout(location=0) out vec4 color;\n"
14811 "void main() {\n"
14812 " color = texelFetch(s, ivec2(0), 0);\n"
14813 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014814 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14815 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14816
14817 VkPipelineObj pipe(m_device);
14818 pipe.AddShader(&vs);
14819 pipe.AddShader(&fs);
14820 pipe.AddColorAttachment();
14821
14822 VkTextureObj texture(m_device, nullptr);
14823 VkSamplerObj sampler(m_device);
14824
14825 VkDescriptorSetObj descriptorSet(m_device);
14826 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14827 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14828
14829 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14830 ASSERT_VK_SUCCESS(err);
14831
Tony Barbour552f6c02016-12-21 14:34:07 -070014832 m_commandBuffer->BeginCommandBuffer();
14833 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014834
14835 m_commandBuffer->BindPipeline(pipe);
14836 m_commandBuffer->BindDescriptorSet(descriptorSet);
14837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014838 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014839 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014840 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014841 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14842
14843 // error produced here.
14844 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14845
14846 m_errorMonitor->VerifyFound();
14847
Tony Barbour552f6c02016-12-21 14:34:07 -070014848 m_commandBuffer->EndRenderPass();
14849 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014850}
14851
Mark Youngc48c4c12016-04-11 14:26:49 -060014852TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014854
14855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014856
14857 // Create an image
14858 VkImage image;
14859
Karl Schultz6addd812016-02-02 17:17:23 -070014860 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14861 const int32_t tex_width = 32;
14862 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014863
14864 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014865 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14866 image_create_info.pNext = NULL;
14867 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14868 image_create_info.format = tex_format;
14869 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014870 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014871 image_create_info.extent.depth = 1;
14872 image_create_info.mipLevels = 1;
14873 image_create_info.arrayLayers = 1;
14874 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14875 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14876 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14877 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014878
14879 // Introduce error by sending down a bogus width extent
14880 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014881 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014882
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014883 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014884}
14885
Mark Youngc48c4c12016-04-11 14:26:49 -060014886TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070014887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060014888
14889 ASSERT_NO_FATAL_FAILURE(InitState());
14890
14891 // Create an image
14892 VkImage image;
14893
14894 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14895 const int32_t tex_width = 32;
14896 const int32_t tex_height = 32;
14897
14898 VkImageCreateInfo image_create_info = {};
14899 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14900 image_create_info.pNext = NULL;
14901 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14902 image_create_info.format = tex_format;
14903 image_create_info.extent.width = tex_width;
14904 image_create_info.extent.height = tex_height;
14905 image_create_info.extent.depth = 1;
14906 image_create_info.mipLevels = 1;
14907 image_create_info.arrayLayers = 1;
14908 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14909 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14910 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14911 image_create_info.flags = 0;
14912
14913 // Introduce error by sending down a bogus width extent
14914 image_create_info.extent.width = 0;
14915 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14916
14917 m_errorMonitor->VerifyFound();
14918}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014919
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014920TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014921 TEST_DESCRIPTION(
14922 "Create a render pass with an attachment description "
14923 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014924
14925 ASSERT_NO_FATAL_FAILURE(InitState());
14926 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14927
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070014928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014929
14930 VkAttachmentReference color_attach = {};
14931 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14932 color_attach.attachment = 0;
14933 VkSubpassDescription subpass = {};
14934 subpass.colorAttachmentCount = 1;
14935 subpass.pColorAttachments = &color_attach;
14936
14937 VkRenderPassCreateInfo rpci = {};
14938 rpci.subpassCount = 1;
14939 rpci.pSubpasses = &subpass;
14940 rpci.attachmentCount = 1;
14941 VkAttachmentDescription attach_desc = {};
14942 attach_desc.format = VK_FORMAT_UNDEFINED;
14943 rpci.pAttachments = &attach_desc;
14944 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14945 VkRenderPass rp;
14946 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14947
14948 m_errorMonitor->VerifyFound();
14949
14950 if (result == VK_SUCCESS) {
14951 vkDestroyRenderPass(m_device->device(), rp, NULL);
14952 }
14953}
14954
Karl Schultz6addd812016-02-02 17:17:23 -070014955TEST_F(VkLayerTest, InvalidImageView) {
14956 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014957
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014958 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014959
Tobin Ehliscde08892015-09-22 10:11:37 -060014960 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014961
Mike Stroyana3082432015-09-25 13:39:21 -060014962 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014963 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014964
Karl Schultz6addd812016-02-02 17:17:23 -070014965 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14966 const int32_t tex_width = 32;
14967 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014968
14969 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014970 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14971 image_create_info.pNext = NULL;
14972 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14973 image_create_info.format = tex_format;
14974 image_create_info.extent.width = tex_width;
14975 image_create_info.extent.height = tex_height;
14976 image_create_info.extent.depth = 1;
14977 image_create_info.mipLevels = 1;
14978 image_create_info.arrayLayers = 1;
14979 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14980 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14981 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14982 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014983
Chia-I Wuf7458c52015-10-26 21:10:41 +080014984 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014985 ASSERT_VK_SUCCESS(err);
14986
14987 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014988 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014989 image_view_create_info.image = image;
14990 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14991 image_view_create_info.format = tex_format;
14992 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014993 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070014994 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014995 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014996
14997 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014998 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060014999
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015000 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015001 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015002}
Mike Stroyana3082432015-09-25 13:39:21 -060015003
Mark Youngd339ba32016-05-30 13:28:35 -060015004TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15005 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015006 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015007 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015008
15009 ASSERT_NO_FATAL_FAILURE(InitState());
15010
15011 // Create an image and try to create a view with no memory backing the image
15012 VkImage image;
15013
15014 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15015 const int32_t tex_width = 32;
15016 const int32_t tex_height = 32;
15017
15018 VkImageCreateInfo image_create_info = {};
15019 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15020 image_create_info.pNext = NULL;
15021 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15022 image_create_info.format = tex_format;
15023 image_create_info.extent.width = tex_width;
15024 image_create_info.extent.height = tex_height;
15025 image_create_info.extent.depth = 1;
15026 image_create_info.mipLevels = 1;
15027 image_create_info.arrayLayers = 1;
15028 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15029 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15030 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15031 image_create_info.flags = 0;
15032
15033 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15034 ASSERT_VK_SUCCESS(err);
15035
15036 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015037 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015038 image_view_create_info.image = image;
15039 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15040 image_view_create_info.format = tex_format;
15041 image_view_create_info.subresourceRange.layerCount = 1;
15042 image_view_create_info.subresourceRange.baseMipLevel = 0;
15043 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015044 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015045
15046 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015047 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015048
15049 m_errorMonitor->VerifyFound();
15050 vkDestroyImage(m_device->device(), image, NULL);
15051 // If last error is success, it still created the view, so delete it.
15052 if (err == VK_SUCCESS) {
15053 vkDestroyImageView(m_device->device(), view, NULL);
15054 }
Mark Youngd339ba32016-05-30 13:28:35 -060015055}
15056
Karl Schultz6addd812016-02-02 17:17:23 -070015057TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015058 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015060
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015061 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015062
Karl Schultz6addd812016-02-02 17:17:23 -070015063 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015064 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015065 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015066 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015067
15068 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015069 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015070 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015071 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15072 image_view_create_info.format = tex_format;
15073 image_view_create_info.subresourceRange.baseMipLevel = 0;
15074 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015075 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015076 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015077 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015078
15079 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015080 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015081
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015082 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015083}
15084
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015085TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015086 VkResult err;
15087 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015088
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015090
Mike Stroyana3082432015-09-25 13:39:21 -060015091 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015092
15093 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015094 VkImage srcImage;
15095 VkImage dstImage;
15096 VkDeviceMemory srcMem;
15097 VkDeviceMemory destMem;
15098 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015099
15100 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015101 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15102 image_create_info.pNext = NULL;
15103 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15104 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15105 image_create_info.extent.width = 32;
15106 image_create_info.extent.height = 32;
15107 image_create_info.extent.depth = 1;
15108 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015109 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015110 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15111 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15112 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15113 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015114
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015115 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015116 ASSERT_VK_SUCCESS(err);
15117
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015118 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015119 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015120 ASSERT_VK_SUCCESS(err);
15121
15122 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015123 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015124 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15125 memAlloc.pNext = NULL;
15126 memAlloc.allocationSize = 0;
15127 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015128
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015129 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015130 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015131 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015132 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015133 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015134 ASSERT_VK_SUCCESS(err);
15135
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015136 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015137 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015138 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015139 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015140 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015141 ASSERT_VK_SUCCESS(err);
15142
15143 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15144 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015145 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015146 ASSERT_VK_SUCCESS(err);
15147
Tony Barbour552f6c02016-12-21 14:34:07 -070015148 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015149 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015150 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015151 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015152 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015153 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015154 copyRegion.srcOffset.x = 0;
15155 copyRegion.srcOffset.y = 0;
15156 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015157 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015158 copyRegion.dstSubresource.mipLevel = 0;
15159 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015160 // Introduce failure by forcing the dst layerCount to differ from src
15161 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015162 copyRegion.dstOffset.x = 0;
15163 copyRegion.dstOffset.y = 0;
15164 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015165 copyRegion.extent.width = 1;
15166 copyRegion.extent.height = 1;
15167 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015168 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015169 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015170
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015171 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015172
Chia-I Wuf7458c52015-10-26 21:10:41 +080015173 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015174 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015175 vkFreeMemory(m_device->device(), srcMem, NULL);
15176 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015177}
15178
Tony Barbourd6673642016-05-05 14:46:39 -060015179TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015180 TEST_DESCRIPTION("Creating images with unsuported formats ");
15181
15182 ASSERT_NO_FATAL_FAILURE(InitState());
15183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15184 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015185 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 -060015186 VK_IMAGE_TILING_OPTIMAL, 0);
15187 ASSERT_TRUE(image.initialized());
15188
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015189 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015190 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015191 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015192 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15193 image_create_info.format = VK_FORMAT_UNDEFINED;
15194 image_create_info.extent.width = 32;
15195 image_create_info.extent.height = 32;
15196 image_create_info.extent.depth = 1;
15197 image_create_info.mipLevels = 1;
15198 image_create_info.arrayLayers = 1;
15199 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15200 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15201 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015202
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15204 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015205
15206 VkImage localImage;
15207 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15208 m_errorMonitor->VerifyFound();
15209
Tony Barbourd6673642016-05-05 14:46:39 -060015210 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015211 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015212 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15213 VkFormat format = static_cast<VkFormat>(f);
15214 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015215 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015216 unsupported = format;
15217 break;
15218 }
15219 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015220
Tony Barbourd6673642016-05-05 14:46:39 -060015221 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015222 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015224
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015225 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015226 m_errorMonitor->VerifyFound();
15227 }
15228}
15229
15230TEST_F(VkLayerTest, ImageLayerViewTests) {
15231 VkResult ret;
15232 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15233
15234 ASSERT_NO_FATAL_FAILURE(InitState());
15235
15236 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015237 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 -060015238 VK_IMAGE_TILING_OPTIMAL, 0);
15239 ASSERT_TRUE(image.initialized());
15240
15241 VkImageView imgView;
15242 VkImageViewCreateInfo imgViewInfo = {};
15243 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15244 imgViewInfo.image = image.handle();
15245 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15246 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15247 imgViewInfo.subresourceRange.layerCount = 1;
15248 imgViewInfo.subresourceRange.baseMipLevel = 0;
15249 imgViewInfo.subresourceRange.levelCount = 1;
15250 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15251
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015253 // View can't have baseMipLevel >= image's mipLevels - Expect
15254 // VIEW_CREATE_ERROR
15255 imgViewInfo.subresourceRange.baseMipLevel = 1;
15256 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15257 m_errorMonitor->VerifyFound();
15258 imgViewInfo.subresourceRange.baseMipLevel = 0;
15259
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015260 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015261 // View can't have baseArrayLayer >= image's arraySize - Expect
15262 // VIEW_CREATE_ERROR
15263 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15264 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15265 m_errorMonitor->VerifyFound();
15266 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15267
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015269 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15270 imgViewInfo.subresourceRange.levelCount = 0;
15271 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15272 m_errorMonitor->VerifyFound();
15273 imgViewInfo.subresourceRange.levelCount = 1;
15274
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015275 m_errorMonitor->SetDesiredFailureMsg(
15276 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15277 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015278 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15279 imgViewInfo.subresourceRange.layerCount = 0;
15280 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15281 m_errorMonitor->VerifyFound();
15282 imgViewInfo.subresourceRange.layerCount = 1;
15283
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15285 "Formats MUST be IDENTICAL unless "
15286 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15287 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015288 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15289 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15290 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15291 m_errorMonitor->VerifyFound();
15292 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15293
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015295 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15296 // VIEW_CREATE_ERROR
15297 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15298 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15299 m_errorMonitor->VerifyFound();
15300 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15301
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015302 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015303 // TODO: Update framework to easily passing mutable flag into ImageObj init
15304 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015305 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15306 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15307 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015308 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15309 // VIEW_CREATE_ERROR
15310 VkImageCreateInfo mutImgInfo = image.create_info();
15311 VkImage mutImage;
15312 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015313 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015314 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15315 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15316 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15317 ASSERT_VK_SUCCESS(ret);
15318 imgViewInfo.image = mutImage;
15319 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15320 m_errorMonitor->VerifyFound();
15321 imgViewInfo.image = image.handle();
15322 vkDestroyImage(m_device->handle(), mutImage, NULL);
15323}
15324
15325TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060015326 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15327
15328 ASSERT_NO_FATAL_FAILURE(InitState());
15329
Rene Lindsay135204f2016-12-22 17:11:09 -070015330 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060015331 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070015332 image.init(128, 128, VK_FORMAT_R16G16B16A16_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015333 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060015334 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060015335 vk_testing::Buffer buffer;
15336 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070015337 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060015338 VkBufferImageCopy region = {};
15339 region.bufferRowLength = 128;
15340 region.bufferImageHeight = 128;
15341 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15342 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070015343 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015344 region.imageExtent.height = 4;
15345 region.imageExtent.width = 4;
15346 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070015347
15348 VkImageObj image2(m_device);
15349 image2.init(128, 128, VK_FORMAT_R8G8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015350 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070015351 ASSERT_TRUE(image2.initialized());
15352 vk_testing::Buffer buffer2;
15353 VkMemoryPropertyFlags reqs2 = 0;
15354 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
15355 VkBufferImageCopy region2 = {};
15356 region2.bufferRowLength = 128;
15357 region2.bufferImageHeight = 128;
15358 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15359 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15360 region2.imageSubresource.layerCount = 1;
15361 region2.imageExtent.height = 4;
15362 region2.imageExtent.width = 4;
15363 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015364 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060015365
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015366 // Image must have offset.z of 0 and extent.depth of 1
15367 // Introduce failure by setting imageExtent.depth to 0
15368 region.imageExtent.depth = 0;
15369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15370 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015371 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015372 m_errorMonitor->VerifyFound();
15373
15374 region.imageExtent.depth = 1;
15375
15376 // Image must have offset.z of 0 and extent.depth of 1
15377 // Introduce failure by setting imageOffset.z to 4
15378 region.imageOffset.z = 4;
15379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15380 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015381 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015382 m_errorMonitor->VerifyFound();
15383
15384 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015385 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15386 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070015387 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015389 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15390 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015391 m_errorMonitor->VerifyFound();
15392
15393 // BufferOffset must be a multiple of 4
15394 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070015395 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070015397 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
15398 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015399 m_errorMonitor->VerifyFound();
15400
15401 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15402 region.bufferOffset = 0;
15403 region.imageExtent.height = 128;
15404 region.imageExtent.width = 128;
15405 // Introduce failure by setting bufferRowLength > 0 but less than width
15406 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015408 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15409 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015410 m_errorMonitor->VerifyFound();
15411
15412 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15413 region.bufferRowLength = 128;
15414 // Introduce failure by setting bufferRowHeight > 0 but less than height
15415 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015416 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015417 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15418 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015419 m_errorMonitor->VerifyFound();
15420
15421 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060015422 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015423 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
15424 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015425 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015426 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15427 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015428 VkImageBlit blitRegion = {};
15429 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15430 blitRegion.srcSubresource.baseArrayLayer = 0;
15431 blitRegion.srcSubresource.layerCount = 1;
15432 blitRegion.srcSubresource.mipLevel = 0;
15433 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15434 blitRegion.dstSubresource.baseArrayLayer = 0;
15435 blitRegion.dstSubresource.layerCount = 1;
15436 blitRegion.dstSubresource.mipLevel = 0;
15437
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015438 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
15440 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15441 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015442 m_errorMonitor->VerifyFound();
15443
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070015444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015445 VkImageMemoryBarrier img_barrier;
15446 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15447 img_barrier.pNext = NULL;
15448 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15449 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15450 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15451 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15452 img_barrier.image = image.handle();
15453 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15454 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15455 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15456 img_barrier.subresourceRange.baseArrayLayer = 0;
15457 img_barrier.subresourceRange.baseMipLevel = 0;
15458 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15459 img_barrier.subresourceRange.layerCount = 0;
15460 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015461 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15462 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015463 m_errorMonitor->VerifyFound();
15464 img_barrier.subresourceRange.layerCount = 1;
15465}
15466
15467TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060015468 TEST_DESCRIPTION("Exceed the limits of image format ");
15469
Cody Northropc31a84f2016-08-22 10:41:47 -060015470 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015472 VkImageCreateInfo image_create_info = {};
15473 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15474 image_create_info.pNext = NULL;
15475 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15476 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15477 image_create_info.extent.width = 32;
15478 image_create_info.extent.height = 32;
15479 image_create_info.extent.depth = 1;
15480 image_create_info.mipLevels = 1;
15481 image_create_info.arrayLayers = 1;
15482 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15483 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15484 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15485 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15486 image_create_info.flags = 0;
15487
15488 VkImage nullImg;
15489 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015490 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15491 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015492 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015493 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15494 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15495 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015496 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015497
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015499 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15500 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15501 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15502 m_errorMonitor->VerifyFound();
15503 image_create_info.mipLevels = 1;
15504
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015505 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015506 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15507 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15508 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15509 m_errorMonitor->VerifyFound();
15510 image_create_info.arrayLayers = 1;
15511
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015513 int samples = imgFmtProps.sampleCounts >> 1;
15514 image_create_info.samples = (VkSampleCountFlagBits)samples;
15515 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15516 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15517 m_errorMonitor->VerifyFound();
15518 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15519
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15521 "pCreateInfo->initialLayout, must be "
15522 "VK_IMAGE_LAYOUT_UNDEFINED or "
15523 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015524 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15525 // Expect INVALID_LAYOUT
15526 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15527 m_errorMonitor->VerifyFound();
15528 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15529}
15530
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015531TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015532 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015534
15535 ASSERT_NO_FATAL_FAILURE(InitState());
15536
15537 VkImageObj src_image(m_device);
15538 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15539 VkImageObj dst_image(m_device);
15540 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15541
Tony Barbour552f6c02016-12-21 14:34:07 -070015542 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015543 VkImageCopy copy_region;
15544 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15545 copy_region.srcSubresource.mipLevel = 0;
15546 copy_region.srcSubresource.baseArrayLayer = 0;
15547 copy_region.srcSubresource.layerCount = 0;
15548 copy_region.srcOffset.x = 0;
15549 copy_region.srcOffset.y = 0;
15550 copy_region.srcOffset.z = 0;
15551 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15552 copy_region.dstSubresource.mipLevel = 0;
15553 copy_region.dstSubresource.baseArrayLayer = 0;
15554 copy_region.dstSubresource.layerCount = 0;
15555 copy_region.dstOffset.x = 0;
15556 copy_region.dstOffset.y = 0;
15557 copy_region.dstOffset.z = 0;
15558 copy_region.extent.width = 64;
15559 copy_region.extent.height = 64;
15560 copy_region.extent.depth = 1;
15561 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15562 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015563 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015564
15565 m_errorMonitor->VerifyFound();
15566}
15567
15568TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015569 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015571
15572 ASSERT_NO_FATAL_FAILURE(InitState());
15573
15574 VkImageObj src_image(m_device);
15575 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15576 VkImageObj dst_image(m_device);
15577 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15578
Tony Barbour552f6c02016-12-21 14:34:07 -070015579 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015580 VkImageCopy copy_region;
15581 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15582 copy_region.srcSubresource.mipLevel = 0;
15583 copy_region.srcSubresource.baseArrayLayer = 0;
15584 copy_region.srcSubresource.layerCount = 0;
15585 copy_region.srcOffset.x = 0;
15586 copy_region.srcOffset.y = 0;
15587 copy_region.srcOffset.z = 0;
15588 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15589 copy_region.dstSubresource.mipLevel = 0;
15590 copy_region.dstSubresource.baseArrayLayer = 0;
15591 copy_region.dstSubresource.layerCount = 0;
15592 copy_region.dstOffset.x = 0;
15593 copy_region.dstOffset.y = 0;
15594 copy_region.dstOffset.z = 0;
15595 copy_region.extent.width = 64;
15596 copy_region.extent.height = 64;
15597 copy_region.extent.depth = 1;
15598 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15599 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015600 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015601
15602 m_errorMonitor->VerifyFound();
15603}
15604
Karl Schultz6addd812016-02-02 17:17:23 -070015605TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015606 VkResult err;
15607 bool pass;
15608
15609 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015611
15612 ASSERT_NO_FATAL_FAILURE(InitState());
15613
15614 // Create two images of different types and try to copy between them
15615 VkImage srcImage;
15616 VkImage dstImage;
15617 VkDeviceMemory srcMem;
15618 VkDeviceMemory destMem;
15619 VkMemoryRequirements memReqs;
15620
15621 VkImageCreateInfo image_create_info = {};
15622 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15623 image_create_info.pNext = NULL;
15624 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15625 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15626 image_create_info.extent.width = 32;
15627 image_create_info.extent.height = 32;
15628 image_create_info.extent.depth = 1;
15629 image_create_info.mipLevels = 1;
15630 image_create_info.arrayLayers = 1;
15631 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15632 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15633 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15634 image_create_info.flags = 0;
15635
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015636 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015637 ASSERT_VK_SUCCESS(err);
15638
15639 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15640 // Introduce failure by creating second image with a different-sized format.
15641 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15642
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015643 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015644 ASSERT_VK_SUCCESS(err);
15645
15646 // Allocate memory
15647 VkMemoryAllocateInfo memAlloc = {};
15648 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15649 memAlloc.pNext = NULL;
15650 memAlloc.allocationSize = 0;
15651 memAlloc.memoryTypeIndex = 0;
15652
15653 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15654 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015655 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015656 ASSERT_TRUE(pass);
15657 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15658 ASSERT_VK_SUCCESS(err);
15659
15660 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15661 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015662 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015663 ASSERT_TRUE(pass);
15664 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15665 ASSERT_VK_SUCCESS(err);
15666
15667 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15668 ASSERT_VK_SUCCESS(err);
15669 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15670 ASSERT_VK_SUCCESS(err);
15671
Tony Barbour552f6c02016-12-21 14:34:07 -070015672 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015673 VkImageCopy copyRegion;
15674 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15675 copyRegion.srcSubresource.mipLevel = 0;
15676 copyRegion.srcSubresource.baseArrayLayer = 0;
15677 copyRegion.srcSubresource.layerCount = 0;
15678 copyRegion.srcOffset.x = 0;
15679 copyRegion.srcOffset.y = 0;
15680 copyRegion.srcOffset.z = 0;
15681 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15682 copyRegion.dstSubresource.mipLevel = 0;
15683 copyRegion.dstSubresource.baseArrayLayer = 0;
15684 copyRegion.dstSubresource.layerCount = 0;
15685 copyRegion.dstOffset.x = 0;
15686 copyRegion.dstOffset.y = 0;
15687 copyRegion.dstOffset.z = 0;
15688 copyRegion.extent.width = 1;
15689 copyRegion.extent.height = 1;
15690 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015691 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015692 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015693
15694 m_errorMonitor->VerifyFound();
15695
15696 vkDestroyImage(m_device->device(), srcImage, NULL);
15697 vkDestroyImage(m_device->device(), dstImage, NULL);
15698 vkFreeMemory(m_device->device(), srcMem, NULL);
15699 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015700}
15701
Karl Schultz6addd812016-02-02 17:17:23 -070015702TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15703 VkResult err;
15704 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015705
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015706 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15708 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015709
Mike Stroyana3082432015-09-25 13:39:21 -060015710 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015711
15712 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015713 VkImage srcImage;
15714 VkImage dstImage;
15715 VkDeviceMemory srcMem;
15716 VkDeviceMemory destMem;
15717 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015718
15719 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015720 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15721 image_create_info.pNext = NULL;
15722 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15723 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15724 image_create_info.extent.width = 32;
15725 image_create_info.extent.height = 32;
15726 image_create_info.extent.depth = 1;
15727 image_create_info.mipLevels = 1;
15728 image_create_info.arrayLayers = 1;
15729 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15730 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15731 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15732 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015733
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015734 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015735 ASSERT_VK_SUCCESS(err);
15736
Karl Schultzbdb75952016-04-19 11:36:49 -060015737 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15738
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015739 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015740 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015741 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015742 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015743
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015744 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015745 ASSERT_VK_SUCCESS(err);
15746
15747 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015748 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015749 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15750 memAlloc.pNext = NULL;
15751 memAlloc.allocationSize = 0;
15752 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015753
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015754 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015755 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015756 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015757 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015758 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015759 ASSERT_VK_SUCCESS(err);
15760
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015761 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015762 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015763 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015764 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015765 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015766 ASSERT_VK_SUCCESS(err);
15767
15768 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15769 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015770 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015771 ASSERT_VK_SUCCESS(err);
15772
Tony Barbour552f6c02016-12-21 14:34:07 -070015773 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015774 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015775 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015776 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015777 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015778 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015779 copyRegion.srcOffset.x = 0;
15780 copyRegion.srcOffset.y = 0;
15781 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015782 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015783 copyRegion.dstSubresource.mipLevel = 0;
15784 copyRegion.dstSubresource.baseArrayLayer = 0;
15785 copyRegion.dstSubresource.layerCount = 0;
15786 copyRegion.dstOffset.x = 0;
15787 copyRegion.dstOffset.y = 0;
15788 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015789 copyRegion.extent.width = 1;
15790 copyRegion.extent.height = 1;
15791 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015792 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015793 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015794
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015795 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015796
Chia-I Wuf7458c52015-10-26 21:10:41 +080015797 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015798 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015799 vkFreeMemory(m_device->device(), srcMem, NULL);
15800 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015801}
15802
Karl Schultz6addd812016-02-02 17:17:23 -070015803TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15804 VkResult err;
15805 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015806
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15808 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015809
Mike Stroyana3082432015-09-25 13:39:21 -060015810 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015811
15812 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015813 VkImage srcImage;
15814 VkImage dstImage;
15815 VkDeviceMemory srcMem;
15816 VkDeviceMemory destMem;
15817 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015818
15819 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015820 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15821 image_create_info.pNext = NULL;
15822 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15823 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15824 image_create_info.extent.width = 32;
15825 image_create_info.extent.height = 1;
15826 image_create_info.extent.depth = 1;
15827 image_create_info.mipLevels = 1;
15828 image_create_info.arrayLayers = 1;
15829 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15830 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15831 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15832 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015833
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015834 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015835 ASSERT_VK_SUCCESS(err);
15836
Karl Schultz6addd812016-02-02 17:17:23 -070015837 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015839 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015840 ASSERT_VK_SUCCESS(err);
15841
15842 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015843 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015844 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15845 memAlloc.pNext = NULL;
15846 memAlloc.allocationSize = 0;
15847 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015848
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015849 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015850 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015851 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015852 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015853 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015854 ASSERT_VK_SUCCESS(err);
15855
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015856 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015857 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015858 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015859 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015860 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015861 ASSERT_VK_SUCCESS(err);
15862
15863 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15864 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015865 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015866 ASSERT_VK_SUCCESS(err);
15867
Tony Barbour552f6c02016-12-21 14:34:07 -070015868 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015869 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015870 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15871 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015872 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015873 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015874 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015875 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015876 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015877 resolveRegion.srcOffset.x = 0;
15878 resolveRegion.srcOffset.y = 0;
15879 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015880 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015881 resolveRegion.dstSubresource.mipLevel = 0;
15882 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015883 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015884 resolveRegion.dstOffset.x = 0;
15885 resolveRegion.dstOffset.y = 0;
15886 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015887 resolveRegion.extent.width = 1;
15888 resolveRegion.extent.height = 1;
15889 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015890 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015891 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015892
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015893 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015894
Chia-I Wuf7458c52015-10-26 21:10:41 +080015895 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015896 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015897 vkFreeMemory(m_device->device(), srcMem, NULL);
15898 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015899}
15900
Karl Schultz6addd812016-02-02 17:17:23 -070015901TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15902 VkResult err;
15903 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015904
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15906 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015907
Mike Stroyana3082432015-09-25 13:39:21 -060015908 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015909
Chris Forbesa7530692016-05-08 12:35:39 +120015910 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015911 VkImage srcImage;
15912 VkImage dstImage;
15913 VkDeviceMemory srcMem;
15914 VkDeviceMemory destMem;
15915 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015916
15917 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015918 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15919 image_create_info.pNext = NULL;
15920 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15921 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15922 image_create_info.extent.width = 32;
15923 image_create_info.extent.height = 1;
15924 image_create_info.extent.depth = 1;
15925 image_create_info.mipLevels = 1;
15926 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015927 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015928 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15929 // Note: Some implementations expect color attachment usage for any
15930 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015931 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015932 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015933
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015934 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015935 ASSERT_VK_SUCCESS(err);
15936
Karl Schultz6addd812016-02-02 17:17:23 -070015937 // Note: Some implementations expect color attachment usage for any
15938 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015939 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015940
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015941 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015942 ASSERT_VK_SUCCESS(err);
15943
15944 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015945 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015946 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15947 memAlloc.pNext = NULL;
15948 memAlloc.allocationSize = 0;
15949 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015950
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015951 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015952 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015953 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015954 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015955 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015956 ASSERT_VK_SUCCESS(err);
15957
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015958 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015959 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015960 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015961 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015962 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015963 ASSERT_VK_SUCCESS(err);
15964
15965 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15966 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015967 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015968 ASSERT_VK_SUCCESS(err);
15969
Tony Barbour552f6c02016-12-21 14:34:07 -070015970 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015971 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015972 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15973 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015974 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015975 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015976 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015977 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015978 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015979 resolveRegion.srcOffset.x = 0;
15980 resolveRegion.srcOffset.y = 0;
15981 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015982 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015983 resolveRegion.dstSubresource.mipLevel = 0;
15984 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015985 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015986 resolveRegion.dstOffset.x = 0;
15987 resolveRegion.dstOffset.y = 0;
15988 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015989 resolveRegion.extent.width = 1;
15990 resolveRegion.extent.height = 1;
15991 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015992 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015993 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015994
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015995 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015996
Chia-I Wuf7458c52015-10-26 21:10:41 +080015997 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015998 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015999 vkFreeMemory(m_device->device(), srcMem, NULL);
16000 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016001}
16002
Karl Schultz6addd812016-02-02 17:17:23 -070016003TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16004 VkResult err;
16005 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016006
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016008 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016009
Mike Stroyana3082432015-09-25 13:39:21 -060016010 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016011
16012 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016013 VkImage srcImage;
16014 VkImage dstImage;
16015 VkDeviceMemory srcMem;
16016 VkDeviceMemory destMem;
16017 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016018
16019 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016020 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16021 image_create_info.pNext = NULL;
16022 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16023 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16024 image_create_info.extent.width = 32;
16025 image_create_info.extent.height = 1;
16026 image_create_info.extent.depth = 1;
16027 image_create_info.mipLevels = 1;
16028 image_create_info.arrayLayers = 1;
16029 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16030 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16031 // Note: Some implementations expect color attachment usage for any
16032 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016033 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016034 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016036 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016037 ASSERT_VK_SUCCESS(err);
16038
Karl Schultz6addd812016-02-02 17:17:23 -070016039 // Set format to something other than source image
16040 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16041 // Note: Some implementations expect color attachment usage for any
16042 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016043 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016044 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016045
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016046 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016047 ASSERT_VK_SUCCESS(err);
16048
16049 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016050 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016051 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16052 memAlloc.pNext = NULL;
16053 memAlloc.allocationSize = 0;
16054 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016055
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016056 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016057 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016058 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016059 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016060 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016061 ASSERT_VK_SUCCESS(err);
16062
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016063 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016064 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016065 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016066 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016067 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016068 ASSERT_VK_SUCCESS(err);
16069
16070 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16071 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016072 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016073 ASSERT_VK_SUCCESS(err);
16074
Tony Barbour552f6c02016-12-21 14:34:07 -070016075 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016076 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016077 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16078 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016079 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016080 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016081 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016082 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016083 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016084 resolveRegion.srcOffset.x = 0;
16085 resolveRegion.srcOffset.y = 0;
16086 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016087 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016088 resolveRegion.dstSubresource.mipLevel = 0;
16089 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016090 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016091 resolveRegion.dstOffset.x = 0;
16092 resolveRegion.dstOffset.y = 0;
16093 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016094 resolveRegion.extent.width = 1;
16095 resolveRegion.extent.height = 1;
16096 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016097 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016098 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016099
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016100 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016101
Chia-I Wuf7458c52015-10-26 21:10:41 +080016102 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016103 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016104 vkFreeMemory(m_device->device(), srcMem, NULL);
16105 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016106}
16107
Karl Schultz6addd812016-02-02 17:17:23 -070016108TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16109 VkResult err;
16110 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016111
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016113 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016114
Mike Stroyana3082432015-09-25 13:39:21 -060016115 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016116
16117 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016118 VkImage srcImage;
16119 VkImage dstImage;
16120 VkDeviceMemory srcMem;
16121 VkDeviceMemory destMem;
16122 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016123
16124 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016125 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16126 image_create_info.pNext = NULL;
16127 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16128 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16129 image_create_info.extent.width = 32;
16130 image_create_info.extent.height = 1;
16131 image_create_info.extent.depth = 1;
16132 image_create_info.mipLevels = 1;
16133 image_create_info.arrayLayers = 1;
16134 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16135 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16136 // Note: Some implementations expect color attachment usage for any
16137 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016138 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016139 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016141 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016142 ASSERT_VK_SUCCESS(err);
16143
Karl Schultz6addd812016-02-02 17:17:23 -070016144 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16145 // Note: Some implementations expect color attachment usage for any
16146 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016147 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016148 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016150 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016151 ASSERT_VK_SUCCESS(err);
16152
16153 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016154 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016155 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16156 memAlloc.pNext = NULL;
16157 memAlloc.allocationSize = 0;
16158 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016159
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016160 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016161 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016162 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016163 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016164 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016165 ASSERT_VK_SUCCESS(err);
16166
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016167 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016168 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016169 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016170 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016171 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016172 ASSERT_VK_SUCCESS(err);
16173
16174 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16175 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016176 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016177 ASSERT_VK_SUCCESS(err);
16178
Tony Barbour552f6c02016-12-21 14:34:07 -070016179 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016180 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016181 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16182 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016183 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016184 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016185 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016186 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016187 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016188 resolveRegion.srcOffset.x = 0;
16189 resolveRegion.srcOffset.y = 0;
16190 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016191 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016192 resolveRegion.dstSubresource.mipLevel = 0;
16193 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016194 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016195 resolveRegion.dstOffset.x = 0;
16196 resolveRegion.dstOffset.y = 0;
16197 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016198 resolveRegion.extent.width = 1;
16199 resolveRegion.extent.height = 1;
16200 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016201 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016202 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016203
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016204 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016205
Chia-I Wuf7458c52015-10-26 21:10:41 +080016206 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016207 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016208 vkFreeMemory(m_device->device(), srcMem, NULL);
16209 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016210}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016211
Karl Schultz6addd812016-02-02 17:17:23 -070016212TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016213 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016214 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16215 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016216 // The image format check comes 2nd in validation so we trigger it first,
16217 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016218 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16221 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016222
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016223 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016224
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016225 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016226 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16227 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016228
16229 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016230 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16231 ds_pool_ci.pNext = NULL;
16232 ds_pool_ci.maxSets = 1;
16233 ds_pool_ci.poolSizeCount = 1;
16234 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016235
16236 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016237 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016238 ASSERT_VK_SUCCESS(err);
16239
16240 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016241 dsl_binding.binding = 0;
16242 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16243 dsl_binding.descriptorCount = 1;
16244 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16245 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016246
16247 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016248 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16249 ds_layout_ci.pNext = NULL;
16250 ds_layout_ci.bindingCount = 1;
16251 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016252 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016253 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016254 ASSERT_VK_SUCCESS(err);
16255
16256 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016257 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016258 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016259 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016260 alloc_info.descriptorPool = ds_pool;
16261 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016262 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016263 ASSERT_VK_SUCCESS(err);
16264
Karl Schultz6addd812016-02-02 17:17:23 -070016265 VkImage image_bad;
16266 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016267 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016268 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016269 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016270 const int32_t tex_width = 32;
16271 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016272
16273 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016274 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16275 image_create_info.pNext = NULL;
16276 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16277 image_create_info.format = tex_format_bad;
16278 image_create_info.extent.width = tex_width;
16279 image_create_info.extent.height = tex_height;
16280 image_create_info.extent.depth = 1;
16281 image_create_info.mipLevels = 1;
16282 image_create_info.arrayLayers = 1;
16283 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16284 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016285 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016286 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016287
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016288 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016289 ASSERT_VK_SUCCESS(err);
16290 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016291 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16292 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016293 ASSERT_VK_SUCCESS(err);
16294
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016295 // ---Bind image memory---
16296 VkMemoryRequirements img_mem_reqs;
16297 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
16298 VkMemoryAllocateInfo image_alloc_info = {};
16299 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16300 image_alloc_info.pNext = NULL;
16301 image_alloc_info.memoryTypeIndex = 0;
16302 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016303 bool pass =
16304 m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &image_alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016305 ASSERT_TRUE(pass);
16306 VkDeviceMemory mem;
16307 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
16308 ASSERT_VK_SUCCESS(err);
16309 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
16310 ASSERT_VK_SUCCESS(err);
16311 // -----------------------
16312
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016313 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016314 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016315 image_view_create_info.image = image_bad;
16316 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16317 image_view_create_info.format = tex_format_bad;
16318 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16319 image_view_create_info.subresourceRange.baseMipLevel = 0;
16320 image_view_create_info.subresourceRange.layerCount = 1;
16321 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016322 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016323
16324 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016325 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016326
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016327 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016328
Chia-I Wuf7458c52015-10-26 21:10:41 +080016329 vkDestroyImage(m_device->device(), image_bad, NULL);
16330 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016331 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16332 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016333
16334 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016335}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016336
16337TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016338 TEST_DESCRIPTION(
16339 "Call ClearColorImage w/ a depth|stencil image and "
16340 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016341
16342 ASSERT_NO_FATAL_FAILURE(InitState());
16343 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16344
Tony Barbour552f6c02016-12-21 14:34:07 -070016345 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016346
16347 // Color image
16348 VkClearColorValue clear_color;
16349 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16350 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16351 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16352 const int32_t img_width = 32;
16353 const int32_t img_height = 32;
16354 VkImageCreateInfo image_create_info = {};
16355 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16356 image_create_info.pNext = NULL;
16357 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16358 image_create_info.format = color_format;
16359 image_create_info.extent.width = img_width;
16360 image_create_info.extent.height = img_height;
16361 image_create_info.extent.depth = 1;
16362 image_create_info.mipLevels = 1;
16363 image_create_info.arrayLayers = 1;
16364 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16365 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16366 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16367
16368 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016369 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016370
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016371 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016372
16373 // Depth/Stencil image
16374 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016375 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016376 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16377 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16378 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16379 ds_image_create_info.extent.width = 64;
16380 ds_image_create_info.extent.height = 64;
16381 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016382 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 -060016383
16384 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016385 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016387 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 -060016388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016391 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016392 &color_range);
16393
16394 m_errorMonitor->VerifyFound();
16395
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016396 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16397 "vkCmdClearColorImage called with "
16398 "image created without "
16399 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016400
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016401 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016402 &color_range);
16403
16404 m_errorMonitor->VerifyFound();
16405
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016406 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016407 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16408 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016409
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016410 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
16411 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016412
16413 m_errorMonitor->VerifyFound();
16414}
Tobin Ehliscde08892015-09-22 10:11:37 -060016415
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016416// WSI Enabled Tests
16417//
Chris Forbes09368e42016-10-13 11:59:22 +130016418#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016419TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
16420
16421#if defined(VK_USE_PLATFORM_XCB_KHR)
16422 VkSurfaceKHR surface = VK_NULL_HANDLE;
16423
16424 VkResult err;
16425 bool pass;
16426 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
16427 VkSwapchainCreateInfoKHR swapchain_create_info = {};
16428 // uint32_t swapchain_image_count = 0;
16429 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
16430 // uint32_t image_index = 0;
16431 // VkPresentInfoKHR present_info = {};
16432
16433 ASSERT_NO_FATAL_FAILURE(InitState());
16434
16435 // Use the create function from one of the VK_KHR_*_surface extension in
16436 // order to create a surface, testing all known errors in the process,
16437 // before successfully creating a surface:
16438 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
16439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
16440 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
16441 pass = (err != VK_SUCCESS);
16442 ASSERT_TRUE(pass);
16443 m_errorMonitor->VerifyFound();
16444
16445 // Next, try to create a surface with the wrong
16446 // VkXcbSurfaceCreateInfoKHR::sType:
16447 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
16448 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16450 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16451 pass = (err != VK_SUCCESS);
16452 ASSERT_TRUE(pass);
16453 m_errorMonitor->VerifyFound();
16454
16455 // Create a native window, and then correctly create a surface:
16456 xcb_connection_t *connection;
16457 xcb_screen_t *screen;
16458 xcb_window_t xcb_window;
16459 xcb_intern_atom_reply_t *atom_wm_delete_window;
16460
16461 const xcb_setup_t *setup;
16462 xcb_screen_iterator_t iter;
16463 int scr;
16464 uint32_t value_mask, value_list[32];
16465 int width = 1;
16466 int height = 1;
16467
16468 connection = xcb_connect(NULL, &scr);
16469 ASSERT_TRUE(connection != NULL);
16470 setup = xcb_get_setup(connection);
16471 iter = xcb_setup_roots_iterator(setup);
16472 while (scr-- > 0)
16473 xcb_screen_next(&iter);
16474 screen = iter.data;
16475
16476 xcb_window = xcb_generate_id(connection);
16477
16478 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16479 value_list[0] = screen->black_pixel;
16480 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16481
16482 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16483 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16484
16485 /* Magic code that will send notification when window is destroyed */
16486 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16487 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16488
16489 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16490 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16491 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16492 free(reply);
16493
16494 xcb_map_window(connection, xcb_window);
16495
16496 // Force the x/y coordinates to 100,100 results are identical in consecutive
16497 // runs
16498 const uint32_t coords[] = { 100, 100 };
16499 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16500
16501 // Finally, try to correctly create a surface:
16502 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16503 xcb_create_info.pNext = NULL;
16504 xcb_create_info.flags = 0;
16505 xcb_create_info.connection = connection;
16506 xcb_create_info.window = xcb_window;
16507 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16508 pass = (err == VK_SUCCESS);
16509 ASSERT_TRUE(pass);
16510
16511 // Check if surface supports presentation:
16512
16513 // 1st, do so without having queried the queue families:
16514 VkBool32 supported = false;
16515 // TODO: Get the following error to come out:
16516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16517 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16518 "function");
16519 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16520 pass = (err != VK_SUCCESS);
16521 // ASSERT_TRUE(pass);
16522 // m_errorMonitor->VerifyFound();
16523
16524 // Next, query a queue family index that's too large:
16525 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16526 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16527 pass = (err != VK_SUCCESS);
16528 ASSERT_TRUE(pass);
16529 m_errorMonitor->VerifyFound();
16530
16531 // Finally, do so correctly:
16532 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16533 // SUPPORTED
16534 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16535 pass = (err == VK_SUCCESS);
16536 ASSERT_TRUE(pass);
16537
16538 // Before proceeding, try to create a swapchain without having called
16539 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16540 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16541 swapchain_create_info.pNext = NULL;
16542 swapchain_create_info.flags = 0;
16543 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16544 swapchain_create_info.surface = surface;
16545 swapchain_create_info.imageArrayLayers = 1;
16546 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16547 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16549 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16550 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16551 pass = (err != VK_SUCCESS);
16552 ASSERT_TRUE(pass);
16553 m_errorMonitor->VerifyFound();
16554
16555 // Get the surface capabilities:
16556 VkSurfaceCapabilitiesKHR surface_capabilities;
16557
16558 // Do so correctly (only error logged by this entrypoint is if the
16559 // extension isn't enabled):
16560 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16561 pass = (err == VK_SUCCESS);
16562 ASSERT_TRUE(pass);
16563
16564 // Get the surface formats:
16565 uint32_t surface_format_count;
16566
16567 // First, try without a pointer to surface_format_count:
16568 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16569 "specified as NULL");
16570 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16571 pass = (err == VK_SUCCESS);
16572 ASSERT_TRUE(pass);
16573 m_errorMonitor->VerifyFound();
16574
16575 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16576 // correctly done a 1st try (to get the count):
16577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16578 surface_format_count = 0;
16579 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16580 pass = (err == VK_SUCCESS);
16581 ASSERT_TRUE(pass);
16582 m_errorMonitor->VerifyFound();
16583
16584 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16585 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16586 pass = (err == VK_SUCCESS);
16587 ASSERT_TRUE(pass);
16588
16589 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16590 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16591
16592 // Next, do a 2nd try with surface_format_count being set too high:
16593 surface_format_count += 5;
16594 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16595 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16596 pass = (err == VK_SUCCESS);
16597 ASSERT_TRUE(pass);
16598 m_errorMonitor->VerifyFound();
16599
16600 // Finally, do a correct 1st and 2nd try:
16601 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16602 pass = (err == VK_SUCCESS);
16603 ASSERT_TRUE(pass);
16604 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16605 pass = (err == VK_SUCCESS);
16606 ASSERT_TRUE(pass);
16607
16608 // Get the surface present modes:
16609 uint32_t surface_present_mode_count;
16610
16611 // First, try without a pointer to surface_format_count:
16612 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16613 "specified as NULL");
16614
16615 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16616 pass = (err == VK_SUCCESS);
16617 ASSERT_TRUE(pass);
16618 m_errorMonitor->VerifyFound();
16619
16620 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16621 // correctly done a 1st try (to get the count):
16622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16623 surface_present_mode_count = 0;
16624 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16625 (VkPresentModeKHR *)&surface_present_mode_count);
16626 pass = (err == VK_SUCCESS);
16627 ASSERT_TRUE(pass);
16628 m_errorMonitor->VerifyFound();
16629
16630 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16631 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16632 pass = (err == VK_SUCCESS);
16633 ASSERT_TRUE(pass);
16634
16635 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16636 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16637
16638 // Next, do a 2nd try with surface_format_count being set too high:
16639 surface_present_mode_count += 5;
16640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16641 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16642 pass = (err == VK_SUCCESS);
16643 ASSERT_TRUE(pass);
16644 m_errorMonitor->VerifyFound();
16645
16646 // Finally, do a correct 1st and 2nd try:
16647 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16648 pass = (err == VK_SUCCESS);
16649 ASSERT_TRUE(pass);
16650 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16651 pass = (err == VK_SUCCESS);
16652 ASSERT_TRUE(pass);
16653
16654 // Create a swapchain:
16655
16656 // First, try without a pointer to swapchain_create_info:
16657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16658 "specified as NULL");
16659
16660 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16661 pass = (err != VK_SUCCESS);
16662 ASSERT_TRUE(pass);
16663 m_errorMonitor->VerifyFound();
16664
16665 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16666 // sType:
16667 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16669
16670 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16671 pass = (err != VK_SUCCESS);
16672 ASSERT_TRUE(pass);
16673 m_errorMonitor->VerifyFound();
16674
16675 // Next, call with a NULL swapchain pointer:
16676 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16677 swapchain_create_info.pNext = NULL;
16678 swapchain_create_info.flags = 0;
16679 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16680 "specified as NULL");
16681
16682 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16683 pass = (err != VK_SUCCESS);
16684 ASSERT_TRUE(pass);
16685 m_errorMonitor->VerifyFound();
16686
16687 // TODO: Enhance swapchain layer so that
16688 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16689
16690 // Next, call with a queue family index that's too large:
16691 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16692 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16693 swapchain_create_info.queueFamilyIndexCount = 2;
16694 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16696 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16697 pass = (err != VK_SUCCESS);
16698 ASSERT_TRUE(pass);
16699 m_errorMonitor->VerifyFound();
16700
16701 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16702 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16703 swapchain_create_info.queueFamilyIndexCount = 1;
16704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16705 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16706 "pCreateInfo->pQueueFamilyIndices).");
16707 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16708 pass = (err != VK_SUCCESS);
16709 ASSERT_TRUE(pass);
16710 m_errorMonitor->VerifyFound();
16711
16712 // Next, call with an invalid imageSharingMode:
16713 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16714 swapchain_create_info.queueFamilyIndexCount = 1;
16715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16716 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16717 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16718 pass = (err != VK_SUCCESS);
16719 ASSERT_TRUE(pass);
16720 m_errorMonitor->VerifyFound();
16721 // Fix for the future:
16722 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16723 // SUPPORTED
16724 swapchain_create_info.queueFamilyIndexCount = 0;
16725 queueFamilyIndex[0] = 0;
16726 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16727
16728 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16729 // Get the images from a swapchain:
16730 // Acquire an image from a swapchain:
16731 // Present an image to a swapchain:
16732 // Destroy the swapchain:
16733
16734 // TODOs:
16735 //
16736 // - Try destroying the device without first destroying the swapchain
16737 //
16738 // - Try destroying the device without first destroying the surface
16739 //
16740 // - Try destroying the surface without first destroying the swapchain
16741
16742 // Destroy the surface:
16743 vkDestroySurfaceKHR(instance(), surface, NULL);
16744
16745 // Tear down the window:
16746 xcb_destroy_window(connection, xcb_window);
16747 xcb_disconnect(connection);
16748
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016749#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016750 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016751#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016752}
Chris Forbes09368e42016-10-13 11:59:22 +130016753#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016754
16755//
16756// POSITIVE VALIDATION TESTS
16757//
16758// These tests do not expect to encounter ANY validation errors pass only if this is true
16759
Tobin Ehlise0006882016-11-03 10:14:28 -060016760TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016761 TEST_DESCRIPTION(
16762 "Perform an image layout transition in a secondary command buffer followed "
16763 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060016764 VkResult err;
16765 m_errorMonitor->ExpectSuccess();
16766 ASSERT_NO_FATAL_FAILURE(InitState());
16767 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16768 // Allocate a secondary and primary cmd buffer
16769 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16770 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16771 command_buffer_allocate_info.commandPool = m_commandPool;
16772 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16773 command_buffer_allocate_info.commandBufferCount = 1;
16774
16775 VkCommandBuffer secondary_command_buffer;
16776 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16777 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16778 VkCommandBuffer primary_command_buffer;
16779 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16780 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16781 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16782 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16783 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16784 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16785 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16786
16787 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16788 ASSERT_VK_SUCCESS(err);
16789 VkImageObj image(m_device);
16790 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16791 ASSERT_TRUE(image.initialized());
16792 VkImageMemoryBarrier img_barrier = {};
16793 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16794 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16795 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16796 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16797 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16798 img_barrier.image = image.handle();
16799 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16800 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16801 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16802 img_barrier.subresourceRange.baseArrayLayer = 0;
16803 img_barrier.subresourceRange.baseMipLevel = 0;
16804 img_barrier.subresourceRange.layerCount = 1;
16805 img_barrier.subresourceRange.levelCount = 1;
16806 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16807 0, nullptr, 1, &img_barrier);
16808 err = vkEndCommandBuffer(secondary_command_buffer);
16809 ASSERT_VK_SUCCESS(err);
16810
16811 // Now update primary cmd buffer to execute secondary and transitions image
16812 command_buffer_begin_info.pInheritanceInfo = nullptr;
16813 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16814 ASSERT_VK_SUCCESS(err);
16815 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16816 VkImageMemoryBarrier img_barrier2 = {};
16817 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16818 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16819 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16820 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16821 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16822 img_barrier2.image = image.handle();
16823 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16824 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16825 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16826 img_barrier2.subresourceRange.baseArrayLayer = 0;
16827 img_barrier2.subresourceRange.baseMipLevel = 0;
16828 img_barrier2.subresourceRange.layerCount = 1;
16829 img_barrier2.subresourceRange.levelCount = 1;
16830 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16831 nullptr, 1, &img_barrier2);
16832 err = vkEndCommandBuffer(primary_command_buffer);
16833 ASSERT_VK_SUCCESS(err);
16834 VkSubmitInfo submit_info = {};
16835 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16836 submit_info.commandBufferCount = 1;
16837 submit_info.pCommandBuffers = &primary_command_buffer;
16838 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16839 ASSERT_VK_SUCCESS(err);
16840 m_errorMonitor->VerifyNotFound();
16841 err = vkDeviceWaitIdle(m_device->device());
16842 ASSERT_VK_SUCCESS(err);
16843 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16844 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16845}
16846
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016847// This is a positive test. No failures are expected.
16848TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016849 TEST_DESCRIPTION(
16850 "Ensure that the vkUpdateDescriptorSets validation code "
16851 "is ignoring VkWriteDescriptorSet members that are not "
16852 "related to the descriptor type specified by "
16853 "VkWriteDescriptorSet::descriptorType. Correct "
16854 "validation behavior will result in the test running to "
16855 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016856
16857 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16858
16859 ASSERT_NO_FATAL_FAILURE(InitState());
16860
16861 // Image Case
16862 {
16863 m_errorMonitor->ExpectSuccess();
16864
16865 VkImage image;
16866 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16867 const int32_t tex_width = 32;
16868 const int32_t tex_height = 32;
16869 VkImageCreateInfo image_create_info = {};
16870 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16871 image_create_info.pNext = NULL;
16872 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16873 image_create_info.format = tex_format;
16874 image_create_info.extent.width = tex_width;
16875 image_create_info.extent.height = tex_height;
16876 image_create_info.extent.depth = 1;
16877 image_create_info.mipLevels = 1;
16878 image_create_info.arrayLayers = 1;
16879 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16880 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16881 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16882 image_create_info.flags = 0;
16883 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16884 ASSERT_VK_SUCCESS(err);
16885
16886 VkMemoryRequirements memory_reqs;
16887 VkDeviceMemory image_memory;
16888 bool pass;
16889 VkMemoryAllocateInfo memory_info = {};
16890 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16891 memory_info.pNext = NULL;
16892 memory_info.allocationSize = 0;
16893 memory_info.memoryTypeIndex = 0;
16894 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16895 memory_info.allocationSize = memory_reqs.size;
16896 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16897 ASSERT_TRUE(pass);
16898 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16899 ASSERT_VK_SUCCESS(err);
16900 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16901 ASSERT_VK_SUCCESS(err);
16902
16903 VkImageViewCreateInfo image_view_create_info = {};
16904 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16905 image_view_create_info.image = image;
16906 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16907 image_view_create_info.format = tex_format;
16908 image_view_create_info.subresourceRange.layerCount = 1;
16909 image_view_create_info.subresourceRange.baseMipLevel = 0;
16910 image_view_create_info.subresourceRange.levelCount = 1;
16911 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16912
16913 VkImageView view;
16914 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16915 ASSERT_VK_SUCCESS(err);
16916
16917 VkDescriptorPoolSize ds_type_count = {};
16918 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16919 ds_type_count.descriptorCount = 1;
16920
16921 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16922 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16923 ds_pool_ci.pNext = NULL;
16924 ds_pool_ci.maxSets = 1;
16925 ds_pool_ci.poolSizeCount = 1;
16926 ds_pool_ci.pPoolSizes = &ds_type_count;
16927
16928 VkDescriptorPool ds_pool;
16929 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16930 ASSERT_VK_SUCCESS(err);
16931
16932 VkDescriptorSetLayoutBinding dsl_binding = {};
16933 dsl_binding.binding = 0;
16934 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16935 dsl_binding.descriptorCount = 1;
16936 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16937 dsl_binding.pImmutableSamplers = NULL;
16938
16939 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16940 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16941 ds_layout_ci.pNext = NULL;
16942 ds_layout_ci.bindingCount = 1;
16943 ds_layout_ci.pBindings = &dsl_binding;
16944 VkDescriptorSetLayout ds_layout;
16945 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16946 ASSERT_VK_SUCCESS(err);
16947
16948 VkDescriptorSet descriptor_set;
16949 VkDescriptorSetAllocateInfo alloc_info = {};
16950 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16951 alloc_info.descriptorSetCount = 1;
16952 alloc_info.descriptorPool = ds_pool;
16953 alloc_info.pSetLayouts = &ds_layout;
16954 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16955 ASSERT_VK_SUCCESS(err);
16956
16957 VkDescriptorImageInfo image_info = {};
16958 image_info.imageView = view;
16959 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16960
16961 VkWriteDescriptorSet descriptor_write;
16962 memset(&descriptor_write, 0, sizeof(descriptor_write));
16963 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16964 descriptor_write.dstSet = descriptor_set;
16965 descriptor_write.dstBinding = 0;
16966 descriptor_write.descriptorCount = 1;
16967 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16968 descriptor_write.pImageInfo = &image_info;
16969
16970 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16971 // be
16972 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16973 // This will most likely produce a crash if the parameter_validation
16974 // layer
16975 // does not correctly ignore pBufferInfo.
16976 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16977 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16978
16979 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16980
16981 m_errorMonitor->VerifyNotFound();
16982
16983 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16984 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16985 vkDestroyImageView(m_device->device(), view, NULL);
16986 vkDestroyImage(m_device->device(), image, NULL);
16987 vkFreeMemory(m_device->device(), image_memory, NULL);
16988 }
16989
16990 // Buffer Case
16991 {
16992 m_errorMonitor->ExpectSuccess();
16993
16994 VkBuffer buffer;
16995 uint32_t queue_family_index = 0;
16996 VkBufferCreateInfo buffer_create_info = {};
16997 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16998 buffer_create_info.size = 1024;
16999 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17000 buffer_create_info.queueFamilyIndexCount = 1;
17001 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17002
17003 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17004 ASSERT_VK_SUCCESS(err);
17005
17006 VkMemoryRequirements memory_reqs;
17007 VkDeviceMemory buffer_memory;
17008 bool pass;
17009 VkMemoryAllocateInfo memory_info = {};
17010 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17011 memory_info.pNext = NULL;
17012 memory_info.allocationSize = 0;
17013 memory_info.memoryTypeIndex = 0;
17014
17015 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17016 memory_info.allocationSize = memory_reqs.size;
17017 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17018 ASSERT_TRUE(pass);
17019
17020 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17021 ASSERT_VK_SUCCESS(err);
17022 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17023 ASSERT_VK_SUCCESS(err);
17024
17025 VkDescriptorPoolSize ds_type_count = {};
17026 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17027 ds_type_count.descriptorCount = 1;
17028
17029 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17030 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17031 ds_pool_ci.pNext = NULL;
17032 ds_pool_ci.maxSets = 1;
17033 ds_pool_ci.poolSizeCount = 1;
17034 ds_pool_ci.pPoolSizes = &ds_type_count;
17035
17036 VkDescriptorPool ds_pool;
17037 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17038 ASSERT_VK_SUCCESS(err);
17039
17040 VkDescriptorSetLayoutBinding dsl_binding = {};
17041 dsl_binding.binding = 0;
17042 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17043 dsl_binding.descriptorCount = 1;
17044 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17045 dsl_binding.pImmutableSamplers = NULL;
17046
17047 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17048 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17049 ds_layout_ci.pNext = NULL;
17050 ds_layout_ci.bindingCount = 1;
17051 ds_layout_ci.pBindings = &dsl_binding;
17052 VkDescriptorSetLayout ds_layout;
17053 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17054 ASSERT_VK_SUCCESS(err);
17055
17056 VkDescriptorSet descriptor_set;
17057 VkDescriptorSetAllocateInfo alloc_info = {};
17058 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17059 alloc_info.descriptorSetCount = 1;
17060 alloc_info.descriptorPool = ds_pool;
17061 alloc_info.pSetLayouts = &ds_layout;
17062 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17063 ASSERT_VK_SUCCESS(err);
17064
17065 VkDescriptorBufferInfo buffer_info = {};
17066 buffer_info.buffer = buffer;
17067 buffer_info.offset = 0;
17068 buffer_info.range = 1024;
17069
17070 VkWriteDescriptorSet descriptor_write;
17071 memset(&descriptor_write, 0, sizeof(descriptor_write));
17072 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17073 descriptor_write.dstSet = descriptor_set;
17074 descriptor_write.dstBinding = 0;
17075 descriptor_write.descriptorCount = 1;
17076 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17077 descriptor_write.pBufferInfo = &buffer_info;
17078
17079 // Set pImageInfo and pTexelBufferView to invalid values, which should
17080 // be
17081 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
17082 // This will most likely produce a crash if the parameter_validation
17083 // layer
17084 // does not correctly ignore pImageInfo.
17085 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17086 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17087
17088 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17089
17090 m_errorMonitor->VerifyNotFound();
17091
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017092 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17093 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17094 vkDestroyBuffer(m_device->device(), buffer, NULL);
17095 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17096 }
17097
17098 // Texel Buffer Case
17099 {
17100 m_errorMonitor->ExpectSuccess();
17101
17102 VkBuffer buffer;
17103 uint32_t queue_family_index = 0;
17104 VkBufferCreateInfo buffer_create_info = {};
17105 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17106 buffer_create_info.size = 1024;
17107 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
17108 buffer_create_info.queueFamilyIndexCount = 1;
17109 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17110
17111 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17112 ASSERT_VK_SUCCESS(err);
17113
17114 VkMemoryRequirements memory_reqs;
17115 VkDeviceMemory buffer_memory;
17116 bool pass;
17117 VkMemoryAllocateInfo memory_info = {};
17118 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17119 memory_info.pNext = NULL;
17120 memory_info.allocationSize = 0;
17121 memory_info.memoryTypeIndex = 0;
17122
17123 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17124 memory_info.allocationSize = memory_reqs.size;
17125 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17126 ASSERT_TRUE(pass);
17127
17128 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17129 ASSERT_VK_SUCCESS(err);
17130 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17131 ASSERT_VK_SUCCESS(err);
17132
17133 VkBufferViewCreateInfo buff_view_ci = {};
17134 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
17135 buff_view_ci.buffer = buffer;
17136 buff_view_ci.format = VK_FORMAT_R8_UNORM;
17137 buff_view_ci.range = VK_WHOLE_SIZE;
17138 VkBufferView buffer_view;
17139 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
17140
17141 VkDescriptorPoolSize ds_type_count = {};
17142 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17143 ds_type_count.descriptorCount = 1;
17144
17145 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17146 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17147 ds_pool_ci.pNext = NULL;
17148 ds_pool_ci.maxSets = 1;
17149 ds_pool_ci.poolSizeCount = 1;
17150 ds_pool_ci.pPoolSizes = &ds_type_count;
17151
17152 VkDescriptorPool ds_pool;
17153 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17154 ASSERT_VK_SUCCESS(err);
17155
17156 VkDescriptorSetLayoutBinding dsl_binding = {};
17157 dsl_binding.binding = 0;
17158 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17159 dsl_binding.descriptorCount = 1;
17160 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17161 dsl_binding.pImmutableSamplers = NULL;
17162
17163 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17164 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17165 ds_layout_ci.pNext = NULL;
17166 ds_layout_ci.bindingCount = 1;
17167 ds_layout_ci.pBindings = &dsl_binding;
17168 VkDescriptorSetLayout ds_layout;
17169 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17170 ASSERT_VK_SUCCESS(err);
17171
17172 VkDescriptorSet descriptor_set;
17173 VkDescriptorSetAllocateInfo alloc_info = {};
17174 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17175 alloc_info.descriptorSetCount = 1;
17176 alloc_info.descriptorPool = ds_pool;
17177 alloc_info.pSetLayouts = &ds_layout;
17178 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17179 ASSERT_VK_SUCCESS(err);
17180
17181 VkWriteDescriptorSet descriptor_write;
17182 memset(&descriptor_write, 0, sizeof(descriptor_write));
17183 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17184 descriptor_write.dstSet = descriptor_set;
17185 descriptor_write.dstBinding = 0;
17186 descriptor_write.descriptorCount = 1;
17187 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17188 descriptor_write.pTexelBufferView = &buffer_view;
17189
17190 // Set pImageInfo and pBufferInfo to invalid values, which should be
17191 // ignored for descriptorType ==
17192 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
17193 // This will most likely produce a crash if the parameter_validation
17194 // layer
17195 // does not correctly ignore pImageInfo and pBufferInfo.
17196 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17197 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17198
17199 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17200
17201 m_errorMonitor->VerifyNotFound();
17202
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017203 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17204 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17205 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
17206 vkDestroyBuffer(m_device->device(), buffer, NULL);
17207 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17208 }
17209}
17210
Tobin Ehlisf7428442016-10-25 07:58:24 -060017211TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
17212 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
17213
17214 ASSERT_NO_FATAL_FAILURE(InitState());
17215 // Create layout where two binding #s are "1"
17216 static const uint32_t NUM_BINDINGS = 3;
17217 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17218 dsl_binding[0].binding = 1;
17219 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17220 dsl_binding[0].descriptorCount = 1;
17221 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17222 dsl_binding[0].pImmutableSamplers = NULL;
17223 dsl_binding[1].binding = 0;
17224 dsl_binding[1].descriptorCount = 1;
17225 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17226 dsl_binding[1].descriptorCount = 1;
17227 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17228 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017229 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060017230 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17231 dsl_binding[2].descriptorCount = 1;
17232 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17233 dsl_binding[2].pImmutableSamplers = NULL;
17234
17235 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17236 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17237 ds_layout_ci.pNext = NULL;
17238 ds_layout_ci.bindingCount = NUM_BINDINGS;
17239 ds_layout_ci.pBindings = dsl_binding;
17240 VkDescriptorSetLayout ds_layout;
17241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
17242 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17243 m_errorMonitor->VerifyFound();
17244}
17245
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017246TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017247 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
17248
17249 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017250
Tony Barbour552f6c02016-12-21 14:34:07 -070017251 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017252
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017253 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
17254
17255 {
17256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
17257 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
17258 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17259 m_errorMonitor->VerifyFound();
17260 }
17261
17262 {
17263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
17264 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
17265 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17266 m_errorMonitor->VerifyFound();
17267 }
17268
17269 {
17270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17271 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
17272 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17273 m_errorMonitor->VerifyFound();
17274 }
17275
17276 {
17277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17278 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
17279 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17280 m_errorMonitor->VerifyFound();
17281 }
17282
17283 {
17284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
17285 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
17286 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17287 m_errorMonitor->VerifyFound();
17288 }
17289
17290 {
17291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
17292 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
17293 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17294 m_errorMonitor->VerifyFound();
17295 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017296
17297 {
17298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17299 VkRect2D scissor = {{-1, 0}, {16, 16}};
17300 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17301 m_errorMonitor->VerifyFound();
17302 }
17303
17304 {
17305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17306 VkRect2D scissor = {{0, -2}, {16, 16}};
17307 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17308 m_errorMonitor->VerifyFound();
17309 }
17310
17311 {
17312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
17313 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
17314 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17315 m_errorMonitor->VerifyFound();
17316 }
17317
17318 {
17319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
17320 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
17321 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17322 m_errorMonitor->VerifyFound();
17323 }
17324
Tony Barbour552f6c02016-12-21 14:34:07 -070017325 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017326}
17327
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017328// This is a positive test. No failures are expected.
17329TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
17330 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
17331 VkResult err;
17332
17333 ASSERT_NO_FATAL_FAILURE(InitState());
17334 m_errorMonitor->ExpectSuccess();
17335 VkDescriptorPoolSize ds_type_count = {};
17336 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17337 ds_type_count.descriptorCount = 2;
17338
17339 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17340 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17341 ds_pool_ci.pNext = NULL;
17342 ds_pool_ci.maxSets = 1;
17343 ds_pool_ci.poolSizeCount = 1;
17344 ds_pool_ci.pPoolSizes = &ds_type_count;
17345
17346 VkDescriptorPool ds_pool;
17347 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17348 ASSERT_VK_SUCCESS(err);
17349
17350 // Create layout with two uniform buffer descriptors w/ empty binding between them
17351 static const uint32_t NUM_BINDINGS = 3;
17352 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17353 dsl_binding[0].binding = 0;
17354 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17355 dsl_binding[0].descriptorCount = 1;
17356 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
17357 dsl_binding[0].pImmutableSamplers = NULL;
17358 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017359 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017360 dsl_binding[2].binding = 2;
17361 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17362 dsl_binding[2].descriptorCount = 1;
17363 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
17364 dsl_binding[2].pImmutableSamplers = NULL;
17365
17366 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17367 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17368 ds_layout_ci.pNext = NULL;
17369 ds_layout_ci.bindingCount = NUM_BINDINGS;
17370 ds_layout_ci.pBindings = dsl_binding;
17371 VkDescriptorSetLayout ds_layout;
17372 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17373 ASSERT_VK_SUCCESS(err);
17374
17375 VkDescriptorSet descriptor_set = {};
17376 VkDescriptorSetAllocateInfo alloc_info = {};
17377 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17378 alloc_info.descriptorSetCount = 1;
17379 alloc_info.descriptorPool = ds_pool;
17380 alloc_info.pSetLayouts = &ds_layout;
17381 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17382 ASSERT_VK_SUCCESS(err);
17383
17384 // Create a buffer to be used for update
17385 VkBufferCreateInfo buff_ci = {};
17386 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17387 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17388 buff_ci.size = 256;
17389 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17390 VkBuffer buffer;
17391 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
17392 ASSERT_VK_SUCCESS(err);
17393 // Have to bind memory to buffer before descriptor update
17394 VkMemoryAllocateInfo mem_alloc = {};
17395 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17396 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017397 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017398 mem_alloc.memoryTypeIndex = 0;
17399
17400 VkMemoryRequirements mem_reqs;
17401 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17402 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
17403 if (!pass) {
17404 vkDestroyBuffer(m_device->device(), buffer, NULL);
17405 return;
17406 }
17407
17408 VkDeviceMemory mem;
17409 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17410 ASSERT_VK_SUCCESS(err);
17411 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17412 ASSERT_VK_SUCCESS(err);
17413
17414 // Only update the descriptor at binding 2
17415 VkDescriptorBufferInfo buff_info = {};
17416 buff_info.buffer = buffer;
17417 buff_info.offset = 0;
17418 buff_info.range = VK_WHOLE_SIZE;
17419 VkWriteDescriptorSet descriptor_write = {};
17420 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17421 descriptor_write.dstBinding = 2;
17422 descriptor_write.descriptorCount = 1;
17423 descriptor_write.pTexelBufferView = nullptr;
17424 descriptor_write.pBufferInfo = &buff_info;
17425 descriptor_write.pImageInfo = nullptr;
17426 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17427 descriptor_write.dstSet = descriptor_set;
17428
17429 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17430
17431 m_errorMonitor->VerifyNotFound();
17432 // Cleanup
17433 vkFreeMemory(m_device->device(), mem, NULL);
17434 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17435 vkDestroyBuffer(m_device->device(), buffer, NULL);
17436 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17437}
17438
17439// This is a positive test. No failures are expected.
17440TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
17441 VkResult err;
17442 bool pass;
17443
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017444 TEST_DESCRIPTION(
17445 "Create a buffer, allocate memory, bind memory, destroy "
17446 "the buffer, create an image, and bind the same memory to "
17447 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017448
17449 m_errorMonitor->ExpectSuccess();
17450
17451 ASSERT_NO_FATAL_FAILURE(InitState());
17452
17453 VkBuffer buffer;
17454 VkImage image;
17455 VkDeviceMemory mem;
17456 VkMemoryRequirements mem_reqs;
17457
17458 VkBufferCreateInfo buf_info = {};
17459 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17460 buf_info.pNext = NULL;
17461 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17462 buf_info.size = 256;
17463 buf_info.queueFamilyIndexCount = 0;
17464 buf_info.pQueueFamilyIndices = NULL;
17465 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17466 buf_info.flags = 0;
17467 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17468 ASSERT_VK_SUCCESS(err);
17469
17470 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17471
17472 VkMemoryAllocateInfo alloc_info = {};
17473 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17474 alloc_info.pNext = NULL;
17475 alloc_info.memoryTypeIndex = 0;
17476
17477 // Ensure memory is big enough for both bindings
17478 alloc_info.allocationSize = 0x10000;
17479
17480 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17481 if (!pass) {
17482 vkDestroyBuffer(m_device->device(), buffer, NULL);
17483 return;
17484 }
17485
17486 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17487 ASSERT_VK_SUCCESS(err);
17488
17489 uint8_t *pData;
17490 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17491 ASSERT_VK_SUCCESS(err);
17492
17493 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17494
17495 vkUnmapMemory(m_device->device(), mem);
17496
17497 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17498 ASSERT_VK_SUCCESS(err);
17499
17500 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17501 // memory. In fact, it was never used by the GPU.
17502 // Just be be sure, wait for idle.
17503 vkDestroyBuffer(m_device->device(), buffer, NULL);
17504 vkDeviceWaitIdle(m_device->device());
17505
Tobin Ehlis6a005702016-12-28 15:25:56 -070017506 // Use optimal as some platforms report linear support but then fail image creation
17507 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17508 VkImageFormatProperties image_format_properties;
17509 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17510 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17511 if (image_format_properties.maxExtent.width == 0) {
17512 printf("Image format not supported; skipped.\n");
17513 vkFreeMemory(m_device->device(), mem, NULL);
17514 return;
17515 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017516 VkImageCreateInfo image_create_info = {};
17517 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17518 image_create_info.pNext = NULL;
17519 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17520 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17521 image_create_info.extent.width = 64;
17522 image_create_info.extent.height = 64;
17523 image_create_info.extent.depth = 1;
17524 image_create_info.mipLevels = 1;
17525 image_create_info.arrayLayers = 1;
17526 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017527 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017528 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17529 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17530 image_create_info.queueFamilyIndexCount = 0;
17531 image_create_info.pQueueFamilyIndices = NULL;
17532 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17533 image_create_info.flags = 0;
17534
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017535 /* Create a mappable image. It will be the texture if linear images are ok
17536 * to be textures or it will be the staging image if they are not.
17537 */
17538 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17539 ASSERT_VK_SUCCESS(err);
17540
17541 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17542
Tobin Ehlis6a005702016-12-28 15:25:56 -070017543 VkMemoryAllocateInfo mem_alloc = {};
17544 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17545 mem_alloc.pNext = NULL;
17546 mem_alloc.allocationSize = 0;
17547 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017548 mem_alloc.allocationSize = mem_reqs.size;
17549
17550 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17551 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017552 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017553 vkDestroyImage(m_device->device(), image, NULL);
17554 return;
17555 }
17556
17557 // VALIDATION FAILURE:
17558 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17559 ASSERT_VK_SUCCESS(err);
17560
17561 m_errorMonitor->VerifyNotFound();
17562
17563 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017564 vkDestroyImage(m_device->device(), image, NULL);
17565}
17566
Tony Barbourab713912017-02-02 14:17:35 -070017567// This is a positive test. No failures are expected.
17568TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
17569 VkResult err;
17570
17571 TEST_DESCRIPTION(
17572 "Call all applicable destroy and free routines with NULL"
17573 "handles, expecting no validation errors");
17574
17575 m_errorMonitor->ExpectSuccess();
17576
17577 ASSERT_NO_FATAL_FAILURE(InitState());
17578 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
17579 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
17580 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
17581 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
17582 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
17583 vkDestroyDevice(VK_NULL_HANDLE, NULL);
17584 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
17585 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
17586 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
17587 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
17588 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
17589 vkDestroyInstance(VK_NULL_HANDLE, NULL);
17590 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
17591 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
17592 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
17593 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
17594 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
17595 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
17596 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
17597 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
17598
17599 VkCommandPool command_pool;
17600 VkCommandPoolCreateInfo pool_create_info{};
17601 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17602 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17603 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17604 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17605 VkCommandBuffer command_buffers[3] = {};
17606 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17607 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17608 command_buffer_allocate_info.commandPool = command_pool;
17609 command_buffer_allocate_info.commandBufferCount = 1;
17610 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17611 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
17612 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
17613 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17614
17615 VkDescriptorPoolSize ds_type_count = {};
17616 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17617 ds_type_count.descriptorCount = 1;
17618
17619 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17620 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17621 ds_pool_ci.pNext = NULL;
17622 ds_pool_ci.maxSets = 1;
17623 ds_pool_ci.poolSizeCount = 1;
17624 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
17625 ds_pool_ci.pPoolSizes = &ds_type_count;
17626
17627 VkDescriptorPool ds_pool;
17628 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17629 ASSERT_VK_SUCCESS(err);
17630
17631 VkDescriptorSetLayoutBinding dsl_binding = {};
17632 dsl_binding.binding = 2;
17633 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17634 dsl_binding.descriptorCount = 1;
17635 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17636 dsl_binding.pImmutableSamplers = NULL;
17637 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17638 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17639 ds_layout_ci.pNext = NULL;
17640 ds_layout_ci.bindingCount = 1;
17641 ds_layout_ci.pBindings = &dsl_binding;
17642 VkDescriptorSetLayout ds_layout;
17643 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17644 ASSERT_VK_SUCCESS(err);
17645
17646 VkDescriptorSet descriptor_sets[3] = {};
17647 VkDescriptorSetAllocateInfo alloc_info = {};
17648 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17649 alloc_info.descriptorSetCount = 1;
17650 alloc_info.descriptorPool = ds_pool;
17651 alloc_info.pSetLayouts = &ds_layout;
17652 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
17653 ASSERT_VK_SUCCESS(err);
17654 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
17655 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17656 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17657
17658 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
17659
17660 m_errorMonitor->VerifyNotFound();
17661}
17662
Tobin Ehlis953e8392016-11-17 10:54:13 -070017663TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17664 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17665 // We previously had a bug where dynamic offset of inactive bindings was still being used
17666 VkResult err;
17667 m_errorMonitor->ExpectSuccess();
17668
17669 ASSERT_NO_FATAL_FAILURE(InitState());
17670 ASSERT_NO_FATAL_FAILURE(InitViewport());
17671 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17672
17673 VkDescriptorPoolSize ds_type_count = {};
17674 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17675 ds_type_count.descriptorCount = 3;
17676
17677 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17678 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17679 ds_pool_ci.pNext = NULL;
17680 ds_pool_ci.maxSets = 1;
17681 ds_pool_ci.poolSizeCount = 1;
17682 ds_pool_ci.pPoolSizes = &ds_type_count;
17683
17684 VkDescriptorPool ds_pool;
17685 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17686 ASSERT_VK_SUCCESS(err);
17687
17688 const uint32_t BINDING_COUNT = 3;
17689 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017690 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017691 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17692 dsl_binding[0].descriptorCount = 1;
17693 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17694 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017695 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017696 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17697 dsl_binding[1].descriptorCount = 1;
17698 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17699 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017700 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017701 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17702 dsl_binding[2].descriptorCount = 1;
17703 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17704 dsl_binding[2].pImmutableSamplers = NULL;
17705
17706 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17707 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17708 ds_layout_ci.pNext = NULL;
17709 ds_layout_ci.bindingCount = BINDING_COUNT;
17710 ds_layout_ci.pBindings = dsl_binding;
17711 VkDescriptorSetLayout ds_layout;
17712 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17713 ASSERT_VK_SUCCESS(err);
17714
17715 VkDescriptorSet descriptor_set;
17716 VkDescriptorSetAllocateInfo alloc_info = {};
17717 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17718 alloc_info.descriptorSetCount = 1;
17719 alloc_info.descriptorPool = ds_pool;
17720 alloc_info.pSetLayouts = &ds_layout;
17721 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17722 ASSERT_VK_SUCCESS(err);
17723
17724 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17725 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17726 pipeline_layout_ci.pNext = NULL;
17727 pipeline_layout_ci.setLayoutCount = 1;
17728 pipeline_layout_ci.pSetLayouts = &ds_layout;
17729
17730 VkPipelineLayout pipeline_layout;
17731 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17732 ASSERT_VK_SUCCESS(err);
17733
17734 // Create two buffers to update the descriptors with
17735 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17736 uint32_t qfi = 0;
17737 VkBufferCreateInfo buffCI = {};
17738 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17739 buffCI.size = 2048;
17740 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17741 buffCI.queueFamilyIndexCount = 1;
17742 buffCI.pQueueFamilyIndices = &qfi;
17743
17744 VkBuffer dyub1;
17745 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17746 ASSERT_VK_SUCCESS(err);
17747 // buffer2
17748 buffCI.size = 1024;
17749 VkBuffer dyub2;
17750 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17751 ASSERT_VK_SUCCESS(err);
17752 // Allocate memory and bind to buffers
17753 VkMemoryAllocateInfo mem_alloc[2] = {};
17754 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17755 mem_alloc[0].pNext = NULL;
17756 mem_alloc[0].memoryTypeIndex = 0;
17757 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17758 mem_alloc[1].pNext = NULL;
17759 mem_alloc[1].memoryTypeIndex = 0;
17760
17761 VkMemoryRequirements mem_reqs1;
17762 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17763 VkMemoryRequirements mem_reqs2;
17764 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17765 mem_alloc[0].allocationSize = mem_reqs1.size;
17766 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17767 mem_alloc[1].allocationSize = mem_reqs2.size;
17768 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17769 if (!pass) {
17770 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17771 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17772 return;
17773 }
17774
17775 VkDeviceMemory mem1;
17776 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17777 ASSERT_VK_SUCCESS(err);
17778 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17779 ASSERT_VK_SUCCESS(err);
17780 VkDeviceMemory mem2;
17781 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17782 ASSERT_VK_SUCCESS(err);
17783 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17784 ASSERT_VK_SUCCESS(err);
17785 // Update descriptors
17786 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17787 buff_info[0].buffer = dyub1;
17788 buff_info[0].offset = 0;
17789 buff_info[0].range = 256;
17790 buff_info[1].buffer = dyub1;
17791 buff_info[1].offset = 256;
17792 buff_info[1].range = 512;
17793 buff_info[2].buffer = dyub2;
17794 buff_info[2].offset = 0;
17795 buff_info[2].range = 512;
17796
17797 VkWriteDescriptorSet descriptor_write;
17798 memset(&descriptor_write, 0, sizeof(descriptor_write));
17799 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17800 descriptor_write.dstSet = descriptor_set;
17801 descriptor_write.dstBinding = 0;
17802 descriptor_write.descriptorCount = BINDING_COUNT;
17803 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17804 descriptor_write.pBufferInfo = buff_info;
17805
17806 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17807
Tony Barbour552f6c02016-12-21 14:34:07 -070017808 m_commandBuffer->BeginCommandBuffer();
17809 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017810
17811 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017812 char const *vsSource =
17813 "#version 450\n"
17814 "\n"
17815 "out gl_PerVertex { \n"
17816 " vec4 gl_Position;\n"
17817 "};\n"
17818 "void main(){\n"
17819 " gl_Position = vec4(1);\n"
17820 "}\n";
17821 char const *fsSource =
17822 "#version 450\n"
17823 "\n"
17824 "layout(location=0) out vec4 x;\n"
17825 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17826 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17827 "void main(){\n"
17828 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17829 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070017830 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17831 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17832 VkPipelineObj pipe(m_device);
17833 pipe.SetViewport(m_viewports);
17834 pipe.SetScissor(m_scissors);
17835 pipe.AddShader(&vs);
17836 pipe.AddShader(&fs);
17837 pipe.AddColorAttachment();
17838 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17839
17840 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17841 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17842 // we used to have a bug in this case.
17843 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17844 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17845 &descriptor_set, BINDING_COUNT, dyn_off);
17846 Draw(1, 0, 0, 0);
17847 m_errorMonitor->VerifyNotFound();
17848
17849 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17850 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17851 vkFreeMemory(m_device->device(), mem1, NULL);
17852 vkFreeMemory(m_device->device(), mem2, NULL);
17853
17854 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17855 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17856 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17857}
17858
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017859TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017860 TEST_DESCRIPTION(
17861 "Ensure that validations handling of non-coherent memory "
17862 "mapping while using VK_WHOLE_SIZE does not cause access "
17863 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017864 VkResult err;
17865 uint8_t *pData;
17866 ASSERT_NO_FATAL_FAILURE(InitState());
17867
17868 VkDeviceMemory mem;
17869 VkMemoryRequirements mem_reqs;
17870 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017871 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017872 VkMemoryAllocateInfo alloc_info = {};
17873 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17874 alloc_info.pNext = NULL;
17875 alloc_info.memoryTypeIndex = 0;
17876
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017877 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017878 alloc_info.allocationSize = allocation_size;
17879
17880 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17881 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017882 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017883 if (!pass) {
17884 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017885 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17886 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017887 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017888 pass = m_device->phy().set_memory_type(
17889 mem_reqs.memoryTypeBits, &alloc_info,
17890 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17891 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017892 if (!pass) {
17893 return;
17894 }
17895 }
17896 }
17897
17898 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17899 ASSERT_VK_SUCCESS(err);
17900
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017901 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017902 m_errorMonitor->ExpectSuccess();
17903 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17904 ASSERT_VK_SUCCESS(err);
17905 VkMappedMemoryRange mmr = {};
17906 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17907 mmr.memory = mem;
17908 mmr.offset = 0;
17909 mmr.size = VK_WHOLE_SIZE;
17910 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17911 ASSERT_VK_SUCCESS(err);
17912 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17913 ASSERT_VK_SUCCESS(err);
17914 m_errorMonitor->VerifyNotFound();
17915 vkUnmapMemory(m_device->device(), mem);
17916
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017917 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017918 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017919 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017920 ASSERT_VK_SUCCESS(err);
17921 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17922 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017923 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017924 mmr.size = VK_WHOLE_SIZE;
17925 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17926 ASSERT_VK_SUCCESS(err);
17927 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17928 ASSERT_VK_SUCCESS(err);
17929 m_errorMonitor->VerifyNotFound();
17930 vkUnmapMemory(m_device->device(), mem);
17931
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017932 // Map with offset and size
17933 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017934 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017935 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017936 ASSERT_VK_SUCCESS(err);
17937 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17938 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017939 mmr.offset = 4 * atom_size;
17940 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017941 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17942 ASSERT_VK_SUCCESS(err);
17943 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17944 ASSERT_VK_SUCCESS(err);
17945 m_errorMonitor->VerifyNotFound();
17946 vkUnmapMemory(m_device->device(), mem);
17947
17948 // Map without offset and flush WHOLE_SIZE with two separate offsets
17949 m_errorMonitor->ExpectSuccess();
17950 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17951 ASSERT_VK_SUCCESS(err);
17952 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17953 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017954 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017955 mmr.size = VK_WHOLE_SIZE;
17956 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17957 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017958 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017959 mmr.size = VK_WHOLE_SIZE;
17960 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17961 ASSERT_VK_SUCCESS(err);
17962 m_errorMonitor->VerifyNotFound();
17963 vkUnmapMemory(m_device->device(), mem);
17964
17965 vkFreeMemory(m_device->device(), mem, NULL);
17966}
17967
17968// This is a positive test. We used to expect error in this case but spec now allows it
17969TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17970 m_errorMonitor->ExpectSuccess();
17971 vk_testing::Fence testFence;
17972 VkFenceCreateInfo fenceInfo = {};
17973 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17974 fenceInfo.pNext = NULL;
17975
17976 ASSERT_NO_FATAL_FAILURE(InitState());
17977 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017978 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017979 VkResult result = vkResetFences(m_device->device(), 1, fences);
17980 ASSERT_VK_SUCCESS(result);
17981
17982 m_errorMonitor->VerifyNotFound();
17983}
17984
17985TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17986 m_errorMonitor->ExpectSuccess();
17987
17988 ASSERT_NO_FATAL_FAILURE(InitState());
17989 VkResult err;
17990
17991 // Record (empty!) command buffer that can be submitted multiple times
17992 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017993 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17994 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017995 m_commandBuffer->BeginCommandBuffer(&cbbi);
17996 m_commandBuffer->EndCommandBuffer();
17997
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017998 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017999 VkFence fence;
18000 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
18001 ASSERT_VK_SUCCESS(err);
18002
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018003 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018004 VkSemaphore s1, s2;
18005 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
18006 ASSERT_VK_SUCCESS(err);
18007 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
18008 ASSERT_VK_SUCCESS(err);
18009
18010 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018011 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018012 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
18013 ASSERT_VK_SUCCESS(err);
18014
18015 // Submit CB again, signaling s2.
18016 si.pSignalSemaphores = &s2;
18017 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
18018 ASSERT_VK_SUCCESS(err);
18019
18020 // Wait for fence.
18021 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18022 ASSERT_VK_SUCCESS(err);
18023
18024 // CB is still in flight from second submission, but semaphore s1 is no
18025 // longer in flight. delete it.
18026 vkDestroySemaphore(m_device->device(), s1, nullptr);
18027
18028 m_errorMonitor->VerifyNotFound();
18029
18030 // Force device idle and clean up remaining objects
18031 vkDeviceWaitIdle(m_device->device());
18032 vkDestroySemaphore(m_device->device(), s2, nullptr);
18033 vkDestroyFence(m_device->device(), fence, nullptr);
18034}
18035
18036TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
18037 m_errorMonitor->ExpectSuccess();
18038
18039 ASSERT_NO_FATAL_FAILURE(InitState());
18040 VkResult err;
18041
18042 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018043 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018044 VkFence f1;
18045 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
18046 ASSERT_VK_SUCCESS(err);
18047
18048 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018049 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018050 VkFence f2;
18051 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
18052 ASSERT_VK_SUCCESS(err);
18053
18054 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018055 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018056 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
18057
18058 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018059 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018060 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
18061
18062 // Should have both retired!
18063 vkDestroyFence(m_device->device(), f1, nullptr);
18064 vkDestroyFence(m_device->device(), f2, nullptr);
18065
18066 m_errorMonitor->VerifyNotFound();
18067}
18068
18069TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018070 TEST_DESCRIPTION(
18071 "Verify that creating an image view from an image with valid usage "
18072 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018073
18074 ASSERT_NO_FATAL_FAILURE(InitState());
18075
18076 m_errorMonitor->ExpectSuccess();
18077 // Verify that we can create a view with usage INPUT_ATTACHMENT
18078 VkImageObj image(m_device);
18079 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18080 ASSERT_TRUE(image.initialized());
18081 VkImageView imageView;
18082 VkImageViewCreateInfo ivci = {};
18083 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18084 ivci.image = image.handle();
18085 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
18086 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
18087 ivci.subresourceRange.layerCount = 1;
18088 ivci.subresourceRange.baseMipLevel = 0;
18089 ivci.subresourceRange.levelCount = 1;
18090 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18091
18092 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
18093 m_errorMonitor->VerifyNotFound();
18094 vkDestroyImageView(m_device->device(), imageView, NULL);
18095}
18096
18097// This is a positive test. No failures are expected.
18098TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018099 TEST_DESCRIPTION(
18100 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
18101 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018102
18103 ASSERT_NO_FATAL_FAILURE(InitState());
18104
18105 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018106 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018107
18108 m_errorMonitor->ExpectSuccess();
18109
18110 VkImage image;
18111 VkImageCreateInfo image_create_info = {};
18112 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18113 image_create_info.pNext = NULL;
18114 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18115 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18116 image_create_info.extent.width = 64;
18117 image_create_info.extent.height = 64;
18118 image_create_info.extent.depth = 1;
18119 image_create_info.mipLevels = 1;
18120 image_create_info.arrayLayers = 1;
18121 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18122 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18123 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
18124 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
18125 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18126 ASSERT_VK_SUCCESS(err);
18127
18128 VkMemoryRequirements memory_reqs;
18129 VkDeviceMemory memory_one, memory_two;
18130 bool pass;
18131 VkMemoryAllocateInfo memory_info = {};
18132 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18133 memory_info.pNext = NULL;
18134 memory_info.allocationSize = 0;
18135 memory_info.memoryTypeIndex = 0;
18136 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18137 // Find an image big enough to allow sparse mapping of 2 memory regions
18138 // Increase the image size until it is at least twice the
18139 // size of the required alignment, to ensure we can bind both
18140 // allocated memory blocks to the image on aligned offsets.
18141 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
18142 vkDestroyImage(m_device->device(), image, nullptr);
18143 image_create_info.extent.width *= 2;
18144 image_create_info.extent.height *= 2;
18145 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
18146 ASSERT_VK_SUCCESS(err);
18147 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18148 }
18149 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
18150 // at the end of the first
18151 memory_info.allocationSize = memory_reqs.alignment;
18152 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18153 ASSERT_TRUE(pass);
18154 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
18155 ASSERT_VK_SUCCESS(err);
18156 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
18157 ASSERT_VK_SUCCESS(err);
18158 VkSparseMemoryBind binds[2];
18159 binds[0].flags = 0;
18160 binds[0].memory = memory_one;
18161 binds[0].memoryOffset = 0;
18162 binds[0].resourceOffset = 0;
18163 binds[0].size = memory_info.allocationSize;
18164 binds[1].flags = 0;
18165 binds[1].memory = memory_two;
18166 binds[1].memoryOffset = 0;
18167 binds[1].resourceOffset = memory_info.allocationSize;
18168 binds[1].size = memory_info.allocationSize;
18169
18170 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
18171 opaqueBindInfo.image = image;
18172 opaqueBindInfo.bindCount = 2;
18173 opaqueBindInfo.pBinds = binds;
18174
18175 VkFence fence = VK_NULL_HANDLE;
18176 VkBindSparseInfo bindSparseInfo = {};
18177 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
18178 bindSparseInfo.imageOpaqueBindCount = 1;
18179 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
18180
18181 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
18182 vkQueueWaitIdle(m_device->m_queue);
18183 vkDestroyImage(m_device->device(), image, NULL);
18184 vkFreeMemory(m_device->device(), memory_one, NULL);
18185 vkFreeMemory(m_device->device(), memory_two, NULL);
18186 m_errorMonitor->VerifyNotFound();
18187}
18188
18189TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018190 TEST_DESCRIPTION(
18191 "Ensure that CmdBeginRenderPass with an attachment's "
18192 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
18193 "the command buffer has prior knowledge of that "
18194 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018195
18196 m_errorMonitor->ExpectSuccess();
18197
18198 ASSERT_NO_FATAL_FAILURE(InitState());
18199
18200 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018201 VkAttachmentDescription attachment = {0,
18202 VK_FORMAT_R8G8B8A8_UNORM,
18203 VK_SAMPLE_COUNT_1_BIT,
18204 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18205 VK_ATTACHMENT_STORE_OP_STORE,
18206 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18207 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18208 VK_IMAGE_LAYOUT_UNDEFINED,
18209 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018210
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018211 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018212
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018213 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018214
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018215 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018216
18217 VkRenderPass rp;
18218 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18219 ASSERT_VK_SUCCESS(err);
18220
18221 // A compatible framebuffer.
18222 VkImageObj image(m_device);
18223 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18224 ASSERT_TRUE(image.initialized());
18225
18226 VkImageViewCreateInfo ivci = {
18227 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18228 nullptr,
18229 0,
18230 image.handle(),
18231 VK_IMAGE_VIEW_TYPE_2D,
18232 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018233 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18234 VK_COMPONENT_SWIZZLE_IDENTITY},
18235 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018236 };
18237 VkImageView view;
18238 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18239 ASSERT_VK_SUCCESS(err);
18240
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018241 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018242 VkFramebuffer fb;
18243 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18244 ASSERT_VK_SUCCESS(err);
18245
18246 // Record a single command buffer which uses this renderpass twice. The
18247 // bug is triggered at the beginning of the second renderpass, when the
18248 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018249 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 -070018250 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018251 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18252 vkCmdEndRenderPass(m_commandBuffer->handle());
18253 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18254
18255 m_errorMonitor->VerifyNotFound();
18256
18257 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018258 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018259
18260 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18261 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18262 vkDestroyImageView(m_device->device(), view, nullptr);
18263}
18264
18265TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018266 TEST_DESCRIPTION(
18267 "This test should pass. Create a Framebuffer and "
18268 "command buffer, bind them together, then destroy "
18269 "command pool and framebuffer and verify there are no "
18270 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018271
18272 m_errorMonitor->ExpectSuccess();
18273
18274 ASSERT_NO_FATAL_FAILURE(InitState());
18275
18276 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018277 VkAttachmentDescription attachment = {0,
18278 VK_FORMAT_R8G8B8A8_UNORM,
18279 VK_SAMPLE_COUNT_1_BIT,
18280 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18281 VK_ATTACHMENT_STORE_OP_STORE,
18282 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18283 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18284 VK_IMAGE_LAYOUT_UNDEFINED,
18285 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018286
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018287 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018288
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018289 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018290
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018291 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018292
18293 VkRenderPass rp;
18294 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18295 ASSERT_VK_SUCCESS(err);
18296
18297 // A compatible framebuffer.
18298 VkImageObj image(m_device);
18299 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18300 ASSERT_TRUE(image.initialized());
18301
18302 VkImageViewCreateInfo ivci = {
18303 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18304 nullptr,
18305 0,
18306 image.handle(),
18307 VK_IMAGE_VIEW_TYPE_2D,
18308 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018309 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18310 VK_COMPONENT_SWIZZLE_IDENTITY},
18311 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018312 };
18313 VkImageView view;
18314 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18315 ASSERT_VK_SUCCESS(err);
18316
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018317 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018318 VkFramebuffer fb;
18319 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18320 ASSERT_VK_SUCCESS(err);
18321
18322 // Explicitly create a command buffer to bind the FB to so that we can then
18323 // destroy the command pool in order to implicitly free command buffer
18324 VkCommandPool command_pool;
18325 VkCommandPoolCreateInfo pool_create_info{};
18326 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18327 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18328 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18329 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18330
18331 VkCommandBuffer command_buffer;
18332 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18333 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18334 command_buffer_allocate_info.commandPool = command_pool;
18335 command_buffer_allocate_info.commandBufferCount = 1;
18336 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18337 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18338
18339 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018340 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018341 VkCommandBufferBeginInfo begin_info{};
18342 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18343 vkBeginCommandBuffer(command_buffer, &begin_info);
18344
18345 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18346 vkCmdEndRenderPass(command_buffer);
18347 vkEndCommandBuffer(command_buffer);
18348 vkDestroyImageView(m_device->device(), view, nullptr);
18349 // Destroy command pool to implicitly free command buffer
18350 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18351 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18352 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18353 m_errorMonitor->VerifyNotFound();
18354}
18355
18356TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018357 TEST_DESCRIPTION(
18358 "Ensure that CmdBeginRenderPass applies the layout "
18359 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018360
18361 m_errorMonitor->ExpectSuccess();
18362
18363 ASSERT_NO_FATAL_FAILURE(InitState());
18364
18365 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018366 VkAttachmentDescription attachment = {0,
18367 VK_FORMAT_R8G8B8A8_UNORM,
18368 VK_SAMPLE_COUNT_1_BIT,
18369 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18370 VK_ATTACHMENT_STORE_OP_STORE,
18371 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18372 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18373 VK_IMAGE_LAYOUT_UNDEFINED,
18374 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018375
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018376 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018377
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018378 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018379
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018380 VkSubpassDependency dep = {0,
18381 0,
18382 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18383 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18384 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18385 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18386 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018387
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018388 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018389
18390 VkResult err;
18391 VkRenderPass rp;
18392 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18393 ASSERT_VK_SUCCESS(err);
18394
18395 // A compatible framebuffer.
18396 VkImageObj image(m_device);
18397 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18398 ASSERT_TRUE(image.initialized());
18399
18400 VkImageViewCreateInfo ivci = {
18401 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18402 nullptr,
18403 0,
18404 image.handle(),
18405 VK_IMAGE_VIEW_TYPE_2D,
18406 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018407 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18408 VK_COMPONENT_SWIZZLE_IDENTITY},
18409 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018410 };
18411 VkImageView view;
18412 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18413 ASSERT_VK_SUCCESS(err);
18414
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018415 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018416 VkFramebuffer fb;
18417 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18418 ASSERT_VK_SUCCESS(err);
18419
18420 // Record a single command buffer which issues a pipeline barrier w/
18421 // image memory barrier for the attachment. This detects the previously
18422 // missing tracking of the subpass layout by throwing a validation error
18423 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018424 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 -070018425 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018426 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18427
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018428 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
18429 nullptr,
18430 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18431 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18432 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18433 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18434 VK_QUEUE_FAMILY_IGNORED,
18435 VK_QUEUE_FAMILY_IGNORED,
18436 image.handle(),
18437 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018438 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018439 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18440 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018441
18442 vkCmdEndRenderPass(m_commandBuffer->handle());
18443 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018444 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018445
18446 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18447 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18448 vkDestroyImageView(m_device->device(), view, nullptr);
18449}
18450
18451TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018452 TEST_DESCRIPTION(
18453 "Validate that when an imageView of a depth/stencil image "
18454 "is used as a depth/stencil framebuffer attachment, the "
18455 "aspectMask is ignored and both depth and stencil image "
18456 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018457
18458 VkFormatProperties format_properties;
18459 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
18460 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
18461 return;
18462 }
18463
18464 m_errorMonitor->ExpectSuccess();
18465
18466 ASSERT_NO_FATAL_FAILURE(InitState());
18467
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018468 VkAttachmentDescription attachment = {0,
18469 VK_FORMAT_D32_SFLOAT_S8_UINT,
18470 VK_SAMPLE_COUNT_1_BIT,
18471 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18472 VK_ATTACHMENT_STORE_OP_STORE,
18473 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18474 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18475 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
18476 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018477
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018478 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018479
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018480 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018481
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018482 VkSubpassDependency dep = {0,
18483 0,
18484 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18485 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18486 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18487 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18488 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018489
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018490 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018491
18492 VkResult err;
18493 VkRenderPass rp;
18494 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18495 ASSERT_VK_SUCCESS(err);
18496
18497 VkImageObj image(m_device);
18498 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018499 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018500 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018501 ASSERT_TRUE(image.initialized());
18502 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
18503
18504 VkImageViewCreateInfo ivci = {
18505 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18506 nullptr,
18507 0,
18508 image.handle(),
18509 VK_IMAGE_VIEW_TYPE_2D,
18510 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018511 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
18512 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018513 };
18514 VkImageView view;
18515 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18516 ASSERT_VK_SUCCESS(err);
18517
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018518 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018519 VkFramebuffer fb;
18520 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18521 ASSERT_VK_SUCCESS(err);
18522
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018523 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 -070018524 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018525 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18526
18527 VkImageMemoryBarrier imb = {};
18528 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18529 imb.pNext = nullptr;
18530 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18531 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18532 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18533 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18534 imb.srcQueueFamilyIndex = 0;
18535 imb.dstQueueFamilyIndex = 0;
18536 imb.image = image.handle();
18537 imb.subresourceRange.aspectMask = 0x6;
18538 imb.subresourceRange.baseMipLevel = 0;
18539 imb.subresourceRange.levelCount = 0x1;
18540 imb.subresourceRange.baseArrayLayer = 0;
18541 imb.subresourceRange.layerCount = 0x1;
18542
18543 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018544 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18545 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018546
18547 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018548 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018549 QueueCommandBuffer(false);
18550 m_errorMonitor->VerifyNotFound();
18551
18552 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18553 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18554 vkDestroyImageView(m_device->device(), view, nullptr);
18555}
18556
18557TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018558 TEST_DESCRIPTION(
18559 "Ensure that layout transitions work correctly without "
18560 "errors, when an attachment reference is "
18561 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018562
18563 m_errorMonitor->ExpectSuccess();
18564
18565 ASSERT_NO_FATAL_FAILURE(InitState());
18566
18567 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018568 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018569
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018570 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018571
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018572 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018573
18574 VkRenderPass rp;
18575 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18576 ASSERT_VK_SUCCESS(err);
18577
18578 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018579 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018580 VkFramebuffer fb;
18581 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18582 ASSERT_VK_SUCCESS(err);
18583
18584 // Record a command buffer which just begins and ends the renderpass. The
18585 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018586 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 -070018587 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018588 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18589 vkCmdEndRenderPass(m_commandBuffer->handle());
18590 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018591 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018592
18593 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18594 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18595}
18596
18597// This is a positive test. No errors are expected.
18598TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018599 TEST_DESCRIPTION(
18600 "Create a stencil-only attachment with a LOAD_OP set to "
18601 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018602 VkResult result = VK_SUCCESS;
18603 VkImageFormatProperties formatProps;
18604 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018605 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18606 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018607 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18608 return;
18609 }
18610
18611 ASSERT_NO_FATAL_FAILURE(InitState());
18612 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18613 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018614 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018615 VkAttachmentDescription att = {};
18616 VkAttachmentReference ref = {};
18617 att.format = depth_stencil_fmt;
18618 att.samples = VK_SAMPLE_COUNT_1_BIT;
18619 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18620 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18621 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18622 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18623 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18624 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18625
18626 VkClearValue clear;
18627 clear.depthStencil.depth = 1.0;
18628 clear.depthStencil.stencil = 0;
18629 ref.attachment = 0;
18630 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18631
18632 VkSubpassDescription subpass = {};
18633 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18634 subpass.flags = 0;
18635 subpass.inputAttachmentCount = 0;
18636 subpass.pInputAttachments = NULL;
18637 subpass.colorAttachmentCount = 0;
18638 subpass.pColorAttachments = NULL;
18639 subpass.pResolveAttachments = NULL;
18640 subpass.pDepthStencilAttachment = &ref;
18641 subpass.preserveAttachmentCount = 0;
18642 subpass.pPreserveAttachments = NULL;
18643
18644 VkRenderPass rp;
18645 VkRenderPassCreateInfo rp_info = {};
18646 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18647 rp_info.attachmentCount = 1;
18648 rp_info.pAttachments = &att;
18649 rp_info.subpassCount = 1;
18650 rp_info.pSubpasses = &subpass;
18651 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18652 ASSERT_VK_SUCCESS(result);
18653
18654 VkImageView *depthView = m_depthStencil->BindInfo();
18655 VkFramebufferCreateInfo fb_info = {};
18656 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18657 fb_info.pNext = NULL;
18658 fb_info.renderPass = rp;
18659 fb_info.attachmentCount = 1;
18660 fb_info.pAttachments = depthView;
18661 fb_info.width = 100;
18662 fb_info.height = 100;
18663 fb_info.layers = 1;
18664 VkFramebuffer fb;
18665 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18666 ASSERT_VK_SUCCESS(result);
18667
18668 VkRenderPassBeginInfo rpbinfo = {};
18669 rpbinfo.clearValueCount = 1;
18670 rpbinfo.pClearValues = &clear;
18671 rpbinfo.pNext = NULL;
18672 rpbinfo.renderPass = rp;
18673 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18674 rpbinfo.renderArea.extent.width = 100;
18675 rpbinfo.renderArea.extent.height = 100;
18676 rpbinfo.renderArea.offset.x = 0;
18677 rpbinfo.renderArea.offset.y = 0;
18678 rpbinfo.framebuffer = fb;
18679
18680 VkFence fence = {};
18681 VkFenceCreateInfo fence_ci = {};
18682 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18683 fence_ci.pNext = nullptr;
18684 fence_ci.flags = 0;
18685 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18686 ASSERT_VK_SUCCESS(result);
18687
18688 m_commandBuffer->BeginCommandBuffer();
18689 m_commandBuffer->BeginRenderPass(rpbinfo);
18690 m_commandBuffer->EndRenderPass();
18691 m_commandBuffer->EndCommandBuffer();
18692 m_commandBuffer->QueueCommandBuffer(fence);
18693
18694 VkImageObj destImage(m_device);
18695 destImage.init(100, 100, depth_stencil_fmt, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018696 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018697 VkImageMemoryBarrier barrier = {};
18698 VkImageSubresourceRange range;
18699 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18700 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18701 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18702 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18703 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18704 barrier.image = m_depthStencil->handle();
18705 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18706 range.baseMipLevel = 0;
18707 range.levelCount = 1;
18708 range.baseArrayLayer = 0;
18709 range.layerCount = 1;
18710 barrier.subresourceRange = range;
18711 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18712 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18713 cmdbuf.BeginCommandBuffer();
18714 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018715 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018716 barrier.srcAccessMask = 0;
18717 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18718 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18719 barrier.image = destImage.handle();
18720 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18721 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018722 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018723 VkImageCopy cregion;
18724 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18725 cregion.srcSubresource.mipLevel = 0;
18726 cregion.srcSubresource.baseArrayLayer = 0;
18727 cregion.srcSubresource.layerCount = 1;
18728 cregion.srcOffset.x = 0;
18729 cregion.srcOffset.y = 0;
18730 cregion.srcOffset.z = 0;
18731 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18732 cregion.dstSubresource.mipLevel = 0;
18733 cregion.dstSubresource.baseArrayLayer = 0;
18734 cregion.dstSubresource.layerCount = 1;
18735 cregion.dstOffset.x = 0;
18736 cregion.dstOffset.y = 0;
18737 cregion.dstOffset.z = 0;
18738 cregion.extent.width = 100;
18739 cregion.extent.height = 100;
18740 cregion.extent.depth = 1;
18741 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018742 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018743 cmdbuf.EndCommandBuffer();
18744
18745 VkSubmitInfo submit_info;
18746 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18747 submit_info.pNext = NULL;
18748 submit_info.waitSemaphoreCount = 0;
18749 submit_info.pWaitSemaphores = NULL;
18750 submit_info.pWaitDstStageMask = NULL;
18751 submit_info.commandBufferCount = 1;
18752 submit_info.pCommandBuffers = &cmdbuf.handle();
18753 submit_info.signalSemaphoreCount = 0;
18754 submit_info.pSignalSemaphores = NULL;
18755
18756 m_errorMonitor->ExpectSuccess();
18757 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18758 m_errorMonitor->VerifyNotFound();
18759
18760 vkQueueWaitIdle(m_device->m_queue);
18761 vkDestroyFence(m_device->device(), fence, nullptr);
18762 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18763 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18764}
18765
18766// This is a positive test. No errors should be generated.
18767TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18768 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18769
18770 m_errorMonitor->ExpectSuccess();
18771 ASSERT_NO_FATAL_FAILURE(InitState());
18772
18773 VkEvent event;
18774 VkEventCreateInfo event_create_info{};
18775 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18776 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18777
18778 VkCommandPool command_pool;
18779 VkCommandPoolCreateInfo pool_create_info{};
18780 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18781 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18782 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18783 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18784
18785 VkCommandBuffer command_buffer;
18786 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18787 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18788 command_buffer_allocate_info.commandPool = command_pool;
18789 command_buffer_allocate_info.commandBufferCount = 1;
18790 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18791 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18792
18793 VkQueue queue = VK_NULL_HANDLE;
18794 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18795
18796 {
18797 VkCommandBufferBeginInfo begin_info{};
18798 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18799 vkBeginCommandBuffer(command_buffer, &begin_info);
18800
18801 vkCmdWaitEvents(command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018802 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018803 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18804 vkEndCommandBuffer(command_buffer);
18805 }
18806 {
18807 VkSubmitInfo submit_info{};
18808 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18809 submit_info.commandBufferCount = 1;
18810 submit_info.pCommandBuffers = &command_buffer;
18811 submit_info.signalSemaphoreCount = 0;
18812 submit_info.pSignalSemaphores = nullptr;
18813 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18814 }
18815 { vkSetEvent(m_device->device(), event); }
18816
18817 vkQueueWaitIdle(queue);
18818
18819 vkDestroyEvent(m_device->device(), event, nullptr);
18820 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18821 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18822
18823 m_errorMonitor->VerifyNotFound();
18824}
18825// This is a positive test. No errors should be generated.
18826TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18827 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18828
18829 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018830 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018831
18832 m_errorMonitor->ExpectSuccess();
18833
18834 VkQueryPool query_pool;
18835 VkQueryPoolCreateInfo query_pool_create_info{};
18836 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18837 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18838 query_pool_create_info.queryCount = 1;
18839 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18840
18841 VkCommandPool command_pool;
18842 VkCommandPoolCreateInfo pool_create_info{};
18843 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18844 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18845 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18846 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18847
18848 VkCommandBuffer command_buffer;
18849 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18850 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18851 command_buffer_allocate_info.commandPool = command_pool;
18852 command_buffer_allocate_info.commandBufferCount = 1;
18853 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18854 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18855
18856 VkCommandBuffer secondary_command_buffer;
18857 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18858 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18859
18860 VkQueue queue = VK_NULL_HANDLE;
18861 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18862
18863 uint32_t qfi = 0;
18864 VkBufferCreateInfo buff_create_info = {};
18865 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18866 buff_create_info.size = 1024;
18867 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18868 buff_create_info.queueFamilyIndexCount = 1;
18869 buff_create_info.pQueueFamilyIndices = &qfi;
18870
18871 VkResult err;
18872 VkBuffer buffer;
18873 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18874 ASSERT_VK_SUCCESS(err);
18875 VkMemoryAllocateInfo mem_alloc = {};
18876 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18877 mem_alloc.pNext = NULL;
18878 mem_alloc.allocationSize = 1024;
18879 mem_alloc.memoryTypeIndex = 0;
18880
18881 VkMemoryRequirements memReqs;
18882 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18883 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18884 if (!pass) {
18885 vkDestroyBuffer(m_device->device(), buffer, NULL);
18886 return;
18887 }
18888
18889 VkDeviceMemory mem;
18890 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18891 ASSERT_VK_SUCCESS(err);
18892 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18893 ASSERT_VK_SUCCESS(err);
18894
18895 VkCommandBufferInheritanceInfo hinfo = {};
18896 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18897 hinfo.renderPass = VK_NULL_HANDLE;
18898 hinfo.subpass = 0;
18899 hinfo.framebuffer = VK_NULL_HANDLE;
18900 hinfo.occlusionQueryEnable = VK_FALSE;
18901 hinfo.queryFlags = 0;
18902 hinfo.pipelineStatistics = 0;
18903
18904 {
18905 VkCommandBufferBeginInfo begin_info{};
18906 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18907 begin_info.pInheritanceInfo = &hinfo;
18908 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18909
18910 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18911 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18912
18913 vkEndCommandBuffer(secondary_command_buffer);
18914
18915 begin_info.pInheritanceInfo = nullptr;
18916 vkBeginCommandBuffer(command_buffer, &begin_info);
18917
18918 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18919 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18920
18921 vkEndCommandBuffer(command_buffer);
18922 }
18923 {
18924 VkSubmitInfo submit_info{};
18925 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18926 submit_info.commandBufferCount = 1;
18927 submit_info.pCommandBuffers = &command_buffer;
18928 submit_info.signalSemaphoreCount = 0;
18929 submit_info.pSignalSemaphores = nullptr;
18930 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18931 }
18932
18933 vkQueueWaitIdle(queue);
18934
18935 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18936 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18937 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18938 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18939 vkDestroyBuffer(m_device->device(), buffer, NULL);
18940 vkFreeMemory(m_device->device(), mem, NULL);
18941
18942 m_errorMonitor->VerifyNotFound();
18943}
18944
18945// This is a positive test. No errors should be generated.
18946TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18947 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18948
18949 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018950 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018951
18952 m_errorMonitor->ExpectSuccess();
18953
18954 VkQueryPool query_pool;
18955 VkQueryPoolCreateInfo query_pool_create_info{};
18956 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18957 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18958 query_pool_create_info.queryCount = 1;
18959 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18960
18961 VkCommandPool command_pool;
18962 VkCommandPoolCreateInfo pool_create_info{};
18963 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18964 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18965 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18966 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18967
18968 VkCommandBuffer command_buffer[2];
18969 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18970 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18971 command_buffer_allocate_info.commandPool = command_pool;
18972 command_buffer_allocate_info.commandBufferCount = 2;
18973 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18974 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18975
18976 VkQueue queue = VK_NULL_HANDLE;
18977 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18978
18979 uint32_t qfi = 0;
18980 VkBufferCreateInfo buff_create_info = {};
18981 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18982 buff_create_info.size = 1024;
18983 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18984 buff_create_info.queueFamilyIndexCount = 1;
18985 buff_create_info.pQueueFamilyIndices = &qfi;
18986
18987 VkResult err;
18988 VkBuffer buffer;
18989 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18990 ASSERT_VK_SUCCESS(err);
18991 VkMemoryAllocateInfo mem_alloc = {};
18992 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18993 mem_alloc.pNext = NULL;
18994 mem_alloc.allocationSize = 1024;
18995 mem_alloc.memoryTypeIndex = 0;
18996
18997 VkMemoryRequirements memReqs;
18998 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18999 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19000 if (!pass) {
19001 vkDestroyBuffer(m_device->device(), buffer, NULL);
19002 return;
19003 }
19004
19005 VkDeviceMemory mem;
19006 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19007 ASSERT_VK_SUCCESS(err);
19008 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19009 ASSERT_VK_SUCCESS(err);
19010
19011 {
19012 VkCommandBufferBeginInfo begin_info{};
19013 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19014 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19015
19016 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
19017 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
19018
19019 vkEndCommandBuffer(command_buffer[0]);
19020
19021 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19022
19023 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
19024
19025 vkEndCommandBuffer(command_buffer[1]);
19026 }
19027 {
19028 VkSubmitInfo submit_info{};
19029 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19030 submit_info.commandBufferCount = 2;
19031 submit_info.pCommandBuffers = command_buffer;
19032 submit_info.signalSemaphoreCount = 0;
19033 submit_info.pSignalSemaphores = nullptr;
19034 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19035 }
19036
19037 vkQueueWaitIdle(queue);
19038
19039 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
19040 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
19041 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19042 vkDestroyBuffer(m_device->device(), buffer, NULL);
19043 vkFreeMemory(m_device->device(), mem, NULL);
19044
19045 m_errorMonitor->VerifyNotFound();
19046}
19047
Tony Barbourc46924f2016-11-04 11:49:52 -060019048TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019049 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
19050
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019051 ASSERT_NO_FATAL_FAILURE(InitState());
19052 VkEvent event;
19053 VkEventCreateInfo event_create_info{};
19054 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19055 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19056
19057 VkCommandPool command_pool;
19058 VkCommandPoolCreateInfo pool_create_info{};
19059 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19060 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19061 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19062 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19063
19064 VkCommandBuffer command_buffer;
19065 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19066 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19067 command_buffer_allocate_info.commandPool = command_pool;
19068 command_buffer_allocate_info.commandBufferCount = 1;
19069 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19070 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19071
19072 VkQueue queue = VK_NULL_HANDLE;
19073 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19074
19075 {
19076 VkCommandBufferBeginInfo begin_info{};
19077 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19078 vkBeginCommandBuffer(command_buffer, &begin_info);
19079
19080 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019081 vkEndCommandBuffer(command_buffer);
19082 }
19083 {
19084 VkSubmitInfo submit_info{};
19085 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19086 submit_info.commandBufferCount = 1;
19087 submit_info.pCommandBuffers = &command_buffer;
19088 submit_info.signalSemaphoreCount = 0;
19089 submit_info.pSignalSemaphores = nullptr;
19090 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19091 }
19092 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19094 "that is already in use by a "
19095 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019096 vkSetEvent(m_device->device(), event);
19097 m_errorMonitor->VerifyFound();
19098 }
19099
19100 vkQueueWaitIdle(queue);
19101
19102 vkDestroyEvent(m_device->device(), event, nullptr);
19103 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19104 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19105}
19106
19107// This is a positive test. No errors should be generated.
19108TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019109 TEST_DESCRIPTION(
19110 "Two command buffers with two separate fences are each "
19111 "run through a Submit & WaitForFences cycle 3 times. This "
19112 "previously revealed a bug so running this positive test "
19113 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019114 m_errorMonitor->ExpectSuccess();
19115
19116 ASSERT_NO_FATAL_FAILURE(InitState());
19117 VkQueue queue = VK_NULL_HANDLE;
19118 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19119
19120 static const uint32_t NUM_OBJECTS = 2;
19121 static const uint32_t NUM_FRAMES = 3;
19122 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
19123 VkFence fences[NUM_OBJECTS] = {};
19124
19125 VkCommandPool cmd_pool;
19126 VkCommandPoolCreateInfo cmd_pool_ci = {};
19127 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19128 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
19129 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19130 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
19131 ASSERT_VK_SUCCESS(err);
19132
19133 VkCommandBufferAllocateInfo cmd_buf_info = {};
19134 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19135 cmd_buf_info.commandPool = cmd_pool;
19136 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19137 cmd_buf_info.commandBufferCount = 1;
19138
19139 VkFenceCreateInfo fence_ci = {};
19140 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19141 fence_ci.pNext = nullptr;
19142 fence_ci.flags = 0;
19143
19144 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19145 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
19146 ASSERT_VK_SUCCESS(err);
19147 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
19148 ASSERT_VK_SUCCESS(err);
19149 }
19150
19151 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
19152 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
19153 // Create empty cmd buffer
19154 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
19155 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19156
19157 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
19158 ASSERT_VK_SUCCESS(err);
19159 err = vkEndCommandBuffer(cmd_buffers[obj]);
19160 ASSERT_VK_SUCCESS(err);
19161
19162 VkSubmitInfo submit_info = {};
19163 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19164 submit_info.commandBufferCount = 1;
19165 submit_info.pCommandBuffers = &cmd_buffers[obj];
19166 // Submit cmd buffer and wait for fence
19167 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
19168 ASSERT_VK_SUCCESS(err);
19169 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
19170 ASSERT_VK_SUCCESS(err);
19171 err = vkResetFences(m_device->device(), 1, &fences[obj]);
19172 ASSERT_VK_SUCCESS(err);
19173 }
19174 }
19175 m_errorMonitor->VerifyNotFound();
19176 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
19177 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19178 vkDestroyFence(m_device->device(), fences[i], nullptr);
19179 }
19180}
19181// This is a positive test. No errors should be generated.
19182TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019183 TEST_DESCRIPTION(
19184 "Two command buffers, each in a separate QueueSubmit call "
19185 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019186
19187 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019188 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019189
19190 m_errorMonitor->ExpectSuccess();
19191
19192 VkSemaphore semaphore;
19193 VkSemaphoreCreateInfo semaphore_create_info{};
19194 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19195 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19196
19197 VkCommandPool command_pool;
19198 VkCommandPoolCreateInfo pool_create_info{};
19199 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19200 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19201 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19202 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19203
19204 VkCommandBuffer command_buffer[2];
19205 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19206 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19207 command_buffer_allocate_info.commandPool = command_pool;
19208 command_buffer_allocate_info.commandBufferCount = 2;
19209 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19210 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19211
19212 VkQueue queue = VK_NULL_HANDLE;
19213 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19214
19215 {
19216 VkCommandBufferBeginInfo begin_info{};
19217 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19218 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19219
19220 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019221 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019222
19223 VkViewport viewport{};
19224 viewport.maxDepth = 1.0f;
19225 viewport.minDepth = 0.0f;
19226 viewport.width = 512;
19227 viewport.height = 512;
19228 viewport.x = 0;
19229 viewport.y = 0;
19230 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19231 vkEndCommandBuffer(command_buffer[0]);
19232 }
19233 {
19234 VkCommandBufferBeginInfo begin_info{};
19235 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19236 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19237
19238 VkViewport viewport{};
19239 viewport.maxDepth = 1.0f;
19240 viewport.minDepth = 0.0f;
19241 viewport.width = 512;
19242 viewport.height = 512;
19243 viewport.x = 0;
19244 viewport.y = 0;
19245 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19246 vkEndCommandBuffer(command_buffer[1]);
19247 }
19248 {
19249 VkSubmitInfo submit_info{};
19250 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19251 submit_info.commandBufferCount = 1;
19252 submit_info.pCommandBuffers = &command_buffer[0];
19253 submit_info.signalSemaphoreCount = 1;
19254 submit_info.pSignalSemaphores = &semaphore;
19255 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19256 }
19257 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019258 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019259 VkSubmitInfo submit_info{};
19260 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19261 submit_info.commandBufferCount = 1;
19262 submit_info.pCommandBuffers = &command_buffer[1];
19263 submit_info.waitSemaphoreCount = 1;
19264 submit_info.pWaitSemaphores = &semaphore;
19265 submit_info.pWaitDstStageMask = flags;
19266 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19267 }
19268
19269 vkQueueWaitIdle(m_device->m_queue);
19270
19271 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19272 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19273 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19274
19275 m_errorMonitor->VerifyNotFound();
19276}
19277
19278// This is a positive test. No errors should be generated.
19279TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019280 TEST_DESCRIPTION(
19281 "Two command buffers, each in a separate QueueSubmit call "
19282 "submitted on separate queues, the second having a fence"
19283 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019284
19285 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019286 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019287
19288 m_errorMonitor->ExpectSuccess();
19289
19290 VkFence fence;
19291 VkFenceCreateInfo fence_create_info{};
19292 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19293 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19294
19295 VkSemaphore semaphore;
19296 VkSemaphoreCreateInfo semaphore_create_info{};
19297 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19298 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19299
19300 VkCommandPool command_pool;
19301 VkCommandPoolCreateInfo pool_create_info{};
19302 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19303 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19304 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19305 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19306
19307 VkCommandBuffer command_buffer[2];
19308 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19309 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19310 command_buffer_allocate_info.commandPool = command_pool;
19311 command_buffer_allocate_info.commandBufferCount = 2;
19312 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19313 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19314
19315 VkQueue queue = VK_NULL_HANDLE;
19316 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19317
19318 {
19319 VkCommandBufferBeginInfo begin_info{};
19320 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19321 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19322
19323 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019324 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019325
19326 VkViewport viewport{};
19327 viewport.maxDepth = 1.0f;
19328 viewport.minDepth = 0.0f;
19329 viewport.width = 512;
19330 viewport.height = 512;
19331 viewport.x = 0;
19332 viewport.y = 0;
19333 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19334 vkEndCommandBuffer(command_buffer[0]);
19335 }
19336 {
19337 VkCommandBufferBeginInfo begin_info{};
19338 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19339 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19340
19341 VkViewport viewport{};
19342 viewport.maxDepth = 1.0f;
19343 viewport.minDepth = 0.0f;
19344 viewport.width = 512;
19345 viewport.height = 512;
19346 viewport.x = 0;
19347 viewport.y = 0;
19348 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19349 vkEndCommandBuffer(command_buffer[1]);
19350 }
19351 {
19352 VkSubmitInfo submit_info{};
19353 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19354 submit_info.commandBufferCount = 1;
19355 submit_info.pCommandBuffers = &command_buffer[0];
19356 submit_info.signalSemaphoreCount = 1;
19357 submit_info.pSignalSemaphores = &semaphore;
19358 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19359 }
19360 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019361 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019362 VkSubmitInfo submit_info{};
19363 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19364 submit_info.commandBufferCount = 1;
19365 submit_info.pCommandBuffers = &command_buffer[1];
19366 submit_info.waitSemaphoreCount = 1;
19367 submit_info.pWaitSemaphores = &semaphore;
19368 submit_info.pWaitDstStageMask = flags;
19369 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19370 }
19371
19372 vkQueueWaitIdle(m_device->m_queue);
19373
19374 vkDestroyFence(m_device->device(), fence, nullptr);
19375 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19376 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19377 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19378
19379 m_errorMonitor->VerifyNotFound();
19380}
19381
19382// This is a positive test. No errors should be generated.
19383TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019384 TEST_DESCRIPTION(
19385 "Two command buffers, each in a separate QueueSubmit call "
19386 "submitted on separate queues, the second having a fence"
19387 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019388
19389 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019390 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019391
19392 m_errorMonitor->ExpectSuccess();
19393
19394 VkFence fence;
19395 VkFenceCreateInfo fence_create_info{};
19396 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19397 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19398
19399 VkSemaphore semaphore;
19400 VkSemaphoreCreateInfo semaphore_create_info{};
19401 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19402 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19403
19404 VkCommandPool command_pool;
19405 VkCommandPoolCreateInfo pool_create_info{};
19406 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19407 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19408 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19409 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19410
19411 VkCommandBuffer command_buffer[2];
19412 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19413 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19414 command_buffer_allocate_info.commandPool = command_pool;
19415 command_buffer_allocate_info.commandBufferCount = 2;
19416 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19417 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19418
19419 VkQueue queue = VK_NULL_HANDLE;
19420 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19421
19422 {
19423 VkCommandBufferBeginInfo begin_info{};
19424 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19425 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19426
19427 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019428 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019429
19430 VkViewport viewport{};
19431 viewport.maxDepth = 1.0f;
19432 viewport.minDepth = 0.0f;
19433 viewport.width = 512;
19434 viewport.height = 512;
19435 viewport.x = 0;
19436 viewport.y = 0;
19437 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19438 vkEndCommandBuffer(command_buffer[0]);
19439 }
19440 {
19441 VkCommandBufferBeginInfo begin_info{};
19442 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19443 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19444
19445 VkViewport viewport{};
19446 viewport.maxDepth = 1.0f;
19447 viewport.minDepth = 0.0f;
19448 viewport.width = 512;
19449 viewport.height = 512;
19450 viewport.x = 0;
19451 viewport.y = 0;
19452 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19453 vkEndCommandBuffer(command_buffer[1]);
19454 }
19455 {
19456 VkSubmitInfo submit_info{};
19457 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19458 submit_info.commandBufferCount = 1;
19459 submit_info.pCommandBuffers = &command_buffer[0];
19460 submit_info.signalSemaphoreCount = 1;
19461 submit_info.pSignalSemaphores = &semaphore;
19462 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19463 }
19464 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019465 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019466 VkSubmitInfo submit_info{};
19467 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19468 submit_info.commandBufferCount = 1;
19469 submit_info.pCommandBuffers = &command_buffer[1];
19470 submit_info.waitSemaphoreCount = 1;
19471 submit_info.pWaitSemaphores = &semaphore;
19472 submit_info.pWaitDstStageMask = flags;
19473 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19474 }
19475
19476 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19477 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19478
19479 vkDestroyFence(m_device->device(), fence, nullptr);
19480 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19481 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19482 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19483
19484 m_errorMonitor->VerifyNotFound();
19485}
19486
19487TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019488 ASSERT_NO_FATAL_FAILURE(InitState());
19489 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
19490 printf("Test requires two queues, skipping\n");
19491 return;
19492 }
19493
19494 VkResult err;
19495
19496 m_errorMonitor->ExpectSuccess();
19497
19498 VkQueue q0 = m_device->m_queue;
19499 VkQueue q1 = nullptr;
19500 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
19501 ASSERT_NE(q1, nullptr);
19502
19503 // An (empty) command buffer. We must have work in the first submission --
19504 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019505 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019506 VkCommandPool pool;
19507 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
19508 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019509 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
19510 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019511 VkCommandBuffer cb;
19512 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
19513 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019514 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019515 err = vkBeginCommandBuffer(cb, &cbbi);
19516 ASSERT_VK_SUCCESS(err);
19517 err = vkEndCommandBuffer(cb);
19518 ASSERT_VK_SUCCESS(err);
19519
19520 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019521 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019522 VkSemaphore s;
19523 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
19524 ASSERT_VK_SUCCESS(err);
19525
19526 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019527 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019528
19529 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
19530 ASSERT_VK_SUCCESS(err);
19531
19532 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019533 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019534 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019535
19536 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
19537 ASSERT_VK_SUCCESS(err);
19538
19539 // Wait for q0 idle
19540 err = vkQueueWaitIdle(q0);
19541 ASSERT_VK_SUCCESS(err);
19542
19543 // Command buffer should have been completed (it was on q0); reset the pool.
19544 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
19545
19546 m_errorMonitor->VerifyNotFound();
19547
19548 // Force device completely idle and clean up resources
19549 vkDeviceWaitIdle(m_device->device());
19550 vkDestroyCommandPool(m_device->device(), pool, nullptr);
19551 vkDestroySemaphore(m_device->device(), s, nullptr);
19552}
19553
19554// This is a positive test. No errors should be generated.
19555TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019556 TEST_DESCRIPTION(
19557 "Two command buffers, each in a separate QueueSubmit call "
19558 "submitted on separate queues, the second having a fence, "
19559 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019560
19561 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019562 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019563
19564 m_errorMonitor->ExpectSuccess();
19565
19566 ASSERT_NO_FATAL_FAILURE(InitState());
19567 VkFence fence;
19568 VkFenceCreateInfo fence_create_info{};
19569 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19570 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19571
19572 VkSemaphore semaphore;
19573 VkSemaphoreCreateInfo semaphore_create_info{};
19574 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19575 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19576
19577 VkCommandPool command_pool;
19578 VkCommandPoolCreateInfo pool_create_info{};
19579 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19580 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19581 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19582 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19583
19584 VkCommandBuffer command_buffer[2];
19585 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19586 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19587 command_buffer_allocate_info.commandPool = command_pool;
19588 command_buffer_allocate_info.commandBufferCount = 2;
19589 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19590 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19591
19592 VkQueue queue = VK_NULL_HANDLE;
19593 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19594
19595 {
19596 VkCommandBufferBeginInfo begin_info{};
19597 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19598 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19599
19600 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019601 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019602
19603 VkViewport viewport{};
19604 viewport.maxDepth = 1.0f;
19605 viewport.minDepth = 0.0f;
19606 viewport.width = 512;
19607 viewport.height = 512;
19608 viewport.x = 0;
19609 viewport.y = 0;
19610 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19611 vkEndCommandBuffer(command_buffer[0]);
19612 }
19613 {
19614 VkCommandBufferBeginInfo begin_info{};
19615 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19616 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19617
19618 VkViewport viewport{};
19619 viewport.maxDepth = 1.0f;
19620 viewport.minDepth = 0.0f;
19621 viewport.width = 512;
19622 viewport.height = 512;
19623 viewport.x = 0;
19624 viewport.y = 0;
19625 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19626 vkEndCommandBuffer(command_buffer[1]);
19627 }
19628 {
19629 VkSubmitInfo submit_info{};
19630 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19631 submit_info.commandBufferCount = 1;
19632 submit_info.pCommandBuffers = &command_buffer[0];
19633 submit_info.signalSemaphoreCount = 1;
19634 submit_info.pSignalSemaphores = &semaphore;
19635 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19636 }
19637 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019638 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019639 VkSubmitInfo submit_info{};
19640 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19641 submit_info.commandBufferCount = 1;
19642 submit_info.pCommandBuffers = &command_buffer[1];
19643 submit_info.waitSemaphoreCount = 1;
19644 submit_info.pWaitSemaphores = &semaphore;
19645 submit_info.pWaitDstStageMask = flags;
19646 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19647 }
19648
19649 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19650
19651 vkDestroyFence(m_device->device(), fence, nullptr);
19652 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19653 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19654 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19655
19656 m_errorMonitor->VerifyNotFound();
19657}
19658
19659// This is a positive test. No errors should be generated.
19660TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019661 TEST_DESCRIPTION(
19662 "Two command buffers, each in a separate QueueSubmit call "
19663 "on the same queue, sharing a signal/wait semaphore, the "
19664 "second having a fence, "
19665 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019666
19667 m_errorMonitor->ExpectSuccess();
19668
19669 ASSERT_NO_FATAL_FAILURE(InitState());
19670 VkFence fence;
19671 VkFenceCreateInfo fence_create_info{};
19672 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19673 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19674
19675 VkSemaphore semaphore;
19676 VkSemaphoreCreateInfo semaphore_create_info{};
19677 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19678 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19679
19680 VkCommandPool command_pool;
19681 VkCommandPoolCreateInfo pool_create_info{};
19682 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19683 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19684 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19685 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19686
19687 VkCommandBuffer command_buffer[2];
19688 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19689 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19690 command_buffer_allocate_info.commandPool = command_pool;
19691 command_buffer_allocate_info.commandBufferCount = 2;
19692 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19693 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19694
19695 {
19696 VkCommandBufferBeginInfo begin_info{};
19697 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19698 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19699
19700 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019701 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019702
19703 VkViewport viewport{};
19704 viewport.maxDepth = 1.0f;
19705 viewport.minDepth = 0.0f;
19706 viewport.width = 512;
19707 viewport.height = 512;
19708 viewport.x = 0;
19709 viewport.y = 0;
19710 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19711 vkEndCommandBuffer(command_buffer[0]);
19712 }
19713 {
19714 VkCommandBufferBeginInfo begin_info{};
19715 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19716 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19717
19718 VkViewport viewport{};
19719 viewport.maxDepth = 1.0f;
19720 viewport.minDepth = 0.0f;
19721 viewport.width = 512;
19722 viewport.height = 512;
19723 viewport.x = 0;
19724 viewport.y = 0;
19725 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19726 vkEndCommandBuffer(command_buffer[1]);
19727 }
19728 {
19729 VkSubmitInfo submit_info{};
19730 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19731 submit_info.commandBufferCount = 1;
19732 submit_info.pCommandBuffers = &command_buffer[0];
19733 submit_info.signalSemaphoreCount = 1;
19734 submit_info.pSignalSemaphores = &semaphore;
19735 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19736 }
19737 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019738 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019739 VkSubmitInfo submit_info{};
19740 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19741 submit_info.commandBufferCount = 1;
19742 submit_info.pCommandBuffers = &command_buffer[1];
19743 submit_info.waitSemaphoreCount = 1;
19744 submit_info.pWaitSemaphores = &semaphore;
19745 submit_info.pWaitDstStageMask = flags;
19746 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19747 }
19748
19749 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19750
19751 vkDestroyFence(m_device->device(), fence, nullptr);
19752 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19753 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19754 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19755
19756 m_errorMonitor->VerifyNotFound();
19757}
19758
19759// This is a positive test. No errors should be generated.
19760TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019761 TEST_DESCRIPTION(
19762 "Two command buffers, each in a separate QueueSubmit call "
19763 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19764 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019765
19766 m_errorMonitor->ExpectSuccess();
19767
19768 ASSERT_NO_FATAL_FAILURE(InitState());
19769 VkFence fence;
19770 VkFenceCreateInfo fence_create_info{};
19771 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19772 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19773
19774 VkCommandPool command_pool;
19775 VkCommandPoolCreateInfo pool_create_info{};
19776 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19777 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19778 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19779 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19780
19781 VkCommandBuffer command_buffer[2];
19782 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19783 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19784 command_buffer_allocate_info.commandPool = command_pool;
19785 command_buffer_allocate_info.commandBufferCount = 2;
19786 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19787 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19788
19789 {
19790 VkCommandBufferBeginInfo begin_info{};
19791 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19792 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19793
19794 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019795 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019796
19797 VkViewport viewport{};
19798 viewport.maxDepth = 1.0f;
19799 viewport.minDepth = 0.0f;
19800 viewport.width = 512;
19801 viewport.height = 512;
19802 viewport.x = 0;
19803 viewport.y = 0;
19804 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19805 vkEndCommandBuffer(command_buffer[0]);
19806 }
19807 {
19808 VkCommandBufferBeginInfo begin_info{};
19809 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19810 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19811
19812 VkViewport viewport{};
19813 viewport.maxDepth = 1.0f;
19814 viewport.minDepth = 0.0f;
19815 viewport.width = 512;
19816 viewport.height = 512;
19817 viewport.x = 0;
19818 viewport.y = 0;
19819 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19820 vkEndCommandBuffer(command_buffer[1]);
19821 }
19822 {
19823 VkSubmitInfo submit_info{};
19824 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19825 submit_info.commandBufferCount = 1;
19826 submit_info.pCommandBuffers = &command_buffer[0];
19827 submit_info.signalSemaphoreCount = 0;
19828 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19829 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19830 }
19831 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019832 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019833 VkSubmitInfo submit_info{};
19834 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19835 submit_info.commandBufferCount = 1;
19836 submit_info.pCommandBuffers = &command_buffer[1];
19837 submit_info.waitSemaphoreCount = 0;
19838 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19839 submit_info.pWaitDstStageMask = flags;
19840 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19841 }
19842
19843 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19844
19845 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19846 ASSERT_VK_SUCCESS(err);
19847
19848 vkDestroyFence(m_device->device(), fence, nullptr);
19849 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19850 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19851
19852 m_errorMonitor->VerifyNotFound();
19853}
19854
19855// This is a positive test. No errors should be generated.
19856TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019857 TEST_DESCRIPTION(
19858 "Two command buffers, each in a separate QueueSubmit call "
19859 "on the same queue, the second having a fence, followed "
19860 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019861
19862 m_errorMonitor->ExpectSuccess();
19863
19864 ASSERT_NO_FATAL_FAILURE(InitState());
19865 VkFence fence;
19866 VkFenceCreateInfo fence_create_info{};
19867 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19868 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19869
19870 VkCommandPool command_pool;
19871 VkCommandPoolCreateInfo pool_create_info{};
19872 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19873 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19874 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19875 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19876
19877 VkCommandBuffer command_buffer[2];
19878 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19879 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19880 command_buffer_allocate_info.commandPool = command_pool;
19881 command_buffer_allocate_info.commandBufferCount = 2;
19882 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19883 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19884
19885 {
19886 VkCommandBufferBeginInfo begin_info{};
19887 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19888 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19889
19890 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019891 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019892
19893 VkViewport viewport{};
19894 viewport.maxDepth = 1.0f;
19895 viewport.minDepth = 0.0f;
19896 viewport.width = 512;
19897 viewport.height = 512;
19898 viewport.x = 0;
19899 viewport.y = 0;
19900 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19901 vkEndCommandBuffer(command_buffer[0]);
19902 }
19903 {
19904 VkCommandBufferBeginInfo begin_info{};
19905 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19906 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19907
19908 VkViewport viewport{};
19909 viewport.maxDepth = 1.0f;
19910 viewport.minDepth = 0.0f;
19911 viewport.width = 512;
19912 viewport.height = 512;
19913 viewport.x = 0;
19914 viewport.y = 0;
19915 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19916 vkEndCommandBuffer(command_buffer[1]);
19917 }
19918 {
19919 VkSubmitInfo submit_info{};
19920 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19921 submit_info.commandBufferCount = 1;
19922 submit_info.pCommandBuffers = &command_buffer[0];
19923 submit_info.signalSemaphoreCount = 0;
19924 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19925 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19926 }
19927 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019928 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019929 VkSubmitInfo submit_info{};
19930 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19931 submit_info.commandBufferCount = 1;
19932 submit_info.pCommandBuffers = &command_buffer[1];
19933 submit_info.waitSemaphoreCount = 0;
19934 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19935 submit_info.pWaitDstStageMask = flags;
19936 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19937 }
19938
19939 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19940
19941 vkDestroyFence(m_device->device(), fence, nullptr);
19942 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19943 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19944
19945 m_errorMonitor->VerifyNotFound();
19946}
19947
19948// This is a positive test. No errors should be generated.
19949TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019950 TEST_DESCRIPTION(
19951 "Two command buffers each in a separate SubmitInfo sent in a single "
19952 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019953 ASSERT_NO_FATAL_FAILURE(InitState());
19954
19955 m_errorMonitor->ExpectSuccess();
19956
19957 VkFence fence;
19958 VkFenceCreateInfo fence_create_info{};
19959 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19960 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19961
19962 VkSemaphore semaphore;
19963 VkSemaphoreCreateInfo semaphore_create_info{};
19964 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19965 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19966
19967 VkCommandPool command_pool;
19968 VkCommandPoolCreateInfo pool_create_info{};
19969 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19970 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19971 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19972 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19973
19974 VkCommandBuffer command_buffer[2];
19975 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19976 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19977 command_buffer_allocate_info.commandPool = command_pool;
19978 command_buffer_allocate_info.commandBufferCount = 2;
19979 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19980 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19981
19982 {
19983 VkCommandBufferBeginInfo begin_info{};
19984 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19985 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19986
19987 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019988 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019989
19990 VkViewport viewport{};
19991 viewport.maxDepth = 1.0f;
19992 viewport.minDepth = 0.0f;
19993 viewport.width = 512;
19994 viewport.height = 512;
19995 viewport.x = 0;
19996 viewport.y = 0;
19997 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19998 vkEndCommandBuffer(command_buffer[0]);
19999 }
20000 {
20001 VkCommandBufferBeginInfo begin_info{};
20002 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20003 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20004
20005 VkViewport viewport{};
20006 viewport.maxDepth = 1.0f;
20007 viewport.minDepth = 0.0f;
20008 viewport.width = 512;
20009 viewport.height = 512;
20010 viewport.x = 0;
20011 viewport.y = 0;
20012 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20013 vkEndCommandBuffer(command_buffer[1]);
20014 }
20015 {
20016 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020017 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020018
20019 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20020 submit_info[0].pNext = NULL;
20021 submit_info[0].commandBufferCount = 1;
20022 submit_info[0].pCommandBuffers = &command_buffer[0];
20023 submit_info[0].signalSemaphoreCount = 1;
20024 submit_info[0].pSignalSemaphores = &semaphore;
20025 submit_info[0].waitSemaphoreCount = 0;
20026 submit_info[0].pWaitSemaphores = NULL;
20027 submit_info[0].pWaitDstStageMask = 0;
20028
20029 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20030 submit_info[1].pNext = NULL;
20031 submit_info[1].commandBufferCount = 1;
20032 submit_info[1].pCommandBuffers = &command_buffer[1];
20033 submit_info[1].waitSemaphoreCount = 1;
20034 submit_info[1].pWaitSemaphores = &semaphore;
20035 submit_info[1].pWaitDstStageMask = flags;
20036 submit_info[1].signalSemaphoreCount = 0;
20037 submit_info[1].pSignalSemaphores = NULL;
20038 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
20039 }
20040
20041 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20042
20043 vkDestroyFence(m_device->device(), fence, nullptr);
20044 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20045 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20046 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20047
20048 m_errorMonitor->VerifyNotFound();
20049}
20050
20051TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
20052 m_errorMonitor->ExpectSuccess();
20053
20054 ASSERT_NO_FATAL_FAILURE(InitState());
20055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20056
Tony Barbour552f6c02016-12-21 14:34:07 -070020057 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020058
20059 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
20060 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20061 m_errorMonitor->VerifyNotFound();
20062 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
20063 m_errorMonitor->VerifyNotFound();
20064 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20065 m_errorMonitor->VerifyNotFound();
20066
20067 m_commandBuffer->EndCommandBuffer();
20068 m_errorMonitor->VerifyNotFound();
20069}
20070
20071TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020072 TEST_DESCRIPTION(
20073 "Positive test where we create a renderpass with an "
20074 "attachment that uses LOAD_OP_CLEAR, the first subpass "
20075 "has a valid layout, and a second subpass then uses a "
20076 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020077 m_errorMonitor->ExpectSuccess();
20078 ASSERT_NO_FATAL_FAILURE(InitState());
20079
20080 VkAttachmentReference attach[2] = {};
20081 attach[0].attachment = 0;
20082 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20083 attach[1].attachment = 0;
20084 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20085 VkSubpassDescription subpasses[2] = {};
20086 // First subpass clears DS attach on load
20087 subpasses[0].pDepthStencilAttachment = &attach[0];
20088 // 2nd subpass reads in DS as input attachment
20089 subpasses[1].inputAttachmentCount = 1;
20090 subpasses[1].pInputAttachments = &attach[1];
20091 VkAttachmentDescription attach_desc = {};
20092 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
20093 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
20094 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
20095 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20096 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20097 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20098 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20099 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20100 VkRenderPassCreateInfo rpci = {};
20101 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20102 rpci.attachmentCount = 1;
20103 rpci.pAttachments = &attach_desc;
20104 rpci.subpassCount = 2;
20105 rpci.pSubpasses = subpasses;
20106
20107 // Now create RenderPass and verify no errors
20108 VkRenderPass rp;
20109 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
20110 m_errorMonitor->VerifyNotFound();
20111
20112 vkDestroyRenderPass(m_device->device(), rp, NULL);
20113}
20114
20115TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020116 TEST_DESCRIPTION(
20117 "Test that pipeline validation accepts matrices passed "
20118 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020119 m_errorMonitor->ExpectSuccess();
20120
20121 ASSERT_NO_FATAL_FAILURE(InitState());
20122 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20123
20124 VkVertexInputBindingDescription input_binding;
20125 memset(&input_binding, 0, sizeof(input_binding));
20126
20127 VkVertexInputAttributeDescription input_attribs[2];
20128 memset(input_attribs, 0, sizeof(input_attribs));
20129
20130 for (int i = 0; i < 2; i++) {
20131 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20132 input_attribs[i].location = i;
20133 }
20134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020135 char const *vsSource =
20136 "#version 450\n"
20137 "\n"
20138 "layout(location=0) in mat2x4 x;\n"
20139 "out gl_PerVertex {\n"
20140 " vec4 gl_Position;\n"
20141 "};\n"
20142 "void main(){\n"
20143 " gl_Position = x[0] + x[1];\n"
20144 "}\n";
20145 char const *fsSource =
20146 "#version 450\n"
20147 "\n"
20148 "layout(location=0) out vec4 color;\n"
20149 "void main(){\n"
20150 " color = vec4(1);\n"
20151 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020152
20153 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20154 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20155
20156 VkPipelineObj pipe(m_device);
20157 pipe.AddColorAttachment();
20158 pipe.AddShader(&vs);
20159 pipe.AddShader(&fs);
20160
20161 pipe.AddVertexInputBindings(&input_binding, 1);
20162 pipe.AddVertexInputAttribs(input_attribs, 2);
20163
20164 VkDescriptorSetObj descriptorSet(m_device);
20165 descriptorSet.AppendDummy();
20166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20167
20168 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20169
20170 /* expect success */
20171 m_errorMonitor->VerifyNotFound();
20172}
20173
20174TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
20175 m_errorMonitor->ExpectSuccess();
20176
20177 ASSERT_NO_FATAL_FAILURE(InitState());
20178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20179
20180 VkVertexInputBindingDescription input_binding;
20181 memset(&input_binding, 0, sizeof(input_binding));
20182
20183 VkVertexInputAttributeDescription input_attribs[2];
20184 memset(input_attribs, 0, sizeof(input_attribs));
20185
20186 for (int i = 0; i < 2; i++) {
20187 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20188 input_attribs[i].location = i;
20189 }
20190
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020191 char const *vsSource =
20192 "#version 450\n"
20193 "\n"
20194 "layout(location=0) in vec4 x[2];\n"
20195 "out gl_PerVertex {\n"
20196 " vec4 gl_Position;\n"
20197 "};\n"
20198 "void main(){\n"
20199 " gl_Position = x[0] + x[1];\n"
20200 "}\n";
20201 char const *fsSource =
20202 "#version 450\n"
20203 "\n"
20204 "layout(location=0) out vec4 color;\n"
20205 "void main(){\n"
20206 " color = vec4(1);\n"
20207 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020208
20209 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20210 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20211
20212 VkPipelineObj pipe(m_device);
20213 pipe.AddColorAttachment();
20214 pipe.AddShader(&vs);
20215 pipe.AddShader(&fs);
20216
20217 pipe.AddVertexInputBindings(&input_binding, 1);
20218 pipe.AddVertexInputAttribs(input_attribs, 2);
20219
20220 VkDescriptorSetObj descriptorSet(m_device);
20221 descriptorSet.AppendDummy();
20222 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20223
20224 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20225
20226 m_errorMonitor->VerifyNotFound();
20227}
20228
20229TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020230 TEST_DESCRIPTION(
20231 "Test that pipeline validation accepts consuming a vertex attribute "
20232 "through multiple vertex shader inputs, each consuming a different "
20233 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020234 m_errorMonitor->ExpectSuccess();
20235
20236 ASSERT_NO_FATAL_FAILURE(InitState());
20237 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20238
20239 VkVertexInputBindingDescription input_binding;
20240 memset(&input_binding, 0, sizeof(input_binding));
20241
20242 VkVertexInputAttributeDescription input_attribs[3];
20243 memset(input_attribs, 0, sizeof(input_attribs));
20244
20245 for (int i = 0; i < 3; i++) {
20246 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20247 input_attribs[i].location = i;
20248 }
20249
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020250 char const *vsSource =
20251 "#version 450\n"
20252 "\n"
20253 "layout(location=0) in vec4 x;\n"
20254 "layout(location=1) in vec3 y1;\n"
20255 "layout(location=1, component=3) in float y2;\n"
20256 "layout(location=2) in vec4 z;\n"
20257 "out gl_PerVertex {\n"
20258 " vec4 gl_Position;\n"
20259 "};\n"
20260 "void main(){\n"
20261 " gl_Position = x + vec4(y1, y2) + z;\n"
20262 "}\n";
20263 char const *fsSource =
20264 "#version 450\n"
20265 "\n"
20266 "layout(location=0) out vec4 color;\n"
20267 "void main(){\n"
20268 " color = vec4(1);\n"
20269 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020270
20271 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20272 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20273
20274 VkPipelineObj pipe(m_device);
20275 pipe.AddColorAttachment();
20276 pipe.AddShader(&vs);
20277 pipe.AddShader(&fs);
20278
20279 pipe.AddVertexInputBindings(&input_binding, 1);
20280 pipe.AddVertexInputAttribs(input_attribs, 3);
20281
20282 VkDescriptorSetObj descriptorSet(m_device);
20283 descriptorSet.AppendDummy();
20284 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20285
20286 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20287
20288 m_errorMonitor->VerifyNotFound();
20289}
20290
20291TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
20292 m_errorMonitor->ExpectSuccess();
20293
20294 ASSERT_NO_FATAL_FAILURE(InitState());
20295 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20296
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020297 char const *vsSource =
20298 "#version 450\n"
20299 "out gl_PerVertex {\n"
20300 " vec4 gl_Position;\n"
20301 "};\n"
20302 "void main(){\n"
20303 " gl_Position = vec4(0);\n"
20304 "}\n";
20305 char const *fsSource =
20306 "#version 450\n"
20307 "\n"
20308 "layout(location=0) out vec4 color;\n"
20309 "void main(){\n"
20310 " color = vec4(1);\n"
20311 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020312
20313 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20314 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20315
20316 VkPipelineObj pipe(m_device);
20317 pipe.AddColorAttachment();
20318 pipe.AddShader(&vs);
20319 pipe.AddShader(&fs);
20320
20321 VkDescriptorSetObj descriptorSet(m_device);
20322 descriptorSet.AppendDummy();
20323 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20324
20325 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20326
20327 m_errorMonitor->VerifyNotFound();
20328}
20329
20330TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020331 TEST_DESCRIPTION(
20332 "Test that pipeline validation accepts the relaxed type matching rules "
20333 "set out in 14.1.3: fundamental type must match, and producer side must "
20334 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020335 m_errorMonitor->ExpectSuccess();
20336
20337 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
20338
20339 ASSERT_NO_FATAL_FAILURE(InitState());
20340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20341
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020342 char const *vsSource =
20343 "#version 450\n"
20344 "out gl_PerVertex {\n"
20345 " vec4 gl_Position;\n"
20346 "};\n"
20347 "layout(location=0) out vec3 x;\n"
20348 "layout(location=1) out ivec3 y;\n"
20349 "layout(location=2) out vec3 z;\n"
20350 "void main(){\n"
20351 " gl_Position = vec4(0);\n"
20352 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
20353 "}\n";
20354 char const *fsSource =
20355 "#version 450\n"
20356 "\n"
20357 "layout(location=0) out vec4 color;\n"
20358 "layout(location=0) in float x;\n"
20359 "layout(location=1) flat in int y;\n"
20360 "layout(location=2) in vec2 z;\n"
20361 "void main(){\n"
20362 " color = vec4(1 + x + y + z.x);\n"
20363 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020364
20365 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20366 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20367
20368 VkPipelineObj pipe(m_device);
20369 pipe.AddColorAttachment();
20370 pipe.AddShader(&vs);
20371 pipe.AddShader(&fs);
20372
20373 VkDescriptorSetObj descriptorSet(m_device);
20374 descriptorSet.AppendDummy();
20375 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20376
20377 VkResult err = VK_SUCCESS;
20378 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20379 ASSERT_VK_SUCCESS(err);
20380
20381 m_errorMonitor->VerifyNotFound();
20382}
20383
20384TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020385 TEST_DESCRIPTION(
20386 "Test that pipeline validation accepts per-vertex variables "
20387 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020388 m_errorMonitor->ExpectSuccess();
20389
20390 ASSERT_NO_FATAL_FAILURE(InitState());
20391 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20392
20393 if (!m_device->phy().features().tessellationShader) {
20394 printf("Device does not support tessellation shaders; skipped.\n");
20395 return;
20396 }
20397
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020398 char const *vsSource =
20399 "#version 450\n"
20400 "void main(){}\n";
20401 char const *tcsSource =
20402 "#version 450\n"
20403 "layout(location=0) out int x[];\n"
20404 "layout(vertices=3) out;\n"
20405 "void main(){\n"
20406 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
20407 " gl_TessLevelInner[0] = 1;\n"
20408 " x[gl_InvocationID] = gl_InvocationID;\n"
20409 "}\n";
20410 char const *tesSource =
20411 "#version 450\n"
20412 "layout(triangles, equal_spacing, cw) in;\n"
20413 "layout(location=0) in int x[];\n"
20414 "out gl_PerVertex { vec4 gl_Position; };\n"
20415 "void main(){\n"
20416 " gl_Position.xyz = gl_TessCoord;\n"
20417 " gl_Position.w = x[0] + x[1] + x[2];\n"
20418 "}\n";
20419 char const *fsSource =
20420 "#version 450\n"
20421 "layout(location=0) out vec4 color;\n"
20422 "void main(){\n"
20423 " color = vec4(1);\n"
20424 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020425
20426 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20427 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
20428 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
20429 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20430
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020431 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
20432 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020433
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020434 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020435
20436 VkPipelineObj pipe(m_device);
20437 pipe.SetInputAssembly(&iasci);
20438 pipe.SetTessellation(&tsci);
20439 pipe.AddColorAttachment();
20440 pipe.AddShader(&vs);
20441 pipe.AddShader(&tcs);
20442 pipe.AddShader(&tes);
20443 pipe.AddShader(&fs);
20444
20445 VkDescriptorSetObj descriptorSet(m_device);
20446 descriptorSet.AppendDummy();
20447 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20448
20449 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20450
20451 m_errorMonitor->VerifyNotFound();
20452}
20453
20454TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020455 TEST_DESCRIPTION(
20456 "Test that pipeline validation accepts a user-defined "
20457 "interface block passed into the geometry shader. This "
20458 "is interesting because the 'extra' array level is not "
20459 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020460 m_errorMonitor->ExpectSuccess();
20461
20462 ASSERT_NO_FATAL_FAILURE(InitState());
20463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20464
20465 if (!m_device->phy().features().geometryShader) {
20466 printf("Device does not support geometry shaders; skipped.\n");
20467 return;
20468 }
20469
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020470 char const *vsSource =
20471 "#version 450\n"
20472 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
20473 "void main(){\n"
20474 " vs_out.x = vec4(1);\n"
20475 "}\n";
20476 char const *gsSource =
20477 "#version 450\n"
20478 "layout(triangles) in;\n"
20479 "layout(triangle_strip, max_vertices=3) out;\n"
20480 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
20481 "out gl_PerVertex { vec4 gl_Position; };\n"
20482 "void main() {\n"
20483 " gl_Position = gs_in[0].x;\n"
20484 " EmitVertex();\n"
20485 "}\n";
20486 char const *fsSource =
20487 "#version 450\n"
20488 "layout(location=0) out vec4 color;\n"
20489 "void main(){\n"
20490 " color = vec4(1);\n"
20491 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020492
20493 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20494 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
20495 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20496
20497 VkPipelineObj pipe(m_device);
20498 pipe.AddColorAttachment();
20499 pipe.AddShader(&vs);
20500 pipe.AddShader(&gs);
20501 pipe.AddShader(&fs);
20502
20503 VkDescriptorSetObj descriptorSet(m_device);
20504 descriptorSet.AppendDummy();
20505 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20506
20507 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20508
20509 m_errorMonitor->VerifyNotFound();
20510}
20511
20512TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020513 TEST_DESCRIPTION(
20514 "Test that pipeline validation accepts basic use of 64bit vertex "
20515 "attributes. This is interesting because they consume multiple "
20516 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020517 m_errorMonitor->ExpectSuccess();
20518
20519 ASSERT_NO_FATAL_FAILURE(InitState());
20520 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20521
20522 if (!m_device->phy().features().shaderFloat64) {
20523 printf("Device does not support 64bit vertex attributes; skipped.\n");
20524 return;
20525 }
20526
20527 VkVertexInputBindingDescription input_bindings[1];
20528 memset(input_bindings, 0, sizeof(input_bindings));
20529
20530 VkVertexInputAttributeDescription input_attribs[4];
20531 memset(input_attribs, 0, sizeof(input_attribs));
20532 input_attribs[0].location = 0;
20533 input_attribs[0].offset = 0;
20534 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20535 input_attribs[1].location = 2;
20536 input_attribs[1].offset = 32;
20537 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20538 input_attribs[2].location = 4;
20539 input_attribs[2].offset = 64;
20540 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20541 input_attribs[3].location = 6;
20542 input_attribs[3].offset = 96;
20543 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20544
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020545 char const *vsSource =
20546 "#version 450\n"
20547 "\n"
20548 "layout(location=0) in dmat4 x;\n"
20549 "out gl_PerVertex {\n"
20550 " vec4 gl_Position;\n"
20551 "};\n"
20552 "void main(){\n"
20553 " gl_Position = vec4(x[0][0]);\n"
20554 "}\n";
20555 char const *fsSource =
20556 "#version 450\n"
20557 "\n"
20558 "layout(location=0) out vec4 color;\n"
20559 "void main(){\n"
20560 " color = vec4(1);\n"
20561 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020562
20563 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20564 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20565
20566 VkPipelineObj pipe(m_device);
20567 pipe.AddColorAttachment();
20568 pipe.AddShader(&vs);
20569 pipe.AddShader(&fs);
20570
20571 pipe.AddVertexInputBindings(input_bindings, 1);
20572 pipe.AddVertexInputAttribs(input_attribs, 4);
20573
20574 VkDescriptorSetObj descriptorSet(m_device);
20575 descriptorSet.AppendDummy();
20576 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20577
20578 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20579
20580 m_errorMonitor->VerifyNotFound();
20581}
20582
20583TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20584 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20585 m_errorMonitor->ExpectSuccess();
20586
20587 ASSERT_NO_FATAL_FAILURE(InitState());
20588
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020589 char const *vsSource =
20590 "#version 450\n"
20591 "\n"
20592 "out gl_PerVertex {\n"
20593 " vec4 gl_Position;\n"
20594 "};\n"
20595 "void main(){\n"
20596 " gl_Position = vec4(1);\n"
20597 "}\n";
20598 char const *fsSource =
20599 "#version 450\n"
20600 "\n"
20601 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20602 "layout(location=0) out vec4 color;\n"
20603 "void main() {\n"
20604 " color = subpassLoad(x);\n"
20605 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020606
20607 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20608 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20609
20610 VkPipelineObj pipe(m_device);
20611 pipe.AddShader(&vs);
20612 pipe.AddShader(&fs);
20613 pipe.AddColorAttachment();
20614 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20615
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020616 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
20617 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020618 VkDescriptorSetLayout dsl;
20619 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20620 ASSERT_VK_SUCCESS(err);
20621
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020622 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020623 VkPipelineLayout pl;
20624 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20625 ASSERT_VK_SUCCESS(err);
20626
20627 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020628 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20629 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20630 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
20631 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20632 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020633 };
20634 VkAttachmentReference color = {
20635 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20636 };
20637 VkAttachmentReference input = {
20638 1, VK_IMAGE_LAYOUT_GENERAL,
20639 };
20640
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020641 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020642
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020643 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020644 VkRenderPass rp;
20645 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20646 ASSERT_VK_SUCCESS(err);
20647
20648 // should be OK. would go wrong here if it's going to...
20649 pipe.CreateVKPipeline(pl, rp);
20650
20651 m_errorMonitor->VerifyNotFound();
20652
20653 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20654 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20655 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20656}
20657
20658TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020659 TEST_DESCRIPTION(
20660 "Test that pipeline validation accepts a compute pipeline which declares a "
20661 "descriptor-backed resource which is not provided, but the shader does not "
20662 "statically use it. This is interesting because it requires compute pipelines "
20663 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020664 m_errorMonitor->ExpectSuccess();
20665
20666 ASSERT_NO_FATAL_FAILURE(InitState());
20667
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020668 char const *csSource =
20669 "#version 450\n"
20670 "\n"
20671 "layout(local_size_x=1) in;\n"
20672 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20673 "void main(){\n"
20674 " // x is not used.\n"
20675 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020676
20677 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20678
20679 VkDescriptorSetObj descriptorSet(m_device);
20680 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20681
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020682 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20683 nullptr,
20684 0,
20685 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20686 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20687 descriptorSet.GetPipelineLayout(),
20688 VK_NULL_HANDLE,
20689 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020690
20691 VkPipeline pipe;
20692 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20693
20694 m_errorMonitor->VerifyNotFound();
20695
20696 if (err == VK_SUCCESS) {
20697 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20698 }
20699}
20700
20701TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020702 TEST_DESCRIPTION(
20703 "Test that pipeline validation accepts a shader consuming only the "
20704 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020705 m_errorMonitor->ExpectSuccess();
20706
20707 ASSERT_NO_FATAL_FAILURE(InitState());
20708
20709 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020710 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20711 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20712 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020713 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020714 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020715 VkDescriptorSetLayout dsl;
20716 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20717 ASSERT_VK_SUCCESS(err);
20718
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020719 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020720 VkPipelineLayout pl;
20721 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20722 ASSERT_VK_SUCCESS(err);
20723
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020724 char const *csSource =
20725 "#version 450\n"
20726 "\n"
20727 "layout(local_size_x=1) in;\n"
20728 "layout(set=0, binding=0) uniform sampler s;\n"
20729 "layout(set=0, binding=1) uniform texture2D t;\n"
20730 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20731 "void main() {\n"
20732 " x = texture(sampler2D(t, s), vec2(0));\n"
20733 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020734 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20735
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020736 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20737 nullptr,
20738 0,
20739 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20740 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20741 pl,
20742 VK_NULL_HANDLE,
20743 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020744
20745 VkPipeline pipe;
20746 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20747
20748 m_errorMonitor->VerifyNotFound();
20749
20750 if (err == VK_SUCCESS) {
20751 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20752 }
20753
20754 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20755 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20756}
20757
20758TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020759 TEST_DESCRIPTION(
20760 "Test that pipeline validation accepts a shader consuming only the "
20761 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020762 m_errorMonitor->ExpectSuccess();
20763
20764 ASSERT_NO_FATAL_FAILURE(InitState());
20765
20766 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020767 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20768 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20769 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020770 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020771 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020772 VkDescriptorSetLayout dsl;
20773 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20774 ASSERT_VK_SUCCESS(err);
20775
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020776 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020777 VkPipelineLayout pl;
20778 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20779 ASSERT_VK_SUCCESS(err);
20780
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020781 char const *csSource =
20782 "#version 450\n"
20783 "\n"
20784 "layout(local_size_x=1) in;\n"
20785 "layout(set=0, binding=0) uniform texture2D t;\n"
20786 "layout(set=0, binding=1) uniform sampler s;\n"
20787 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20788 "void main() {\n"
20789 " x = texture(sampler2D(t, s), vec2(0));\n"
20790 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020791 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20792
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020793 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20794 nullptr,
20795 0,
20796 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20797 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20798 pl,
20799 VK_NULL_HANDLE,
20800 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020801
20802 VkPipeline pipe;
20803 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20804
20805 m_errorMonitor->VerifyNotFound();
20806
20807 if (err == VK_SUCCESS) {
20808 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20809 }
20810
20811 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20812 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20813}
20814
20815TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020816 TEST_DESCRIPTION(
20817 "Test that pipeline validation accepts a shader consuming "
20818 "both the sampler and the image of a combined image+sampler "
20819 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020820 m_errorMonitor->ExpectSuccess();
20821
20822 ASSERT_NO_FATAL_FAILURE(InitState());
20823
20824 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020825 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20826 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020827 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020828 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020829 VkDescriptorSetLayout dsl;
20830 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20831 ASSERT_VK_SUCCESS(err);
20832
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020833 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020834 VkPipelineLayout pl;
20835 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20836 ASSERT_VK_SUCCESS(err);
20837
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020838 char const *csSource =
20839 "#version 450\n"
20840 "\n"
20841 "layout(local_size_x=1) in;\n"
20842 "layout(set=0, binding=0) uniform texture2D t;\n"
20843 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20844 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20845 "void main() {\n"
20846 " x = texture(sampler2D(t, s), vec2(0));\n"
20847 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020848 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20849
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020850 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20851 nullptr,
20852 0,
20853 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20854 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20855 pl,
20856 VK_NULL_HANDLE,
20857 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020858
20859 VkPipeline pipe;
20860 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20861
20862 m_errorMonitor->VerifyNotFound();
20863
20864 if (err == VK_SUCCESS) {
20865 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20866 }
20867
20868 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20869 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20870}
20871
20872TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20873 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20874
20875 ASSERT_NO_FATAL_FAILURE(InitState());
20876
20877 // Positive test to check parameter_validation and unique_objects support
20878 // for NV_dedicated_allocation
20879 uint32_t extension_count = 0;
20880 bool supports_nv_dedicated_allocation = false;
20881 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20882 ASSERT_VK_SUCCESS(err);
20883
20884 if (extension_count > 0) {
20885 std::vector<VkExtensionProperties> available_extensions(extension_count);
20886
20887 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20888 ASSERT_VK_SUCCESS(err);
20889
20890 for (const auto &extension_props : available_extensions) {
20891 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20892 supports_nv_dedicated_allocation = true;
20893 }
20894 }
20895 }
20896
20897 if (supports_nv_dedicated_allocation) {
20898 m_errorMonitor->ExpectSuccess();
20899
20900 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20901 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20902 dedicated_buffer_create_info.pNext = nullptr;
20903 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20904
20905 uint32_t queue_family_index = 0;
20906 VkBufferCreateInfo buffer_create_info = {};
20907 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20908 buffer_create_info.pNext = &dedicated_buffer_create_info;
20909 buffer_create_info.size = 1024;
20910 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20911 buffer_create_info.queueFamilyIndexCount = 1;
20912 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20913
20914 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070020915 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020916 ASSERT_VK_SUCCESS(err);
20917
20918 VkMemoryRequirements memory_reqs;
20919 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20920
20921 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20922 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20923 dedicated_memory_info.pNext = nullptr;
20924 dedicated_memory_info.buffer = buffer;
20925 dedicated_memory_info.image = VK_NULL_HANDLE;
20926
20927 VkMemoryAllocateInfo memory_info = {};
20928 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20929 memory_info.pNext = &dedicated_memory_info;
20930 memory_info.allocationSize = memory_reqs.size;
20931
20932 bool pass;
20933 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20934 ASSERT_TRUE(pass);
20935
20936 VkDeviceMemory buffer_memory;
20937 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20938 ASSERT_VK_SUCCESS(err);
20939
20940 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20941 ASSERT_VK_SUCCESS(err);
20942
20943 vkDestroyBuffer(m_device->device(), buffer, NULL);
20944 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20945
20946 m_errorMonitor->VerifyNotFound();
20947 }
20948}
20949
20950TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20951 VkResult err;
20952
20953 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20954
20955 ASSERT_NO_FATAL_FAILURE(InitState());
20956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20957
20958 std::vector<const char *> device_extension_names;
20959 auto features = m_device->phy().features();
20960 // Artificially disable support for non-solid fill modes
20961 features.fillModeNonSolid = false;
20962 // The sacrificial device object
20963 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20964
20965 VkRenderpassObj render_pass(&test_device);
20966
20967 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20968 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20969 pipeline_layout_ci.setLayoutCount = 0;
20970 pipeline_layout_ci.pSetLayouts = NULL;
20971
20972 VkPipelineLayout pipeline_layout;
20973 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20974 ASSERT_VK_SUCCESS(err);
20975
20976 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20977 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20978 rs_ci.pNext = nullptr;
20979 rs_ci.lineWidth = 1.0f;
20980 rs_ci.rasterizerDiscardEnable = true;
20981
20982 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20983 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20984
20985 // Set polygonMode=FILL. No error is expected
20986 m_errorMonitor->ExpectSuccess();
20987 {
20988 VkPipelineObj pipe(&test_device);
20989 pipe.AddShader(&vs);
20990 pipe.AddShader(&fs);
20991 pipe.AddColorAttachment();
20992 // Set polygonMode to a good value
20993 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20994 pipe.SetRasterization(&rs_ci);
20995 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20996 }
20997 m_errorMonitor->VerifyNotFound();
20998
20999 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
21000}
21001
21002TEST_F(VkPositiveLayerTest, ValidPushConstants) {
21003 VkResult err;
21004 ASSERT_NO_FATAL_FAILURE(InitState());
21005 ASSERT_NO_FATAL_FAILURE(InitViewport());
21006 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21007
21008 VkPipelineLayout pipeline_layout;
21009 VkPushConstantRange pc_range = {};
21010 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
21011 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
21012 pipeline_layout_ci.pushConstantRangeCount = 1;
21013 pipeline_layout_ci.pPushConstantRanges = &pc_range;
21014
21015 //
21016 // Check for invalid push constant ranges in pipeline layouts.
21017 //
21018 struct PipelineLayoutTestCase {
21019 VkPushConstantRange const range;
21020 char const *msg;
21021 };
21022
21023 // Check for overlapping ranges
21024 const uint32_t ranges_per_test = 5;
21025 struct OverlappingRangeTestCase {
21026 VkPushConstantRange const ranges[ranges_per_test];
21027 char const *msg;
21028 };
21029
21030 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021031 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
21032 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
21033 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
21034 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
21035 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
21036 ""},
21037 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
21038 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
21039 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
21040 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
21041 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
21042 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021043 for (const auto &iter : overlapping_range_tests_pos) {
21044 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
21045 m_errorMonitor->ExpectSuccess();
21046 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21047 m_errorMonitor->VerifyNotFound();
21048 if (VK_SUCCESS == err) {
21049 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21050 }
21051 }
21052
21053 //
21054 // CmdPushConstants tests
21055 //
21056 const uint8_t dummy_values[100] = {};
21057
Tony Barbour552f6c02016-12-21 14:34:07 -070021058 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021059
21060 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021061 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
21062 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
21063 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
21064 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
21065 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
21066 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021067
21068 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
21069 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021070 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
21071 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8}, {VK_SHADER_STAGE_VERTEX_BIT, 56, 24},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021072 };
21073
21074 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
21075 pipeline_layout_ci.pPushConstantRanges = pc_range4;
21076 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21077 ASSERT_VK_SUCCESS(err);
21078 for (const auto &iter : cmd_overlap_tests_pos) {
21079 m_errorMonitor->ExpectSuccess();
21080 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021081 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021082 m_errorMonitor->VerifyNotFound();
21083 }
21084 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21085
Tony Barbour552f6c02016-12-21 14:34:07 -070021086 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021087}
21088
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021089#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021090TEST_F(VkPositiveLayerTest, LongFenceChain)
21091{
21092 m_errorMonitor->ExpectSuccess();
21093
21094 ASSERT_NO_FATAL_FAILURE(InitState());
21095 VkResult err;
21096
21097 std::vector<VkFence> fences;
21098
21099 const int chainLength = 32768;
21100
21101 for (int i = 0; i < chainLength; i++) {
21102 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
21103 VkFence fence;
21104 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
21105 ASSERT_VK_SUCCESS(err);
21106
21107 fences.push_back(fence);
21108
21109 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
21110 0, nullptr, 0, nullptr };
21111 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
21112 ASSERT_VK_SUCCESS(err);
21113
21114 }
21115
21116 // BOOM, stack overflow.
21117 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
21118
21119 for (auto fence : fences)
21120 vkDestroyFence(m_device->device(), fence, nullptr);
21121
21122 m_errorMonitor->VerifyNotFound();
21123}
21124#endif
21125
Cody Northrop1242dfd2016-07-13 17:24:59 -060021126#if defined(ANDROID) && defined(VALIDATION_APK)
21127static bool initialized = false;
21128static bool active = false;
21129
21130// Convert Intents to argv
21131// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021132std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021133 std::vector<std::string> args;
21134 JavaVM &vm = *app.activity->vm;
21135 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021136 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021137
21138 JNIEnv &env = *p_env;
21139 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021140 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021141 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021142 jmethodID get_string_extra_method =
21143 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021144 jvalue get_string_extra_args;
21145 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021146 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060021147
21148 std::string args_str;
21149 if (extra_str) {
21150 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
21151 args_str = extra_utf;
21152 env.ReleaseStringUTFChars(extra_str, extra_utf);
21153 env.DeleteLocalRef(extra_str);
21154 }
21155
21156 env.DeleteLocalRef(get_string_extra_args.l);
21157 env.DeleteLocalRef(intent);
21158 vm.DetachCurrentThread();
21159
21160 // split args_str
21161 std::stringstream ss(args_str);
21162 std::string arg;
21163 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021164 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021165 }
21166
21167 return args;
21168}
21169
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021170static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021171
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021172static void processCommand(struct android_app *app, int32_t cmd) {
21173 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021174 case APP_CMD_INIT_WINDOW: {
21175 if (app->window) {
21176 initialized = true;
21177 }
21178 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021179 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021180 case APP_CMD_GAINED_FOCUS: {
21181 active = true;
21182 break;
21183 }
21184 case APP_CMD_LOST_FOCUS: {
21185 active = false;
21186 break;
21187 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021188 }
21189}
21190
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021191void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021192 app_dummy();
21193
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021194 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060021195
21196 int vulkanSupport = InitVulkan();
21197 if (vulkanSupport == 0) {
21198 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
21199 return;
21200 }
21201
21202 app->onAppCmd = processCommand;
21203 app->onInputEvent = processInput;
21204
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021205 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021206 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021207 struct android_poll_source *source;
21208 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021209 if (source) {
21210 source->process(app, source);
21211 }
21212
21213 if (app->destroyRequested != 0) {
21214 VkTestFramework::Finish();
21215 return;
21216 }
21217 }
21218
21219 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021220 // Use the following key to send arguments to gtest, i.e.
21221 // --es args "--gtest_filter=-VkLayerTest.foo"
21222 const char key[] = "args";
21223 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021225 std::string filter = "";
21226 if (args.size() > 0) {
21227 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
21228 filter += args[0];
21229 } else {
21230 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
21231 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021232
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021233 int argc = 2;
21234 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
21235 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021236
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021237 // Route output to files until we can override the gtest output
21238 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
21239 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021241 ::testing::InitGoogleTest(&argc, argv);
21242 VkTestFramework::InitArgs(&argc, argv);
21243 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021245 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021246
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021247 if (result != 0) {
21248 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
21249 } else {
21250 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
21251 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021252
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021253 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021255 fclose(stdout);
21256 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021258 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021260 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021261 }
21262 }
21263}
21264#endif
21265
Tony Barbour300a6082015-04-07 13:44:53 -060021266int main(int argc, char **argv) {
21267 int result;
21268
Cody Northrop8e54a402016-03-08 22:25:52 -070021269#ifdef ANDROID
21270 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021271 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070021272#endif
21273
Tony Barbour300a6082015-04-07 13:44:53 -060021274 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060021275 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060021276
21277 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
21278
21279 result = RUN_ALL_TESTS();
21280
Tony Barbour6918cd52015-04-09 12:58:51 -060021281 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060021282 return result;
21283}