blob: b2dbb2df9763c3a3edd3a3fe153808c1384dccf0 [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;
8341 VkDeviceSize dataSize = 1024;
Karl Schultzee344492016-07-11 15:09:57 -06008342 const void *pData = NULL;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008343
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008344 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, pData);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008345
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008346 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008347}
8348
Karl Schultz6addd812016-02-02 17:17:23 -07008349TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008350 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8352 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008353
8354 ASSERT_NO_FATAL_FAILURE(InitState());
8355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008356
Tony Barbour552f6c02016-12-21 14:34:07 -07008357 m_commandBuffer->BeginCommandBuffer();
8358 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008359
Michael Lentine0a369f62016-02-03 16:51:46 -06008360 VkClearColorValue clear_color;
8361 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008362 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8363 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8364 const int32_t tex_width = 32;
8365 const int32_t tex_height = 32;
8366 VkImageCreateInfo image_create_info = {};
8367 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8368 image_create_info.pNext = NULL;
8369 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8370 image_create_info.format = tex_format;
8371 image_create_info.extent.width = tex_width;
8372 image_create_info.extent.height = tex_height;
8373 image_create_info.extent.depth = 1;
8374 image_create_info.mipLevels = 1;
8375 image_create_info.arrayLayers = 1;
8376 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8377 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8378 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008379
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008380 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008381 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008382
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008383 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008385 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008386
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008387 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008388}
8389
Karl Schultz6addd812016-02-02 17:17:23 -07008390TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008391 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8393 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008394
8395 ASSERT_NO_FATAL_FAILURE(InitState());
8396 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008397
Tony Barbour552f6c02016-12-21 14:34:07 -07008398 m_commandBuffer->BeginCommandBuffer();
8399 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008400
8401 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008402 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008403 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8404 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8405 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8406 image_create_info.extent.width = 64;
8407 image_create_info.extent.height = 64;
8408 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8409 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008410
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008411 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008412 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008413
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008414 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008415
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008416 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8417 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008418
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008419 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008420}
8421
Karl Schultz6addd812016-02-02 17:17:23 -07008422TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008423 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008424 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008425
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008426 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8427 "vkCmdClearAttachments(): This call "
8428 "must be issued inside an active "
8429 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008430
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008431 ASSERT_NO_FATAL_FAILURE(InitState());
8432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008433
8434 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008435 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008436 ASSERT_VK_SUCCESS(err);
8437
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008438 VkClearAttachment color_attachment;
8439 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8440 color_attachment.clearValue.color.float32[0] = 0;
8441 color_attachment.clearValue.color.float32[1] = 0;
8442 color_attachment.clearValue.color.float32[2] = 0;
8443 color_attachment.clearValue.color.float32[3] = 0;
8444 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008445 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008446 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008447
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008448 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008449}
8450
Chris Forbes3b97e932016-09-07 11:29:24 +12008451TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008452 TEST_DESCRIPTION(
8453 "Test that an error is produced when CmdNextSubpass is "
8454 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008455
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8457 "vkCmdNextSubpass(): Attempted to advance "
8458 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008459
8460 ASSERT_NO_FATAL_FAILURE(InitState());
8461 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8462
Tony Barbour552f6c02016-12-21 14:34:07 -07008463 m_commandBuffer->BeginCommandBuffer();
8464 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008465
8466 // error here.
8467 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8468 m_errorMonitor->VerifyFound();
8469
Tony Barbour552f6c02016-12-21 14:34:07 -07008470 m_commandBuffer->EndRenderPass();
8471 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008472}
8473
Chris Forbes6d624702016-09-07 13:57:05 +12008474TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008475 TEST_DESCRIPTION(
8476 "Test that an error is produced when CmdEndRenderPass is "
8477 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008478
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008479 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8480 "vkCmdEndRenderPass(): Called before reaching "
8481 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008482
8483 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008484 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8485 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008488
8489 VkRenderPass rp;
8490 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8491 ASSERT_VK_SUCCESS(err);
8492
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008493 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008494
8495 VkFramebuffer fb;
8496 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8497 ASSERT_VK_SUCCESS(err);
8498
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008499 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008500
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008501 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 +12008502
8503 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8504
8505 // Error here.
8506 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8507 m_errorMonitor->VerifyFound();
8508
8509 // Clean up.
8510 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8511 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8512}
8513
Karl Schultz9e66a292016-04-21 15:57:51 -06008514TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8515 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8517 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008518
8519 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008520 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008521
8522 VkBufferMemoryBarrier buf_barrier = {};
8523 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8524 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8525 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8526 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8527 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8528 buf_barrier.buffer = VK_NULL_HANDLE;
8529 buf_barrier.offset = 0;
8530 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008531 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8532 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008533
8534 m_errorMonitor->VerifyFound();
8535}
8536
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008537TEST_F(VkLayerTest, InvalidBarriers) {
8538 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8539
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008541
8542 ASSERT_NO_FATAL_FAILURE(InitState());
8543 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8544
8545 VkMemoryBarrier mem_barrier = {};
8546 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8547 mem_barrier.pNext = NULL;
8548 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8549 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008550 m_commandBuffer->BeginCommandBuffer();
8551 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008552 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008553 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008554 &mem_barrier, 0, nullptr, 0, nullptr);
8555 m_errorMonitor->VerifyFound();
8556
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008557 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008558 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008559 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 -06008560 ASSERT_TRUE(image.initialized());
8561 VkImageMemoryBarrier img_barrier = {};
8562 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8563 img_barrier.pNext = NULL;
8564 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8565 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8566 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8567 // New layout can't be UNDEFINED
8568 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8569 img_barrier.image = image.handle();
8570 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8571 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8572 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8573 img_barrier.subresourceRange.baseArrayLayer = 0;
8574 img_barrier.subresourceRange.baseMipLevel = 0;
8575 img_barrier.subresourceRange.layerCount = 1;
8576 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008577 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8578 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008579 m_errorMonitor->VerifyFound();
8580 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8581
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008582 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8583 "Subresource must have the sum of the "
8584 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008585 // baseArrayLayer + layerCount must be <= image's arrayLayers
8586 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008587 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8588 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008589 m_errorMonitor->VerifyFound();
8590 img_barrier.subresourceRange.baseArrayLayer = 0;
8591
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008593 // baseMipLevel + levelCount must be <= image's mipLevels
8594 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008595 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8596 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008597 m_errorMonitor->VerifyFound();
8598 img_barrier.subresourceRange.baseMipLevel = 0;
8599
Mike Weiblen7053aa32017-01-25 15:21:10 -07008600 // levelCount must be non-zero.
8601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8602 img_barrier.subresourceRange.levelCount = 0;
8603 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8604 nullptr, 0, nullptr, 1, &img_barrier);
8605 m_errorMonitor->VerifyFound();
8606 img_barrier.subresourceRange.levelCount = 1;
8607
8608 // layerCount must be non-zero.
8609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8610 img_barrier.subresourceRange.layerCount = 0;
8611 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8612 nullptr, 0, nullptr, 1, &img_barrier);
8613 m_errorMonitor->VerifyFound();
8614 img_barrier.subresourceRange.layerCount = 1;
8615
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008616 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 -06008617 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008618 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8619 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008620 VkBufferMemoryBarrier buf_barrier = {};
8621 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8622 buf_barrier.pNext = NULL;
8623 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8624 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8625 buf_barrier.buffer = buffer.handle();
8626 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8627 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8628 buf_barrier.offset = 0;
8629 buf_barrier.size = VK_WHOLE_SIZE;
8630 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008631 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8632 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008633 m_errorMonitor->VerifyFound();
8634 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8635
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008636 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008637 buf_barrier.offset = 257;
8638 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008639 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8640 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008641 m_errorMonitor->VerifyFound();
8642 buf_barrier.offset = 0;
8643
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008645 buf_barrier.size = 257;
8646 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8648 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008649 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008650
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008651 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008652 m_errorMonitor->SetDesiredFailureMsg(
8653 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008654 "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 -06008655 VkDepthStencilObj ds_image(m_device);
8656 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
8657 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06008658 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
8659 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008660 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008661
8662 // Not having DEPTH or STENCIL set is an error
8663 img_barrier.subresourceRange.aspectMask = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8665 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008666 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07008667
8668 // Having anything other than DEPTH or STENCIL is an error
8669 m_errorMonitor->SetDesiredFailureMsg(
8670 VK_DEBUG_REPORT_ERROR_BIT_EXT,
8671 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
8672 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
8673 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8674 nullptr, 0, nullptr, 1, &img_barrier);
8675 m_errorMonitor->VerifyFound();
8676
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008677 // Now test depth-only
8678 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008679 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
8680 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008681 VkDepthStencilObj d_image(m_device);
8682 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
8683 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008684 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008685 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008686 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008687
8688 // DEPTH bit must be set
8689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8690 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8691 img_barrier.subresourceRange.aspectMask = 0;
8692 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8693 0, nullptr, 0, nullptr, 1, &img_barrier);
8694 m_errorMonitor->VerifyFound();
8695
8696 // No bits other than DEPTH may be set
8697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8698 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
8699 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008700 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8701 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008702 m_errorMonitor->VerifyFound();
8703 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008704
8705 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008706 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
8707 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06008708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8709 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008710 VkDepthStencilObj s_image(m_device);
8711 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
8712 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008713 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06008714 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008715 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06008716 // Use of COLOR aspect on depth image is error
8717 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008718 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
8719 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008720 m_errorMonitor->VerifyFound();
8721 }
Dave Houltonfbf52152017-01-06 12:55:29 -07008722
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008723 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008724 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008725 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 -06008726 ASSERT_TRUE(c_image.initialized());
8727 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8728 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
8729 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07008730
8731 // COLOR bit must be set
8732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8733 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
8734 img_barrier.subresourceRange.aspectMask = 0;
8735 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8736 nullptr, 0, nullptr, 1, &img_barrier);
8737 m_errorMonitor->VerifyFound();
8738
8739 // No bits other than COLOR may be set
8740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8741 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
8742 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008743 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8744 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06008745 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008746
8747 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
8748
8749 // Create command pool with incompatible queueflags
8750 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
8751 uint32_t queue_family_index = UINT32_MAX;
8752 for (uint32_t i = 0; i < queue_props.size(); i++) {
8753 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
8754 queue_family_index = i;
8755 break;
8756 }
8757 }
8758 if (queue_family_index == UINT32_MAX) {
8759 printf("No non-compute queue found; skipped.\n");
8760 return;
8761 }
8762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
8763
8764 VkCommandPool command_pool;
8765 VkCommandPoolCreateInfo pool_create_info{};
8766 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
8767 pool_create_info.queueFamilyIndex = queue_family_index;
8768 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
8769 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
8770
8771 // Allocate a command buffer
8772 VkCommandBuffer bad_command_buffer;
8773 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
8774 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
8775 command_buffer_allocate_info.commandPool = command_pool;
8776 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
8777 command_buffer_allocate_info.commandBufferCount = 1;
8778 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
8779
8780 VkCommandBufferBeginInfo cbbi = {};
8781 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8782 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
8783 buf_barrier.offset = 0;
8784 buf_barrier.size = VK_WHOLE_SIZE;
8785 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
8786 &buf_barrier, 0, nullptr);
8787 m_errorMonitor->VerifyFound();
8788
8789 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
8790 vkEndCommandBuffer(bad_command_buffer);
8791 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
8792 printf("The non-compute queue does not support graphics; skipped.\n");
8793 return;
8794 }
8795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
8796 VkEvent event;
8797 VkEventCreateInfo event_create_info{};
8798 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
8799 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
8800 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
8801 nullptr, 0, nullptr);
8802 m_errorMonitor->VerifyFound();
8803
8804 vkEndCommandBuffer(bad_command_buffer);
8805 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008806}
8807
Tony Barbour18ba25c2016-09-29 13:42:40 -06008808TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
8809 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
8810
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06008812 ASSERT_NO_FATAL_FAILURE(InitState());
8813 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06008814 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 -06008815 ASSERT_TRUE(image.initialized());
8816
8817 VkImageMemoryBarrier barrier = {};
8818 VkImageSubresourceRange range;
8819 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8820 barrier.srcAccessMask = 0;
8821 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
8822 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
8823 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8824 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8825 barrier.image = image.handle();
8826 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8827 range.baseMipLevel = 0;
8828 range.levelCount = 1;
8829 range.baseArrayLayer = 0;
8830 range.layerCount = 1;
8831 barrier.subresourceRange = range;
8832 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
8833 cmdbuf.BeginCommandBuffer();
8834 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8835 &barrier);
8836 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
8837 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
8838 barrier.srcAccessMask = 0;
8839 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
8840 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
8841 &barrier);
8842
8843 m_errorMonitor->VerifyFound();
8844}
8845
Karl Schultz6addd812016-02-02 17:17:23 -07008846TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008847 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008848 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008849
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008851
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008852 ASSERT_NO_FATAL_FAILURE(InitState());
8853 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008854 uint32_t qfi = 0;
8855 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008856 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8857 buffCI.size = 1024;
8858 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8859 buffCI.queueFamilyIndexCount = 1;
8860 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008861
8862 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08008863 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008864 ASSERT_VK_SUCCESS(err);
8865
Tony Barbour552f6c02016-12-21 14:34:07 -07008866 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008867 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07008868 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
8869 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008870 // Should error before calling to driver so don't care about actual data
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008871 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008872
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008873 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06008874
Chia-I Wuf7458c52015-10-26 21:10:41 +08008875 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06008876}
8877
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008878TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
8879 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008880 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8881 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
8882 "of the indices specified when the device was created, via the "
8883 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008884
8885 ASSERT_NO_FATAL_FAILURE(InitState());
8886 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8887 VkBufferCreateInfo buffCI = {};
8888 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
8889 buffCI.size = 1024;
8890 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
8891 buffCI.queueFamilyIndexCount = 1;
8892 // Introduce failure by specifying invalid queue_family_index
8893 uint32_t qfi = 777;
8894 buffCI.pQueueFamilyIndices = &qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008895 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008896
8897 VkBuffer ib;
8898 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
8899
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008900 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008901 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07008902}
8903
Karl Schultz6addd812016-02-02 17:17:23 -07008904TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008905 TEST_DESCRIPTION(
8906 "Attempt vkCmdExecuteCommands with a primary command buffer"
8907 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008908
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008909 ASSERT_NO_FATAL_FAILURE(InitState());
8910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008911
Chris Forbesf29a84f2016-10-06 18:39:28 +13008912 // An empty primary command buffer
8913 VkCommandBufferObj cb(m_device, m_commandPool);
8914 cb.BeginCommandBuffer();
8915 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06008916
Chris Forbesf29a84f2016-10-06 18:39:28 +13008917 m_commandBuffer->BeginCommandBuffer();
8918 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
8919 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008920
Chris Forbesf29a84f2016-10-06 18:39:28 +13008921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
8922 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008923 m_errorMonitor->VerifyFound();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06008924}
8925
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008926TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008927 TEST_DESCRIPTION(
8928 "Attempt to update descriptor sets for images and buffers "
8929 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008930 VkResult err;
8931
8932 ASSERT_NO_FATAL_FAILURE(InitState());
8933 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8934 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8935 ds_type_count[i].type = VkDescriptorType(i);
8936 ds_type_count[i].descriptorCount = 1;
8937 }
8938 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8939 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8940 ds_pool_ci.pNext = NULL;
8941 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8942 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8943 ds_pool_ci.pPoolSizes = ds_type_count;
8944
8945 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008946 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008947 ASSERT_VK_SUCCESS(err);
8948
8949 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008950 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008951 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8952 dsl_binding[i].binding = 0;
8953 dsl_binding[i].descriptorType = VkDescriptorType(i);
8954 dsl_binding[i].descriptorCount = 1;
8955 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
8956 dsl_binding[i].pImmutableSamplers = NULL;
8957 }
8958
8959 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8960 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8961 ds_layout_ci.pNext = NULL;
8962 ds_layout_ci.bindingCount = 1;
8963 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
8964 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
8965 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008966 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008967 ASSERT_VK_SUCCESS(err);
8968 }
8969 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
8970 VkDescriptorSetAllocateInfo alloc_info = {};
8971 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8972 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
8973 alloc_info.descriptorPool = ds_pool;
8974 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008975 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008976 ASSERT_VK_SUCCESS(err);
8977
8978 // Create a buffer & bufferView to be used for invalid updates
8979 VkBufferCreateInfo buff_ci = {};
8980 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07008981 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008982 buff_ci.size = 256;
8983 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07008984 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06008985 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
8986 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07008987
8988 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
8989 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
8990 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
8991 ASSERT_VK_SUCCESS(err);
8992
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07008993 VkMemoryRequirements mem_reqs;
8994 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
8995 VkMemoryAllocateInfo mem_alloc_info = {};
8996 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
8997 mem_alloc_info.pNext = NULL;
8998 mem_alloc_info.memoryTypeIndex = 0;
8999 mem_alloc_info.allocationSize = mem_reqs.size;
9000 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9001 if (!pass) {
9002 vkDestroyBuffer(m_device->device(), buffer, NULL);
9003 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9004 return;
9005 }
9006 VkDeviceMemory mem;
9007 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9008 ASSERT_VK_SUCCESS(err);
9009 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9010 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009011
9012 VkBufferViewCreateInfo buff_view_ci = {};
9013 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9014 buff_view_ci.buffer = buffer;
9015 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9016 buff_view_ci.range = VK_WHOLE_SIZE;
9017 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009018 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009019 ASSERT_VK_SUCCESS(err);
9020
Tony Barbour415497c2017-01-24 10:06:09 -07009021 // Now get resources / view for storage_texel_buffer
9022 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9023 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9024 if (!pass) {
9025 vkDestroyBuffer(m_device->device(), buffer, NULL);
9026 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9027 vkFreeMemory(m_device->device(), mem, NULL);
9028 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9029 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9030 return;
9031 }
9032 VkDeviceMemory storage_texel_buffer_mem;
9033 VkBufferView storage_texel_buffer_view;
9034 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9035 ASSERT_VK_SUCCESS(err);
9036 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9037 ASSERT_VK_SUCCESS(err);
9038 buff_view_ci.buffer = storage_texel_buffer;
9039 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9040 ASSERT_VK_SUCCESS(err);
9041
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009042 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009043 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009044 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009045 image_ci.format = VK_FORMAT_UNDEFINED;
9046 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9047 VkFormat format = static_cast<VkFormat>(f);
9048 VkFormatProperties fProps = m_device->format_properties(format);
9049 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9050 image_ci.format = format;
9051 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9052 break;
9053 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9054 image_ci.format = format;
9055 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9056 break;
9057 }
9058 }
9059 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9060 return;
9061 }
9062
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009063 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9064 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009065 image_ci.extent.width = 64;
9066 image_ci.extent.height = 64;
9067 image_ci.extent.depth = 1;
9068 image_ci.mipLevels = 1;
9069 image_ci.arrayLayers = 1;
9070 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009071 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009072 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009073 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9074 VkImage image;
9075 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9076 ASSERT_VK_SUCCESS(err);
9077 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009078 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009079
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009080 VkMemoryAllocateInfo mem_alloc = {};
9081 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9082 mem_alloc.pNext = NULL;
9083 mem_alloc.allocationSize = 0;
9084 mem_alloc.memoryTypeIndex = 0;
9085 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9086 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009087 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009088 ASSERT_TRUE(pass);
9089 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9090 ASSERT_VK_SUCCESS(err);
9091 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9092 ASSERT_VK_SUCCESS(err);
9093 // Now create view for image
9094 VkImageViewCreateInfo image_view_ci = {};
9095 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9096 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009097 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009098 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9099 image_view_ci.subresourceRange.layerCount = 1;
9100 image_view_ci.subresourceRange.baseArrayLayer = 0;
9101 image_view_ci.subresourceRange.levelCount = 1;
9102 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9103 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009104 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009105 ASSERT_VK_SUCCESS(err);
9106
9107 VkDescriptorBufferInfo buff_info = {};
9108 buff_info.buffer = buffer;
9109 VkDescriptorImageInfo img_info = {};
9110 img_info.imageView = image_view;
9111 VkWriteDescriptorSet descriptor_write = {};
9112 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9113 descriptor_write.dstBinding = 0;
9114 descriptor_write.descriptorCount = 1;
9115 descriptor_write.pTexelBufferView = &buff_view;
9116 descriptor_write.pBufferInfo = &buff_info;
9117 descriptor_write.pImageInfo = &img_info;
9118
9119 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009120 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009121 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9122 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9123 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9124 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9125 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9126 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9127 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9128 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9129 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9130 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9131 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009132 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009133 // Start loop at 1 as SAMPLER desc type has no usage bit error
9134 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009135 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9136 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9137 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9138 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009139 descriptor_write.descriptorType = VkDescriptorType(i);
9140 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009141 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009142
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009143 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009144
9145 m_errorMonitor->VerifyFound();
9146 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009147 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9148 descriptor_write.pTexelBufferView = &buff_view;
9149 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009150 }
Tony Barbour415497c2017-01-24 10:06:09 -07009151
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009152 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9153 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009154 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009155 vkDestroyImageView(m_device->device(), image_view, NULL);
9156 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009157 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009158 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009159 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009160 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009161 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009162 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9163}
9164
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009165TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009166 TEST_DESCRIPTION(
9167 "Attempt to update buffer descriptor set that has incorrect "
9168 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9169 "1. offset value greater than buffer size\n"
9170 "2. range value of 0\n"
9171 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009172 VkResult err;
9173
9174 ASSERT_NO_FATAL_FAILURE(InitState());
9175 VkDescriptorPoolSize ds_type_count = {};
9176 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9177 ds_type_count.descriptorCount = 1;
9178
9179 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9180 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9181 ds_pool_ci.pNext = NULL;
9182 ds_pool_ci.maxSets = 1;
9183 ds_pool_ci.poolSizeCount = 1;
9184 ds_pool_ci.pPoolSizes = &ds_type_count;
9185
9186 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009187 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009188 ASSERT_VK_SUCCESS(err);
9189
9190 // Create layout with single uniform buffer descriptor
9191 VkDescriptorSetLayoutBinding dsl_binding = {};
9192 dsl_binding.binding = 0;
9193 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9194 dsl_binding.descriptorCount = 1;
9195 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9196 dsl_binding.pImmutableSamplers = NULL;
9197
9198 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9199 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9200 ds_layout_ci.pNext = NULL;
9201 ds_layout_ci.bindingCount = 1;
9202 ds_layout_ci.pBindings = &dsl_binding;
9203 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009204 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009205 ASSERT_VK_SUCCESS(err);
9206
9207 VkDescriptorSet descriptor_set = {};
9208 VkDescriptorSetAllocateInfo alloc_info = {};
9209 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9210 alloc_info.descriptorSetCount = 1;
9211 alloc_info.descriptorPool = ds_pool;
9212 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009213 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009214 ASSERT_VK_SUCCESS(err);
9215
9216 // Create a buffer to be used for invalid updates
9217 VkBufferCreateInfo buff_ci = {};
9218 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9219 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9220 buff_ci.size = 256;
9221 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9222 VkBuffer buffer;
9223 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9224 ASSERT_VK_SUCCESS(err);
9225 // Have to bind memory to buffer before descriptor update
9226 VkMemoryAllocateInfo mem_alloc = {};
9227 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9228 mem_alloc.pNext = NULL;
9229 mem_alloc.allocationSize = 256;
9230 mem_alloc.memoryTypeIndex = 0;
9231
9232 VkMemoryRequirements mem_reqs;
9233 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009234 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009235 if (!pass) {
9236 vkDestroyBuffer(m_device->device(), buffer, NULL);
9237 return;
9238 }
9239
9240 VkDeviceMemory mem;
9241 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9242 ASSERT_VK_SUCCESS(err);
9243 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9244 ASSERT_VK_SUCCESS(err);
9245
9246 VkDescriptorBufferInfo buff_info = {};
9247 buff_info.buffer = buffer;
9248 // First make offset 1 larger than buffer size
9249 buff_info.offset = 257;
9250 buff_info.range = VK_WHOLE_SIZE;
9251 VkWriteDescriptorSet descriptor_write = {};
9252 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9253 descriptor_write.dstBinding = 0;
9254 descriptor_write.descriptorCount = 1;
9255 descriptor_write.pTexelBufferView = nullptr;
9256 descriptor_write.pBufferInfo = &buff_info;
9257 descriptor_write.pImageInfo = nullptr;
9258
9259 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9260 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009262
9263 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9264
9265 m_errorMonitor->VerifyFound();
9266 // Now cause error due to range of 0
9267 buff_info.offset = 0;
9268 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009270
9271 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9272
9273 m_errorMonitor->VerifyFound();
9274 // Now cause error due to range exceeding buffer size - offset
9275 buff_info.offset = 128;
9276 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009278
9279 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9280
9281 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009282 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009283 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9284 vkDestroyBuffer(m_device->device(), buffer, NULL);
9285 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9286 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9287}
9288
Tobin Ehlis845887e2017-02-02 19:01:44 -07009289TEST_F(VkLayerTest, DSBufferLimitErrors) {
9290 TEST_DESCRIPTION(
9291 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9292 "Test cases include:\n"
9293 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9294 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9295 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9296 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9297 VkResult err;
9298
9299 ASSERT_NO_FATAL_FAILURE(InitState());
9300 VkDescriptorPoolSize ds_type_count[2] = {};
9301 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9302 ds_type_count[0].descriptorCount = 1;
9303 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9304 ds_type_count[1].descriptorCount = 1;
9305
9306 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9307 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9308 ds_pool_ci.pNext = NULL;
9309 ds_pool_ci.maxSets = 1;
9310 ds_pool_ci.poolSizeCount = 2;
9311 ds_pool_ci.pPoolSizes = ds_type_count;
9312
9313 VkDescriptorPool ds_pool;
9314 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9315 ASSERT_VK_SUCCESS(err);
9316
9317 // Create layout with single uniform buffer & single storage buffer descriptor
9318 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9319 dsl_binding[0].binding = 0;
9320 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9321 dsl_binding[0].descriptorCount = 1;
9322 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9323 dsl_binding[0].pImmutableSamplers = NULL;
9324 dsl_binding[1].binding = 1;
9325 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9326 dsl_binding[1].descriptorCount = 1;
9327 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9328 dsl_binding[1].pImmutableSamplers = NULL;
9329
9330 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9331 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9332 ds_layout_ci.pNext = NULL;
9333 ds_layout_ci.bindingCount = 2;
9334 ds_layout_ci.pBindings = dsl_binding;
9335 VkDescriptorSetLayout ds_layout;
9336 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9337 ASSERT_VK_SUCCESS(err);
9338
9339 VkDescriptorSet descriptor_set = {};
9340 VkDescriptorSetAllocateInfo alloc_info = {};
9341 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9342 alloc_info.descriptorSetCount = 1;
9343 alloc_info.descriptorPool = ds_pool;
9344 alloc_info.pSetLayouts = &ds_layout;
9345 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9346 ASSERT_VK_SUCCESS(err);
9347
9348 // Create a buffer to be used for invalid updates
9349 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9350 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9351 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9352 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9353 VkBufferCreateInfo ub_ci = {};
9354 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9355 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9356 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9357 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9358 VkBuffer uniform_buffer;
9359 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9360 ASSERT_VK_SUCCESS(err);
9361 VkBufferCreateInfo sb_ci = {};
9362 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9363 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9364 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9365 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9366 VkBuffer storage_buffer;
9367 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9368 ASSERT_VK_SUCCESS(err);
9369 // Have to bind memory to buffer before descriptor update
9370 VkMemoryAllocateInfo mem_alloc = {};
9371 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9372 mem_alloc.pNext = NULL;
9373 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9374 mem_alloc.memoryTypeIndex = 0;
9375
9376 VkMemoryRequirements mem_reqs;
9377 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9378 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9379 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9380 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9381 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009382 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009383 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009384 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9385 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009386 return;
9387 }
9388
9389 VkDeviceMemory mem;
9390 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009391 if (VK_SUCCESS != err) {
9392 printf("Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
9393 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9394 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9395 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9396 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9397 return;
9398 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009399 ASSERT_VK_SUCCESS(err);
9400 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9401 ASSERT_VK_SUCCESS(err);
9402 auto sb_offset = ub_ci.size + 1024;
9403 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9404 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9405 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9406 ASSERT_VK_SUCCESS(err);
9407
9408 VkDescriptorBufferInfo buff_info = {};
9409 buff_info.buffer = uniform_buffer;
9410 buff_info.range = ub_ci.size; // This will exceed limit
9411 VkWriteDescriptorSet descriptor_write = {};
9412 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9413 descriptor_write.dstBinding = 0;
9414 descriptor_write.descriptorCount = 1;
9415 descriptor_write.pTexelBufferView = nullptr;
9416 descriptor_write.pBufferInfo = &buff_info;
9417 descriptor_write.pImageInfo = nullptr;
9418
9419 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9420 descriptor_write.dstSet = descriptor_set;
9421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9422 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9423 m_errorMonitor->VerifyFound();
9424
9425 // Reduce size of range to acceptable limit & cause offset error
9426 buff_info.range = max_ub_range;
9427 buff_info.offset = min_ub_align - 1;
9428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9429 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9430 m_errorMonitor->VerifyFound();
9431
9432 // Now break storage updates
9433 buff_info.buffer = storage_buffer;
9434 buff_info.range = sb_ci.size; // This will exceed limit
9435 buff_info.offset = 0; // Reset offset for this update
9436
9437 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9438 descriptor_write.dstBinding = 1;
9439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9440 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9441 m_errorMonitor->VerifyFound();
9442
9443 // Reduce size of range to acceptable limit & cause offset error
9444 buff_info.range = max_sb_range;
9445 buff_info.offset = min_sb_align - 1;
9446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9447 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9448 m_errorMonitor->VerifyFound();
9449
9450 vkFreeMemory(m_device->device(), mem, NULL);
9451 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9452 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9453 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9454 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9455}
9456
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009457TEST_F(VkLayerTest, DSAspectBitsErrors) {
9458 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9459 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009460 TEST_DESCRIPTION(
9461 "Attempt to update descriptor sets for images "
9462 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009463 VkResult err;
9464
9465 ASSERT_NO_FATAL_FAILURE(InitState());
9466 VkDescriptorPoolSize ds_type_count = {};
9467 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9468 ds_type_count.descriptorCount = 1;
9469
9470 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9471 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9472 ds_pool_ci.pNext = NULL;
9473 ds_pool_ci.maxSets = 5;
9474 ds_pool_ci.poolSizeCount = 1;
9475 ds_pool_ci.pPoolSizes = &ds_type_count;
9476
9477 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009479 ASSERT_VK_SUCCESS(err);
9480
9481 VkDescriptorSetLayoutBinding dsl_binding = {};
9482 dsl_binding.binding = 0;
9483 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9484 dsl_binding.descriptorCount = 1;
9485 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9486 dsl_binding.pImmutableSamplers = NULL;
9487
9488 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9489 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9490 ds_layout_ci.pNext = NULL;
9491 ds_layout_ci.bindingCount = 1;
9492 ds_layout_ci.pBindings = &dsl_binding;
9493 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009495 ASSERT_VK_SUCCESS(err);
9496
9497 VkDescriptorSet descriptor_set = {};
9498 VkDescriptorSetAllocateInfo alloc_info = {};
9499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9500 alloc_info.descriptorSetCount = 1;
9501 alloc_info.descriptorPool = ds_pool;
9502 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009504 ASSERT_VK_SUCCESS(err);
9505
9506 // Create an image to be used for invalid updates
9507 VkImageCreateInfo image_ci = {};
9508 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9509 image_ci.imageType = VK_IMAGE_TYPE_2D;
9510 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9511 image_ci.extent.width = 64;
9512 image_ci.extent.height = 64;
9513 image_ci.extent.depth = 1;
9514 image_ci.mipLevels = 1;
9515 image_ci.arrayLayers = 1;
9516 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9517 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9518 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9519 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9520 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9521 VkImage image;
9522 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9523 ASSERT_VK_SUCCESS(err);
9524 // Bind memory to image
9525 VkMemoryRequirements mem_reqs;
9526 VkDeviceMemory image_mem;
9527 bool pass;
9528 VkMemoryAllocateInfo mem_alloc = {};
9529 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9530 mem_alloc.pNext = NULL;
9531 mem_alloc.allocationSize = 0;
9532 mem_alloc.memoryTypeIndex = 0;
9533 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9534 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009535 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009536 ASSERT_TRUE(pass);
9537 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9538 ASSERT_VK_SUCCESS(err);
9539 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9540 ASSERT_VK_SUCCESS(err);
9541 // Now create view for image
9542 VkImageViewCreateInfo image_view_ci = {};
9543 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9544 image_view_ci.image = image;
9545 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9546 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9547 image_view_ci.subresourceRange.layerCount = 1;
9548 image_view_ci.subresourceRange.baseArrayLayer = 0;
9549 image_view_ci.subresourceRange.levelCount = 1;
9550 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009551 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009552
9553 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009554 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009555 ASSERT_VK_SUCCESS(err);
9556
9557 VkDescriptorImageInfo img_info = {};
9558 img_info.imageView = image_view;
9559 VkWriteDescriptorSet descriptor_write = {};
9560 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9561 descriptor_write.dstBinding = 0;
9562 descriptor_write.descriptorCount = 1;
9563 descriptor_write.pTexelBufferView = NULL;
9564 descriptor_write.pBufferInfo = NULL;
9565 descriptor_write.pImageInfo = &img_info;
9566 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9567 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009568 const char *error_msg =
9569 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9570 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009572
9573 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9574
9575 m_errorMonitor->VerifyFound();
9576 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9577 vkDestroyImage(m_device->device(), image, NULL);
9578 vkFreeMemory(m_device->device(), image_mem, NULL);
9579 vkDestroyImageView(m_device->device(), image_view, NULL);
9580 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9581 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9582}
9583
Karl Schultz6addd812016-02-02 17:17:23 -07009584TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009585 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009586 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009587
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9589 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9590 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009591
Tobin Ehlis3b780662015-05-28 12:11:26 -06009592 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009593 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009594 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009595 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9596 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009597
9598 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009599 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9600 ds_pool_ci.pNext = NULL;
9601 ds_pool_ci.maxSets = 1;
9602 ds_pool_ci.poolSizeCount = 1;
9603 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009604
Tobin Ehlis3b780662015-05-28 12:11:26 -06009605 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009606 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009607 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009608 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009609 dsl_binding.binding = 0;
9610 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9611 dsl_binding.descriptorCount = 1;
9612 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9613 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009614
Tony Barboureb254902015-07-15 12:50:33 -06009615 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009616 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9617 ds_layout_ci.pNext = NULL;
9618 ds_layout_ci.bindingCount = 1;
9619 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009620
Tobin Ehlis3b780662015-05-28 12:11:26 -06009621 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009622 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009623 ASSERT_VK_SUCCESS(err);
9624
9625 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009626 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009627 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009628 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009629 alloc_info.descriptorPool = ds_pool;
9630 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009631 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009632 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009633
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009634 VkSamplerCreateInfo sampler_ci = {};
9635 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9636 sampler_ci.pNext = NULL;
9637 sampler_ci.magFilter = VK_FILTER_NEAREST;
9638 sampler_ci.minFilter = VK_FILTER_NEAREST;
9639 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9640 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9641 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9642 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9643 sampler_ci.mipLodBias = 1.0;
9644 sampler_ci.anisotropyEnable = VK_FALSE;
9645 sampler_ci.maxAnisotropy = 1;
9646 sampler_ci.compareEnable = VK_FALSE;
9647 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9648 sampler_ci.minLod = 1.0;
9649 sampler_ci.maxLod = 1.0;
9650 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9651 sampler_ci.unnormalizedCoordinates = VK_FALSE;
9652 VkSampler sampler;
9653 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9654 ASSERT_VK_SUCCESS(err);
9655
9656 VkDescriptorImageInfo info = {};
9657 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009658
9659 VkWriteDescriptorSet descriptor_write;
9660 memset(&descriptor_write, 0, sizeof(descriptor_write));
9661 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009662 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009663 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009664 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009665 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009666 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009667
9668 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9669
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009670 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009671
Chia-I Wuf7458c52015-10-26 21:10:41 +08009672 vkDestroySampler(m_device->device(), sampler, NULL);
9673 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9674 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009675}
9676
Karl Schultz6addd812016-02-02 17:17:23 -07009677TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009678 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -07009679 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009680
Tobin Ehlisf922ef82016-11-30 10:19:14 -07009681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009682
Tobin Ehlis3b780662015-05-28 12:11:26 -06009683 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009684 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009685 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009686 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9687 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009688
9689 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009690 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9691 ds_pool_ci.pNext = NULL;
9692 ds_pool_ci.maxSets = 1;
9693 ds_pool_ci.poolSizeCount = 1;
9694 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -06009695
Tobin Ehlis3b780662015-05-28 12:11:26 -06009696 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009697 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009698 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009699
Tony Barboureb254902015-07-15 12:50:33 -06009700 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009701 dsl_binding.binding = 0;
9702 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9703 dsl_binding.descriptorCount = 1;
9704 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9705 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009706
9707 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009708 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9709 ds_layout_ci.pNext = NULL;
9710 ds_layout_ci.bindingCount = 1;
9711 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009712
Tobin Ehlis3b780662015-05-28 12:11:26 -06009713 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009714 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009715 ASSERT_VK_SUCCESS(err);
9716
9717 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009718 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009719 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009720 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009721 alloc_info.descriptorPool = ds_pool;
9722 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009723 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009724 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009725
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009726 // Correctly update descriptor to avoid "NOT_UPDATED" error
9727 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009728 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -06009729 buff_info.offset = 0;
9730 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009731
9732 VkWriteDescriptorSet descriptor_write;
9733 memset(&descriptor_write, 0, sizeof(descriptor_write));
9734 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009735 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009736 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +08009737 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06009738 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9739 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009740
9741 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9742
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009743 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009744
Chia-I Wuf7458c52015-10-26 21:10:41 +08009745 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9746 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009747}
9748
Karl Schultz6addd812016-02-02 17:17:23 -07009749TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009750 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -07009751 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009752
Tobin Ehlisc8d352d2016-11-21 10:33:40 -07009753 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009754
Tobin Ehlis3b780662015-05-28 12:11:26 -06009755 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -07009756 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009757 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009758 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9759 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009760
9761 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009762 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9763 ds_pool_ci.pNext = NULL;
9764 ds_pool_ci.maxSets = 1;
9765 ds_pool_ci.poolSizeCount = 1;
9766 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009767
Tobin Ehlis3b780662015-05-28 12:11:26 -06009768 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009769 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009770 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009771
Tony Barboureb254902015-07-15 12:50:33 -06009772 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009773 dsl_binding.binding = 0;
9774 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9775 dsl_binding.descriptorCount = 1;
9776 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9777 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -06009778
9779 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009780 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9781 ds_layout_ci.pNext = NULL;
9782 ds_layout_ci.bindingCount = 1;
9783 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009784 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009785 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009786 ASSERT_VK_SUCCESS(err);
9787
9788 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009789 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009790 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009791 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009792 alloc_info.descriptorPool = ds_pool;
9793 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009794 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009795 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009796
Tony Barboureb254902015-07-15 12:50:33 -06009797 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009798 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9799 sampler_ci.pNext = NULL;
9800 sampler_ci.magFilter = VK_FILTER_NEAREST;
9801 sampler_ci.minFilter = VK_FILTER_NEAREST;
9802 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9803 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9804 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9805 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9806 sampler_ci.mipLodBias = 1.0;
9807 sampler_ci.anisotropyEnable = VK_FALSE;
9808 sampler_ci.maxAnisotropy = 1;
9809 sampler_ci.compareEnable = VK_FALSE;
9810 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9811 sampler_ci.minLod = 1.0;
9812 sampler_ci.maxLod = 1.0;
9813 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9814 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -06009815
Tobin Ehlis3b780662015-05-28 12:11:26 -06009816 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009817 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009818 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009819
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009820 VkDescriptorImageInfo info = {};
9821 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009822
9823 VkWriteDescriptorSet descriptor_write;
9824 memset(&descriptor_write, 0, sizeof(descriptor_write));
9825 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009826 descriptor_write.dstSet = descriptorSet;
9827 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +08009828 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009829 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009830 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -06009831 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009832
9833 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9834
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009835 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009836
Chia-I Wuf7458c52015-10-26 21:10:41 +08009837 vkDestroySampler(m_device->device(), sampler, NULL);
9838 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9839 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009840}
9841
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009842TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
9843 // Create layout w/ empty binding and attempt to update it
9844 VkResult err;
9845
9846 ASSERT_NO_FATAL_FAILURE(InitState());
9847
9848 VkDescriptorPoolSize ds_type_count = {};
9849 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
9850 ds_type_count.descriptorCount = 1;
9851
9852 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9853 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9854 ds_pool_ci.pNext = NULL;
9855 ds_pool_ci.maxSets = 1;
9856 ds_pool_ci.poolSizeCount = 1;
9857 ds_pool_ci.pPoolSizes = &ds_type_count;
9858
9859 VkDescriptorPool ds_pool;
9860 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9861 ASSERT_VK_SUCCESS(err);
9862
9863 VkDescriptorSetLayoutBinding dsl_binding = {};
9864 dsl_binding.binding = 0;
9865 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9866 dsl_binding.descriptorCount = 0;
9867 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9868 dsl_binding.pImmutableSamplers = NULL;
9869
9870 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9871 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9872 ds_layout_ci.pNext = NULL;
9873 ds_layout_ci.bindingCount = 1;
9874 ds_layout_ci.pBindings = &dsl_binding;
9875 VkDescriptorSetLayout ds_layout;
9876 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9877 ASSERT_VK_SUCCESS(err);
9878
9879 VkDescriptorSet descriptor_set;
9880 VkDescriptorSetAllocateInfo alloc_info = {};
9881 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9882 alloc_info.descriptorSetCount = 1;
9883 alloc_info.descriptorPool = ds_pool;
9884 alloc_info.pSetLayouts = &ds_layout;
9885 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9886 ASSERT_VK_SUCCESS(err);
9887
9888 VkSamplerCreateInfo sampler_ci = {};
9889 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9890 sampler_ci.magFilter = VK_FILTER_NEAREST;
9891 sampler_ci.minFilter = VK_FILTER_NEAREST;
9892 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9893 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9894 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9895 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9896 sampler_ci.mipLodBias = 1.0;
9897 sampler_ci.maxAnisotropy = 1;
9898 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9899 sampler_ci.minLod = 1.0;
9900 sampler_ci.maxLod = 1.0;
9901 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9902
9903 VkSampler sampler;
9904 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
9905 ASSERT_VK_SUCCESS(err);
9906
9907 VkDescriptorImageInfo info = {};
9908 info.sampler = sampler;
9909
9910 VkWriteDescriptorSet descriptor_write;
9911 memset(&descriptor_write, 0, sizeof(descriptor_write));
9912 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9913 descriptor_write.dstSet = descriptor_set;
9914 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009915 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -07009916 // This is the wrong type, but empty binding error will be flagged first
9917 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
9918 descriptor_write.pImageInfo = &info;
9919
9920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
9921 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9922 m_errorMonitor->VerifyFound();
9923
9924 vkDestroySampler(m_device->device(), sampler, NULL);
9925 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9926 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9927}
9928
Karl Schultz6addd812016-02-02 17:17:23 -07009929TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
9930 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
9931 // types
9932 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009934 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 -06009935
Tobin Ehlis3b780662015-05-28 12:11:26 -06009936 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06009937
Chia-I Wu1b99bb22015-10-27 19:25:11 +08009938 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009939 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9940 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06009941
9942 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009943 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9944 ds_pool_ci.pNext = NULL;
9945 ds_pool_ci.maxSets = 1;
9946 ds_pool_ci.poolSizeCount = 1;
9947 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -06009948
Tobin Ehlis3b780662015-05-28 12:11:26 -06009949 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009950 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009951 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -06009952 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009953 dsl_binding.binding = 0;
9954 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9955 dsl_binding.descriptorCount = 1;
9956 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9957 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009958
Tony Barboureb254902015-07-15 12:50:33 -06009959 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009960 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9961 ds_layout_ci.pNext = NULL;
9962 ds_layout_ci.bindingCount = 1;
9963 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06009964
Tobin Ehlis3b780662015-05-28 12:11:26 -06009965 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009966 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009967 ASSERT_VK_SUCCESS(err);
9968
9969 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08009970 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08009971 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07009972 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06009973 alloc_info.descriptorPool = ds_pool;
9974 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009975 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009976 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009977
Tony Barboureb254902015-07-15 12:50:33 -06009978 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009979 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
9980 sampler_ci.pNext = NULL;
9981 sampler_ci.magFilter = VK_FILTER_NEAREST;
9982 sampler_ci.minFilter = VK_FILTER_NEAREST;
9983 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
9984 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9985 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9986 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
9987 sampler_ci.mipLodBias = 1.0;
9988 sampler_ci.anisotropyEnable = VK_FALSE;
9989 sampler_ci.maxAnisotropy = 1;
9990 sampler_ci.compareEnable = VK_FALSE;
9991 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
9992 sampler_ci.minLod = 1.0;
9993 sampler_ci.maxLod = 1.0;
9994 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
9995 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009996 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009997 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -06009998 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +08009999
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010000 VkDescriptorImageInfo info = {};
10001 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010002
10003 VkWriteDescriptorSet descriptor_write;
10004 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010005 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010006 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010007 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010008 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010009 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010010 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010011
10012 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10013
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010014 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010015
Chia-I Wuf7458c52015-10-26 21:10:41 +080010016 vkDestroySampler(m_device->device(), sampler, NULL);
10017 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10018 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010019}
10020
Karl Schultz6addd812016-02-02 17:17:23 -070010021TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010022 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010023 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010024
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010025 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010026
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010027 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010028 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10029 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010030 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010031 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10032 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010033
10034 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010035 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10036 ds_pool_ci.pNext = NULL;
10037 ds_pool_ci.maxSets = 1;
10038 ds_pool_ci.poolSizeCount = 1;
10039 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010040
10041 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010042 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010043 ASSERT_VK_SUCCESS(err);
10044
10045 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010046 dsl_binding.binding = 0;
10047 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10048 dsl_binding.descriptorCount = 1;
10049 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10050 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010051
10052 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010053 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10054 ds_layout_ci.pNext = NULL;
10055 ds_layout_ci.bindingCount = 1;
10056 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010057 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010058 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010059 ASSERT_VK_SUCCESS(err);
10060
10061 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010062 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010063 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010064 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010065 alloc_info.descriptorPool = ds_pool;
10066 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010067 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010068 ASSERT_VK_SUCCESS(err);
10069
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010070 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010071
10072 VkDescriptorImageInfo descriptor_info;
10073 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10074 descriptor_info.sampler = sampler;
10075
10076 VkWriteDescriptorSet descriptor_write;
10077 memset(&descriptor_write, 0, sizeof(descriptor_write));
10078 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010079 descriptor_write.dstSet = descriptorSet;
10080 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010081 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010082 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10083 descriptor_write.pImageInfo = &descriptor_info;
10084
10085 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10086
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010087 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010088
Chia-I Wuf7458c52015-10-26 21:10:41 +080010089 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10090 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010091}
10092
Karl Schultz6addd812016-02-02 17:17:23 -070010093TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10094 // Create a single combined Image/Sampler descriptor and send it an invalid
10095 // imageView
10096 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010097
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010099
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010100 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010101 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010102 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10103 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010104
10105 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010106 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10107 ds_pool_ci.pNext = NULL;
10108 ds_pool_ci.maxSets = 1;
10109 ds_pool_ci.poolSizeCount = 1;
10110 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010111
10112 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010113 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010114 ASSERT_VK_SUCCESS(err);
10115
10116 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010117 dsl_binding.binding = 0;
10118 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10119 dsl_binding.descriptorCount = 1;
10120 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10121 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010122
10123 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010124 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10125 ds_layout_ci.pNext = NULL;
10126 ds_layout_ci.bindingCount = 1;
10127 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010128 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010129 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010130 ASSERT_VK_SUCCESS(err);
10131
10132 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010133 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010134 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010135 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010136 alloc_info.descriptorPool = ds_pool;
10137 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010138 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010139 ASSERT_VK_SUCCESS(err);
10140
10141 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010142 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10143 sampler_ci.pNext = NULL;
10144 sampler_ci.magFilter = VK_FILTER_NEAREST;
10145 sampler_ci.minFilter = VK_FILTER_NEAREST;
10146 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10147 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10148 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10149 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10150 sampler_ci.mipLodBias = 1.0;
10151 sampler_ci.anisotropyEnable = VK_FALSE;
10152 sampler_ci.maxAnisotropy = 1;
10153 sampler_ci.compareEnable = VK_FALSE;
10154 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10155 sampler_ci.minLod = 1.0;
10156 sampler_ci.maxLod = 1.0;
10157 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10158 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010159
10160 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010161 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010162 ASSERT_VK_SUCCESS(err);
10163
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010164 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010165
10166 VkDescriptorImageInfo descriptor_info;
10167 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10168 descriptor_info.sampler = sampler;
10169 descriptor_info.imageView = view;
10170
10171 VkWriteDescriptorSet descriptor_write;
10172 memset(&descriptor_write, 0, sizeof(descriptor_write));
10173 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010174 descriptor_write.dstSet = descriptorSet;
10175 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010176 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010177 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10178 descriptor_write.pImageInfo = &descriptor_info;
10179
10180 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10181
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010182 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010183
Chia-I Wuf7458c52015-10-26 21:10:41 +080010184 vkDestroySampler(m_device->device(), sampler, NULL);
10185 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10186 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010187}
10188
Karl Schultz6addd812016-02-02 17:17:23 -070010189TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10190 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10191 // into the other
10192 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010193
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10195 " binding #1 with type "
10196 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10197 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010198
Tobin Ehlis04356f92015-10-27 16:35:27 -060010199 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010200 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010201 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010202 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10203 ds_type_count[0].descriptorCount = 1;
10204 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10205 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010206
10207 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010208 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10209 ds_pool_ci.pNext = NULL;
10210 ds_pool_ci.maxSets = 1;
10211 ds_pool_ci.poolSizeCount = 2;
10212 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010213
10214 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010215 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010216 ASSERT_VK_SUCCESS(err);
10217 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010218 dsl_binding[0].binding = 0;
10219 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10220 dsl_binding[0].descriptorCount = 1;
10221 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10222 dsl_binding[0].pImmutableSamplers = NULL;
10223 dsl_binding[1].binding = 1;
10224 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10225 dsl_binding[1].descriptorCount = 1;
10226 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10227 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010228
10229 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010230 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10231 ds_layout_ci.pNext = NULL;
10232 ds_layout_ci.bindingCount = 2;
10233 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010234
10235 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010236 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010237 ASSERT_VK_SUCCESS(err);
10238
10239 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010240 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010241 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010242 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010243 alloc_info.descriptorPool = ds_pool;
10244 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010245 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010246 ASSERT_VK_SUCCESS(err);
10247
10248 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010249 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10250 sampler_ci.pNext = NULL;
10251 sampler_ci.magFilter = VK_FILTER_NEAREST;
10252 sampler_ci.minFilter = VK_FILTER_NEAREST;
10253 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10254 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10255 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10256 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10257 sampler_ci.mipLodBias = 1.0;
10258 sampler_ci.anisotropyEnable = VK_FALSE;
10259 sampler_ci.maxAnisotropy = 1;
10260 sampler_ci.compareEnable = VK_FALSE;
10261 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10262 sampler_ci.minLod = 1.0;
10263 sampler_ci.maxLod = 1.0;
10264 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10265 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010266
10267 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010268 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010269 ASSERT_VK_SUCCESS(err);
10270
10271 VkDescriptorImageInfo info = {};
10272 info.sampler = sampler;
10273
10274 VkWriteDescriptorSet descriptor_write;
10275 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10276 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010277 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010278 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010279 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010280 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10281 descriptor_write.pImageInfo = &info;
10282 // This write update should succeed
10283 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10284 // Now perform a copy update that fails due to type mismatch
10285 VkCopyDescriptorSet copy_ds_update;
10286 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10287 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10288 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010289 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010290 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010291 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10292 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010293 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10294
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010295 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010296 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010297 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 -060010298 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10299 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10300 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010301 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010302 copy_ds_update.dstSet = descriptorSet;
10303 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010304 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010305 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10306
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010307 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010308
Tobin Ehlis04356f92015-10-27 16:35:27 -060010309 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10311 " binding#1 with offset index of 1 plus "
10312 "update array offset of 0 and update of "
10313 "5 descriptors oversteps total number "
10314 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010315
Tobin Ehlis04356f92015-10-27 16:35:27 -060010316 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10317 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10318 copy_ds_update.srcSet = descriptorSet;
10319 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010320 copy_ds_update.dstSet = descriptorSet;
10321 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010322 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010323 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10324
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010325 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010326
Chia-I Wuf7458c52015-10-26 21:10:41 +080010327 vkDestroySampler(m_device->device(), sampler, NULL);
10328 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10329 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010330}
10331
Karl Schultz6addd812016-02-02 17:17:23 -070010332TEST_F(VkLayerTest, NumSamplesMismatch) {
10333 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10334 // sampleCount
10335 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010337 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010338
Tobin Ehlis3b780662015-05-28 12:11:26 -060010339 ASSERT_NO_FATAL_FAILURE(InitState());
10340 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010341 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010342 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010343 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010344
10345 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010346 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10347 ds_pool_ci.pNext = NULL;
10348 ds_pool_ci.maxSets = 1;
10349 ds_pool_ci.poolSizeCount = 1;
10350 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010351
Tobin Ehlis3b780662015-05-28 12:11:26 -060010352 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010353 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010354 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010355
Tony Barboureb254902015-07-15 12:50:33 -060010356 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010357 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010358 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010359 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010360 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10361 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010362
Tony Barboureb254902015-07-15 12:50:33 -060010363 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10364 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10365 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010366 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010367 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010368
Tobin Ehlis3b780662015-05-28 12:11:26 -060010369 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010370 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010371 ASSERT_VK_SUCCESS(err);
10372
10373 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010374 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010375 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010376 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010377 alloc_info.descriptorPool = ds_pool;
10378 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010379 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010380 ASSERT_VK_SUCCESS(err);
10381
Tony Barboureb254902015-07-15 12:50:33 -060010382 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010383 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010384 pipe_ms_state_ci.pNext = NULL;
10385 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10386 pipe_ms_state_ci.sampleShadingEnable = 0;
10387 pipe_ms_state_ci.minSampleShading = 1.0;
10388 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010389
Tony Barboureb254902015-07-15 12:50:33 -060010390 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010391 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10392 pipeline_layout_ci.pNext = NULL;
10393 pipeline_layout_ci.setLayoutCount = 1;
10394 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010395
10396 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010397 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010398 ASSERT_VK_SUCCESS(err);
10399
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010400 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010401 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 -060010402 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010403 VkPipelineObj pipe(m_device);
10404 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010405 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010406 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010407 pipe.SetMSAA(&pipe_ms_state_ci);
10408 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010409
Tony Barbour552f6c02016-12-21 14:34:07 -070010410 m_commandBuffer->BeginCommandBuffer();
10411 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010412 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010413
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010414 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10415 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10416 VkRect2D scissor = {{0, 0}, {16, 16}};
10417 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10418
Mark Young29927482016-05-04 14:38:51 -060010419 // Render triangle (the error should trigger on the attempt to draw).
10420 Draw(3, 1, 0, 0);
10421
10422 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010423 m_commandBuffer->EndRenderPass();
10424 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010425
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010426 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010427
Chia-I Wuf7458c52015-10-26 21:10:41 +080010428 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10429 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10430 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010431}
Mark Young29927482016-05-04 14:38:51 -060010432
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010433TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010434 TEST_DESCRIPTION(
10435 "Hit RenderPass incompatible cases. "
10436 "Initial case is drawing with an active renderpass that's "
10437 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010438 VkResult err;
10439
10440 ASSERT_NO_FATAL_FAILURE(InitState());
10441 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10442
10443 VkDescriptorSetLayoutBinding dsl_binding = {};
10444 dsl_binding.binding = 0;
10445 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10446 dsl_binding.descriptorCount = 1;
10447 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10448 dsl_binding.pImmutableSamplers = NULL;
10449
10450 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10451 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10452 ds_layout_ci.pNext = NULL;
10453 ds_layout_ci.bindingCount = 1;
10454 ds_layout_ci.pBindings = &dsl_binding;
10455
10456 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010458 ASSERT_VK_SUCCESS(err);
10459
10460 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10461 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10462 pipeline_layout_ci.pNext = NULL;
10463 pipeline_layout_ci.setLayoutCount = 1;
10464 pipeline_layout_ci.pSetLayouts = &ds_layout;
10465
10466 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010467 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010468 ASSERT_VK_SUCCESS(err);
10469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010470 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010471 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 -060010472 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010473 // Create a renderpass that will be incompatible with default renderpass
10474 VkAttachmentReference attach = {};
10475 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10476 VkAttachmentReference color_att = {};
10477 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10478 VkSubpassDescription subpass = {};
10479 subpass.inputAttachmentCount = 1;
10480 subpass.pInputAttachments = &attach;
10481 subpass.colorAttachmentCount = 1;
10482 subpass.pColorAttachments = &color_att;
10483 VkRenderPassCreateInfo rpci = {};
10484 rpci.subpassCount = 1;
10485 rpci.pSubpasses = &subpass;
10486 rpci.attachmentCount = 1;
10487 VkAttachmentDescription attach_desc = {};
10488 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010489 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10490 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010491 rpci.pAttachments = &attach_desc;
10492 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10493 VkRenderPass rp;
10494 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10495 VkPipelineObj pipe(m_device);
10496 pipe.AddShader(&vs);
10497 pipe.AddShader(&fs);
10498 pipe.AddColorAttachment();
10499 VkViewport view_port = {};
10500 m_viewports.push_back(view_port);
10501 pipe.SetViewport(m_viewports);
10502 VkRect2D rect = {};
10503 m_scissors.push_back(rect);
10504 pipe.SetScissor(m_scissors);
10505 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10506
10507 VkCommandBufferInheritanceInfo cbii = {};
10508 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10509 cbii.renderPass = rp;
10510 cbii.subpass = 0;
10511 VkCommandBufferBeginInfo cbbi = {};
10512 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10513 cbbi.pInheritanceInfo = &cbii;
10514 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10515 VkRenderPassBeginInfo rpbi = {};
10516 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10517 rpbi.framebuffer = m_framebuffer;
10518 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010519 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10520 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010521
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010522 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010523 // Render triangle (the error should trigger on the attempt to draw).
10524 Draw(3, 1, 0, 0);
10525
10526 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010527 m_commandBuffer->EndRenderPass();
10528 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010529
10530 m_errorMonitor->VerifyFound();
10531
10532 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10533 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10534 vkDestroyRenderPass(m_device->device(), rp, NULL);
10535}
10536
Mark Youngc89c6312016-03-31 16:03:20 -060010537TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10538 // Create Pipeline where the number of blend attachments doesn't match the
10539 // number of color attachments. In this case, we don't add any color
10540 // blend attachments even though we have a color attachment.
10541 VkResult err;
10542
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010544
10545 ASSERT_NO_FATAL_FAILURE(InitState());
10546 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10547 VkDescriptorPoolSize ds_type_count = {};
10548 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10549 ds_type_count.descriptorCount = 1;
10550
10551 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10552 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10553 ds_pool_ci.pNext = NULL;
10554 ds_pool_ci.maxSets = 1;
10555 ds_pool_ci.poolSizeCount = 1;
10556 ds_pool_ci.pPoolSizes = &ds_type_count;
10557
10558 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010559 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010560 ASSERT_VK_SUCCESS(err);
10561
10562 VkDescriptorSetLayoutBinding dsl_binding = {};
10563 dsl_binding.binding = 0;
10564 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10565 dsl_binding.descriptorCount = 1;
10566 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10567 dsl_binding.pImmutableSamplers = NULL;
10568
10569 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10570 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10571 ds_layout_ci.pNext = NULL;
10572 ds_layout_ci.bindingCount = 1;
10573 ds_layout_ci.pBindings = &dsl_binding;
10574
10575 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010576 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010577 ASSERT_VK_SUCCESS(err);
10578
10579 VkDescriptorSet descriptorSet;
10580 VkDescriptorSetAllocateInfo alloc_info = {};
10581 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10582 alloc_info.descriptorSetCount = 1;
10583 alloc_info.descriptorPool = ds_pool;
10584 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010585 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010586 ASSERT_VK_SUCCESS(err);
10587
10588 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010589 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010590 pipe_ms_state_ci.pNext = NULL;
10591 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10592 pipe_ms_state_ci.sampleShadingEnable = 0;
10593 pipe_ms_state_ci.minSampleShading = 1.0;
10594 pipe_ms_state_ci.pSampleMask = NULL;
10595
10596 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10597 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10598 pipeline_layout_ci.pNext = NULL;
10599 pipeline_layout_ci.setLayoutCount = 1;
10600 pipeline_layout_ci.pSetLayouts = &ds_layout;
10601
10602 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010604 ASSERT_VK_SUCCESS(err);
10605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010606 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010607 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 -060010608 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060010609 VkPipelineObj pipe(m_device);
10610 pipe.AddShader(&vs);
10611 pipe.AddShader(&fs);
10612 pipe.SetMSAA(&pipe_ms_state_ci);
10613 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010614 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060010615
10616 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10617 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10618 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10619}
Mark Young29927482016-05-04 14:38:51 -060010620
Mark Muellerd4914412016-06-13 17:52:06 -060010621TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010622 TEST_DESCRIPTION(
10623 "Points to a wrong colorAttachment index in a VkClearAttachment "
10624 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060010625 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060010627
10628 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
10629 m_errorMonitor->VerifyFound();
10630}
10631
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010632TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010633 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
10634 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010635
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010636 ASSERT_NO_FATAL_FAILURE(InitState());
10637 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010638
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010639 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010640 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10641 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010642
10643 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010644 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10645 ds_pool_ci.pNext = NULL;
10646 ds_pool_ci.maxSets = 1;
10647 ds_pool_ci.poolSizeCount = 1;
10648 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010649
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010650 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010651 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010652 ASSERT_VK_SUCCESS(err);
10653
Tony Barboureb254902015-07-15 12:50:33 -060010654 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010655 dsl_binding.binding = 0;
10656 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10657 dsl_binding.descriptorCount = 1;
10658 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10659 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010660
Tony Barboureb254902015-07-15 12:50:33 -060010661 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010662 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10663 ds_layout_ci.pNext = NULL;
10664 ds_layout_ci.bindingCount = 1;
10665 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010666
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010667 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010668 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010669 ASSERT_VK_SUCCESS(err);
10670
10671 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010672 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010673 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010674 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010675 alloc_info.descriptorPool = ds_pool;
10676 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010677 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010678 ASSERT_VK_SUCCESS(err);
10679
Tony Barboureb254902015-07-15 12:50:33 -060010680 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010681 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010682 pipe_ms_state_ci.pNext = NULL;
10683 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10684 pipe_ms_state_ci.sampleShadingEnable = 0;
10685 pipe_ms_state_ci.minSampleShading = 1.0;
10686 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010687
Tony Barboureb254902015-07-15 12:50:33 -060010688 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010689 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10690 pipeline_layout_ci.pNext = NULL;
10691 pipeline_layout_ci.setLayoutCount = 1;
10692 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010693
10694 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010695 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010696 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010697
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010698 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060010699 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070010700 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010701 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010702
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010703 VkPipelineObj pipe(m_device);
10704 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010705 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010706 pipe.SetMSAA(&pipe_ms_state_ci);
10707 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010708
Tony Barbour552f6c02016-12-21 14:34:07 -070010709 m_commandBuffer->BeginCommandBuffer();
10710 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010711
Karl Schultz6addd812016-02-02 17:17:23 -070010712 // Main thing we care about for this test is that the VkImage obj we're
10713 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010714 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060010715 VkClearAttachment color_attachment;
10716 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10717 color_attachment.clearValue.color.float32[0] = 1.0;
10718 color_attachment.clearValue.color.float32[1] = 1.0;
10719 color_attachment.clearValue.color.float32[2] = 1.0;
10720 color_attachment.clearValue.color.float32[3] = 1.0;
10721 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010722 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010723
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010724 // Call for full-sized FB Color attachment prior to issuing a Draw
10725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070010726 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010727 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010728 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010729
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070010730 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
10731 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
10732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
10733 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
10734 m_errorMonitor->VerifyFound();
10735
10736 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
10737 clear_rect.layerCount = 2;
10738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
10739 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010740 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010741
Chia-I Wuf7458c52015-10-26 21:10:41 +080010742 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10743 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10744 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060010745}
10746
Karl Schultz6addd812016-02-02 17:17:23 -070010747TEST_F(VkLayerTest, VtxBufferBadIndex) {
10748 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010749
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
10751 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010752
Tobin Ehlis502480b2015-06-24 15:53:07 -060010753 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060010754 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060010755 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060010756
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010757 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010758 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10759 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010760
10761 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010762 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10763 ds_pool_ci.pNext = NULL;
10764 ds_pool_ci.maxSets = 1;
10765 ds_pool_ci.poolSizeCount = 1;
10766 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010767
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010768 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010769 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010770 ASSERT_VK_SUCCESS(err);
10771
Tony Barboureb254902015-07-15 12:50:33 -060010772 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010773 dsl_binding.binding = 0;
10774 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10775 dsl_binding.descriptorCount = 1;
10776 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10777 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010778
Tony Barboureb254902015-07-15 12:50:33 -060010779 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010780 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10781 ds_layout_ci.pNext = NULL;
10782 ds_layout_ci.bindingCount = 1;
10783 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010784
Tobin Ehlis502480b2015-06-24 15:53:07 -060010785 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010786 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010787 ASSERT_VK_SUCCESS(err);
10788
10789 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010790 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010791 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010792 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010793 alloc_info.descriptorPool = ds_pool;
10794 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010795 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010796 ASSERT_VK_SUCCESS(err);
10797
Tony Barboureb254902015-07-15 12:50:33 -060010798 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010799 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010800 pipe_ms_state_ci.pNext = NULL;
10801 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
10802 pipe_ms_state_ci.sampleShadingEnable = 0;
10803 pipe_ms_state_ci.minSampleShading = 1.0;
10804 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010805
Tony Barboureb254902015-07-15 12:50:33 -060010806 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010807 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10808 pipeline_layout_ci.pNext = NULL;
10809 pipeline_layout_ci.setLayoutCount = 1;
10810 pipeline_layout_ci.pSetLayouts = &ds_layout;
10811 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060010812
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010813 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010814 ASSERT_VK_SUCCESS(err);
10815
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010816 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010817 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 -060010818 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010819 VkPipelineObj pipe(m_device);
10820 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010821 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010822 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010823 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060010824 pipe.SetViewport(m_viewports);
10825 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010826 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060010827
Tony Barbour552f6c02016-12-21 14:34:07 -070010828 m_commandBuffer->BeginCommandBuffer();
10829 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010830 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060010831 // Don't care about actual data, just need to get to draw to flag error
10832 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010834 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060010835 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010836
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010837 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010838
Chia-I Wuf7458c52015-10-26 21:10:41 +080010839 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060010842}
Mark Muellerdfe37552016-07-07 14:47:42 -060010843
Mark Mueller2ee294f2016-08-04 12:59:48 -060010844TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010845 TEST_DESCRIPTION(
10846 "Use an invalid count in a vkEnumeratePhysicalDevices call."
10847 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060010848 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060010849
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010850 const char *invalid_queueFamilyIndex_message =
10851 "Invalid queue create request in vkCreateDevice(). Invalid "
10852 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010853
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010854 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010855
Mark Mueller880fce52016-08-17 15:23:23 -060010856 // The following test fails with recent NVidia drivers.
10857 // By the time core_validation is reached, the NVidia
10858 // driver has sanitized the invalid condition and core_validation
10859 // is not introduced to the failure condition. This is not the case
10860 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010861 // uint32_t count = static_cast<uint32_t>(~0);
10862 // VkPhysicalDevice physical_device;
10863 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
10864 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010865
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010867 float queue_priority = 0.0;
10868
10869 VkDeviceQueueCreateInfo queue_create_info = {};
10870 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10871 queue_create_info.queueCount = 1;
10872 queue_create_info.pQueuePriorities = &queue_priority;
10873 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
10874
10875 VkPhysicalDeviceFeatures features = m_device->phy().features();
10876 VkDevice testDevice;
10877 VkDeviceCreateInfo device_create_info = {};
10878 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10879 device_create_info.queueCreateInfoCount = 1;
10880 device_create_info.pQueueCreateInfos = &queue_create_info;
10881 device_create_info.pEnabledFeatures = &features;
10882 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10883 m_errorMonitor->VerifyFound();
10884
10885 queue_create_info.queueFamilyIndex = 1;
10886
10887 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
10888 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
10889 for (unsigned i = 0; i < feature_count; i++) {
10890 if (VK_FALSE == feature_array[i]) {
10891 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010893 device_create_info.pEnabledFeatures = &features;
10894 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
10895 m_errorMonitor->VerifyFound();
10896 break;
10897 }
10898 }
10899}
10900
Tobin Ehlis16edf082016-11-21 12:33:49 -070010901TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
10902 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
10903
10904 ASSERT_NO_FATAL_FAILURE(InitState());
10905
10906 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
10907 std::vector<VkDeviceQueueCreateInfo> queue_info;
10908 queue_info.reserve(queue_props.size());
10909 std::vector<std::vector<float>> queue_priorities;
10910 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
10911 VkDeviceQueueCreateInfo qi{};
10912 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
10913 qi.queueFamilyIndex = i;
10914 qi.queueCount = queue_props[i].queueCount;
10915 queue_priorities.emplace_back(qi.queueCount, 0.0f);
10916 qi.pQueuePriorities = queue_priorities[i].data();
10917 queue_info.push_back(qi);
10918 }
10919
10920 std::vector<const char *> device_extension_names;
10921
10922 VkDevice local_device;
10923 VkDeviceCreateInfo device_create_info = {};
10924 auto features = m_device->phy().features();
10925 // Intentionally disable pipeline stats
10926 features.pipelineStatisticsQuery = VK_FALSE;
10927 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
10928 device_create_info.pNext = NULL;
10929 device_create_info.queueCreateInfoCount = queue_info.size();
10930 device_create_info.pQueueCreateInfos = queue_info.data();
10931 device_create_info.enabledLayerCount = 0;
10932 device_create_info.ppEnabledLayerNames = NULL;
10933 device_create_info.pEnabledFeatures = &features;
10934 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
10935 ASSERT_VK_SUCCESS(err);
10936
10937 VkQueryPoolCreateInfo qpci{};
10938 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
10939 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
10940 qpci.queryCount = 1;
10941 VkQueryPool query_pool;
10942
10943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
10944 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
10945 m_errorMonitor->VerifyFound();
10946
10947 vkDestroyDevice(local_device, nullptr);
10948}
10949
Mark Mueller2ee294f2016-08-04 12:59:48 -060010950TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010951 TEST_DESCRIPTION(
10952 "Use an invalid queue index in a vkCmdWaitEvents call."
10953 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060010954
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010955 const char *invalid_queue_index =
10956 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
10957 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
10958 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010959
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010960 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060010961
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010962 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010963
10964 ASSERT_NO_FATAL_FAILURE(InitState());
10965
10966 VkEvent event;
10967 VkEventCreateInfo event_create_info{};
10968 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
10969 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
10970
Mark Mueller2ee294f2016-08-04 12:59:48 -060010971 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010972 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010973
Tony Barbour552f6c02016-12-21 14:34:07 -070010974 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060010975
10976 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010977 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 -060010978 ASSERT_TRUE(image.initialized());
10979 VkImageMemoryBarrier img_barrier = {};
10980 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
10981 img_barrier.pNext = NULL;
10982 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
10983 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
10984 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10985 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10986 img_barrier.image = image.handle();
10987 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060010988
10989 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
10990 // that layer validation catches the case when it is not.
10991 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060010992 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
10993 img_barrier.subresourceRange.baseArrayLayer = 0;
10994 img_barrier.subresourceRange.baseMipLevel = 0;
10995 img_barrier.subresourceRange.layerCount = 1;
10996 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010997 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
10998 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060010999 m_errorMonitor->VerifyFound();
11000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011002
11003 VkQueryPool query_pool;
11004 VkQueryPoolCreateInfo query_pool_create_info = {};
11005 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11006 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11007 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011008 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011010 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011011 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11012
11013 vkEndCommandBuffer(m_commandBuffer->handle());
11014 m_errorMonitor->VerifyFound();
11015
11016 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11017 vkDestroyEvent(m_device->device(), event, nullptr);
11018}
11019
Mark Muellerdfe37552016-07-07 14:47:42 -060011020TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011021 TEST_DESCRIPTION(
11022 "Submit a command buffer using deleted vertex buffer, "
11023 "delete a buffer twice, use an invalid offset for each "
11024 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011025
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011026 const char *deleted_buffer_in_command_buffer =
11027 "Cannot submit cmd buffer "
11028 "using deleted buffer ";
11029 const char *invalid_offset_message =
11030 "vkBindBufferMemory(): "
11031 "memoryOffset is 0x";
11032 const char *invalid_storage_buffer_offset_message =
11033 "vkBindBufferMemory(): "
11034 "storage memoryOffset "
11035 "is 0x";
11036 const char *invalid_texel_buffer_offset_message =
11037 "vkBindBufferMemory(): "
11038 "texel memoryOffset "
11039 "is 0x";
11040 const char *invalid_uniform_buffer_offset_message =
11041 "vkBindBufferMemory(): "
11042 "uniform memoryOffset "
11043 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011044
11045 ASSERT_NO_FATAL_FAILURE(InitState());
11046 ASSERT_NO_FATAL_FAILURE(InitViewport());
11047 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11048
11049 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011050 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011051 pipe_ms_state_ci.pNext = NULL;
11052 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11053 pipe_ms_state_ci.sampleShadingEnable = 0;
11054 pipe_ms_state_ci.minSampleShading = 1.0;
11055 pipe_ms_state_ci.pSampleMask = nullptr;
11056
11057 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11058 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11059 VkPipelineLayout pipeline_layout;
11060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011061 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011062 ASSERT_VK_SUCCESS(err);
11063
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011064 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11065 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011066 VkPipelineObj pipe(m_device);
11067 pipe.AddShader(&vs);
11068 pipe.AddShader(&fs);
11069 pipe.AddColorAttachment();
11070 pipe.SetMSAA(&pipe_ms_state_ci);
11071 pipe.SetViewport(m_viewports);
11072 pipe.SetScissor(m_scissors);
11073 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11074
Tony Barbour552f6c02016-12-21 14:34:07 -070011075 m_commandBuffer->BeginCommandBuffer();
11076 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011077 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011078
11079 {
11080 // Create and bind a vertex buffer in a reduced scope, which will cause
11081 // it to be deleted upon leaving this scope
11082 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011083 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011084 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11085 draw_verticies.AddVertexInputToPipe(pipe);
11086 }
11087
11088 Draw(1, 0, 0, 0);
11089
Tony Barbour552f6c02016-12-21 14:34:07 -070011090 m_commandBuffer->EndRenderPass();
11091 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011093 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011094 QueueCommandBuffer(false);
11095 m_errorMonitor->VerifyFound();
11096
11097 {
11098 // Create and bind a vertex buffer in a reduced scope, and delete it
11099 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011100 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011102 buffer_test.TestDoubleDestroy();
11103 }
11104 m_errorMonitor->VerifyFound();
11105
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011106 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011107 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011108 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
11109 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11110 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011111 m_errorMonitor->VerifyFound();
11112 }
11113
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011114 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11115 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011116 // Create and bind a memory buffer with an invalid offset again,
11117 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
11119 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11120 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011121 m_errorMonitor->VerifyFound();
11122 }
11123
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011124 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011125 // Create and bind a memory buffer with an invalid offset again, but
11126 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011127 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
11128 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11129 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011130 m_errorMonitor->VerifyFound();
11131 }
11132
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011133 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011134 // Create and bind a memory buffer with an invalid offset again, but
11135 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011136 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
11137 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11138 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011139 m_errorMonitor->VerifyFound();
11140 }
11141
11142 {
11143 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011145 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11146 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011147 m_errorMonitor->VerifyFound();
11148 }
11149
11150 {
11151 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011153 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11154 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011155 }
11156 m_errorMonitor->VerifyFound();
11157
11158 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11159}
11160
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011161// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11162TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011163 TEST_DESCRIPTION(
11164 "Hit all possible validation checks associated with the "
11165 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11166 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011167 // 3 in ValidateCmdBufImageLayouts
11168 // * -1 Attempt to submit cmd buf w/ deleted image
11169 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11170 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011171
11172 ASSERT_NO_FATAL_FAILURE(InitState());
11173 // Create src & dst images to use for copy operations
11174 VkImage src_image;
11175 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011176 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011177
11178 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11179 const int32_t tex_width = 32;
11180 const int32_t tex_height = 32;
11181
11182 VkImageCreateInfo image_create_info = {};
11183 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11184 image_create_info.pNext = NULL;
11185 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11186 image_create_info.format = tex_format;
11187 image_create_info.extent.width = tex_width;
11188 image_create_info.extent.height = tex_height;
11189 image_create_info.extent.depth = 1;
11190 image_create_info.mipLevels = 1;
11191 image_create_info.arrayLayers = 4;
11192 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11193 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11194 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011195 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011196 image_create_info.flags = 0;
11197
11198 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11199 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011200 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011201 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11202 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011203 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11204 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11205 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11206 ASSERT_VK_SUCCESS(err);
11207
11208 // Allocate memory
11209 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011210 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011211 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011212 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11213 mem_alloc.pNext = NULL;
11214 mem_alloc.allocationSize = 0;
11215 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011216
11217 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011218 mem_alloc.allocationSize = img_mem_reqs.size;
11219 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011220 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011221 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011222 ASSERT_VK_SUCCESS(err);
11223
11224 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011225 mem_alloc.allocationSize = img_mem_reqs.size;
11226 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011227 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011228 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011229 ASSERT_VK_SUCCESS(err);
11230
11231 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011232 mem_alloc.allocationSize = img_mem_reqs.size;
11233 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011234 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011235 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011236 ASSERT_VK_SUCCESS(err);
11237
11238 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11239 ASSERT_VK_SUCCESS(err);
11240 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11241 ASSERT_VK_SUCCESS(err);
11242 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11243 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011244
Tony Barbour552f6c02016-12-21 14:34:07 -070011245 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011246 VkImageCopy copy_region;
11247 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11248 copy_region.srcSubresource.mipLevel = 0;
11249 copy_region.srcSubresource.baseArrayLayer = 0;
11250 copy_region.srcSubresource.layerCount = 1;
11251 copy_region.srcOffset.x = 0;
11252 copy_region.srcOffset.y = 0;
11253 copy_region.srcOffset.z = 0;
11254 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11255 copy_region.dstSubresource.mipLevel = 0;
11256 copy_region.dstSubresource.baseArrayLayer = 0;
11257 copy_region.dstSubresource.layerCount = 1;
11258 copy_region.dstOffset.x = 0;
11259 copy_region.dstOffset.y = 0;
11260 copy_region.dstOffset.z = 0;
11261 copy_region.extent.width = 1;
11262 copy_region.extent.height = 1;
11263 copy_region.extent.depth = 1;
11264
11265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11266 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
11267 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 -060011268 m_errorMonitor->VerifyFound();
11269 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11271 "Cannot copy from an image whose source layout is "
11272 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11273 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011274 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 -060011275 m_errorMonitor->VerifyFound();
11276 // Final src error is due to bad layout type
11277 m_errorMonitor->SetDesiredFailureMsg(
11278 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11279 "Layout for input image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_SRC_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011280 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 -060011281 m_errorMonitor->VerifyFound();
11282 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11284 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011285 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 -060011286 m_errorMonitor->VerifyFound();
11287 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11289 "Cannot copy from an image whose dest layout is "
11290 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11291 "layout VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011292 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 -060011293 m_errorMonitor->VerifyFound();
11294 m_errorMonitor->SetDesiredFailureMsg(
11295 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11296 "Layout for output image is VK_IMAGE_LAYOUT_UNDEFINED but can only be TRANSFER_DST_OPTIMAL or GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011297 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 -060011298 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011299
Cort3b021012016-12-07 12:00:57 -080011300 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11301 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11302 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11303 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11304 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11305 transfer_dst_image_barrier[0].srcAccessMask = 0;
11306 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11307 transfer_dst_image_barrier[0].image = dst_image;
11308 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11309 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11310 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11311 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11312 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11313 transfer_dst_image_barrier[0].image = depth_image;
11314 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11315 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11316 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11317
11318 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011319 VkClearColorValue color_clear_value = {};
11320 VkImageSubresourceRange clear_range;
11321 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11322 clear_range.baseMipLevel = 0;
11323 clear_range.baseArrayLayer = 0;
11324 clear_range.layerCount = 1;
11325 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011326
Cort3b021012016-12-07 12:00:57 -080011327 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11328 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011331 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011332 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011333 // Fail due to provided layout not matching actual current layout for color clear.
11334 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011335 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011336 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011337
Cort530cf382016-12-08 09:59:47 -080011338 VkClearDepthStencilValue depth_clear_value = {};
11339 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011340
11341 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11342 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011345 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011346 m_errorMonitor->VerifyFound();
11347 // Fail due to provided layout not matching actual current layout for depth clear.
11348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011349 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011350 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011351
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011352 // Now cause error due to bad image layout transition in PipelineBarrier
11353 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011354 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011355 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011356 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011357 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011358 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11359 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011360 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11362 "You cannot transition the layout of aspect 1 from "
11363 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11364 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011365 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11366 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011367 m_errorMonitor->VerifyFound();
11368
11369 // Finally some layout errors at RenderPass create time
11370 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11371 VkAttachmentReference attach = {};
11372 // perf warning for GENERAL layout w/ non-DS input attachment
11373 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11374 VkSubpassDescription subpass = {};
11375 subpass.inputAttachmentCount = 1;
11376 subpass.pInputAttachments = &attach;
11377 VkRenderPassCreateInfo rpci = {};
11378 rpci.subpassCount = 1;
11379 rpci.pSubpasses = &subpass;
11380 rpci.attachmentCount = 1;
11381 VkAttachmentDescription attach_desc = {};
11382 attach_desc.format = VK_FORMAT_UNDEFINED;
11383 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011384 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011385 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11387 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011388 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11389 m_errorMonitor->VerifyFound();
11390 // error w/ non-general layout
11391 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11392
11393 m_errorMonitor->SetDesiredFailureMsg(
11394 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11395 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11396 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11397 m_errorMonitor->VerifyFound();
11398 subpass.inputAttachmentCount = 0;
11399 subpass.colorAttachmentCount = 1;
11400 subpass.pColorAttachments = &attach;
11401 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11402 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11404 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011405 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11406 m_errorMonitor->VerifyFound();
11407 // error w/ non-color opt or GENERAL layout for color attachment
11408 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11409 m_errorMonitor->SetDesiredFailureMsg(
11410 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11411 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11412 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11413 m_errorMonitor->VerifyFound();
11414 subpass.colorAttachmentCount = 0;
11415 subpass.pDepthStencilAttachment = &attach;
11416 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11417 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11419 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011420 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11421 m_errorMonitor->VerifyFound();
11422 // error w/ non-ds opt or GENERAL layout for color attachment
11423 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11425 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11426 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011427 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11428 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011429 // For this error we need a valid renderpass so create default one
11430 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11431 attach.attachment = 0;
11432 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11433 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11434 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11435 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11436 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11437 // Can't do a CLEAR load on READ_ONLY initialLayout
11438 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11439 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11440 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011441 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11442 " with invalid first layout "
11443 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11444 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011445 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11446 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011447
Cort3b021012016-12-07 12:00:57 -080011448 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11449 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11450 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011451 vkDestroyImage(m_device->device(), src_image, NULL);
11452 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011453 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011454}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011455
Tobin Ehlise0936662016-10-11 08:10:51 -060011456TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11457 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11458 VkResult err;
11459
11460 ASSERT_NO_FATAL_FAILURE(InitState());
11461
11462 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11463 VkImageTiling tiling;
11464 VkFormatProperties format_properties;
11465 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11466 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11467 tiling = VK_IMAGE_TILING_LINEAR;
11468 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11469 tiling = VK_IMAGE_TILING_OPTIMAL;
11470 } else {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011471 printf(
11472 "Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; "
11473 "skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011474 return;
11475 }
11476
11477 VkDescriptorPoolSize ds_type = {};
11478 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11479 ds_type.descriptorCount = 1;
11480
11481 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11482 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11483 ds_pool_ci.maxSets = 1;
11484 ds_pool_ci.poolSizeCount = 1;
11485 ds_pool_ci.pPoolSizes = &ds_type;
11486 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11487
11488 VkDescriptorPool ds_pool;
11489 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11490 ASSERT_VK_SUCCESS(err);
11491
11492 VkDescriptorSetLayoutBinding dsl_binding = {};
11493 dsl_binding.binding = 0;
11494 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11495 dsl_binding.descriptorCount = 1;
11496 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11497 dsl_binding.pImmutableSamplers = NULL;
11498
11499 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11500 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11501 ds_layout_ci.pNext = NULL;
11502 ds_layout_ci.bindingCount = 1;
11503 ds_layout_ci.pBindings = &dsl_binding;
11504
11505 VkDescriptorSetLayout ds_layout;
11506 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11507 ASSERT_VK_SUCCESS(err);
11508
11509 VkDescriptorSetAllocateInfo alloc_info = {};
11510 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11511 alloc_info.descriptorSetCount = 1;
11512 alloc_info.descriptorPool = ds_pool;
11513 alloc_info.pSetLayouts = &ds_layout;
11514 VkDescriptorSet descriptor_set;
11515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11516 ASSERT_VK_SUCCESS(err);
11517
11518 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11519 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11520 pipeline_layout_ci.pNext = NULL;
11521 pipeline_layout_ci.setLayoutCount = 1;
11522 pipeline_layout_ci.pSetLayouts = &ds_layout;
11523 VkPipelineLayout pipeline_layout;
11524 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11525 ASSERT_VK_SUCCESS(err);
11526
11527 VkImageObj image(m_device);
11528 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11529 ASSERT_TRUE(image.initialized());
11530 VkImageView view = image.targetView(tex_format);
11531
11532 VkDescriptorImageInfo image_info = {};
11533 image_info.imageView = view;
11534 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11535
11536 VkWriteDescriptorSet descriptor_write = {};
11537 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11538 descriptor_write.dstSet = descriptor_set;
11539 descriptor_write.dstBinding = 0;
11540 descriptor_write.descriptorCount = 1;
11541 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11542 descriptor_write.pImageInfo = &image_info;
11543
11544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11545 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11546 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11547 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11548 m_errorMonitor->VerifyFound();
11549
11550 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11551 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11552 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11553 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11554}
11555
Mark Mueller93b938f2016-08-18 10:27:40 -060011556TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011557 TEST_DESCRIPTION(
11558 "Use vkCmdExecuteCommands with invalid state "
11559 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060011560
11561 ASSERT_NO_FATAL_FAILURE(InitState());
11562 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11563
Mike Weiblen95dd0f92016-10-19 12:28:27 -060011564 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011565 const char *simultaneous_use_message2 =
11566 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
11567 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060011568
11569 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011570 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011571 command_buffer_allocate_info.commandPool = m_commandPool;
11572 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
11573 command_buffer_allocate_info.commandBufferCount = 1;
11574
11575 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011576 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060011577 VkCommandBufferBeginInfo command_buffer_begin_info = {};
11578 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011579 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060011580 command_buffer_inheritance_info.renderPass = m_renderPass;
11581 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011582
Mark Mueller93b938f2016-08-18 10:27:40 -060011583 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011584 command_buffer_begin_info.flags =
11585 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011586 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
11587
11588 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
11589 vkEndCommandBuffer(secondary_command_buffer);
11590
Mark Mueller93b938f2016-08-18 10:27:40 -060011591 VkSubmitInfo submit_info = {};
11592 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11593 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011594 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060011595
Mark Mueller4042b652016-09-05 22:52:21 -060011596 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011597 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
11598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
11599 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011600 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011601 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011602 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11603 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060011604
Dave Houltonfbf52152017-01-06 12:55:29 -070011605 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060011606 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070011607 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060011608
Mark Mueller4042b652016-09-05 22:52:21 -060011609 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060011610 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011611 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060011612
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
11614 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060011615 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060011616 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
11617 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070011618
11619 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller93b938f2016-08-18 10:27:40 -060011620}
11621
Tobin Ehlisb093da82017-01-19 12:05:27 -070011622TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011623 TEST_DESCRIPTION(
11624 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
11625 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070011626
11627 ASSERT_NO_FATAL_FAILURE(InitState());
11628 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11629
11630 std::vector<const char *> device_extension_names;
11631 auto features = m_device->phy().features();
11632 // Make sure gs & ts are disabled
11633 features.geometryShader = false;
11634 features.tessellationShader = false;
11635 // The sacrificial device object
11636 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
11637
11638 VkCommandPoolCreateInfo pool_create_info{};
11639 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
11640 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
11641
11642 VkCommandPool command_pool;
11643 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
11644
11645 VkCommandBufferAllocateInfo cmd = {};
11646 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
11647 cmd.pNext = NULL;
11648 cmd.commandPool = command_pool;
11649 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
11650 cmd.commandBufferCount = 1;
11651
11652 VkCommandBuffer cmd_buffer;
11653 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
11654 ASSERT_VK_SUCCESS(err);
11655
11656 VkEvent event;
11657 VkEventCreateInfo evci = {};
11658 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11659 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
11660 ASSERT_VK_SUCCESS(result);
11661
11662 VkCommandBufferBeginInfo cbbi = {};
11663 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11664 vkBeginCommandBuffer(cmd_buffer, &cbbi);
11665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
11666 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
11667 m_errorMonitor->VerifyFound();
11668
11669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
11670 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
11671 m_errorMonitor->VerifyFound();
11672
11673 vkDestroyEvent(test_device.handle(), event, NULL);
11674 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
11675}
11676
Mark Mueller917f6bc2016-08-30 10:57:19 -060011677TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011678 TEST_DESCRIPTION(
11679 "Use vkCmdExecuteCommands with invalid state "
11680 "in primary and secondary command buffers. "
11681 "Delete objects that are inuse. Call VkQueueSubmit "
11682 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011683
11684 ASSERT_NO_FATAL_FAILURE(InitState());
11685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11686
Tony Barbour552f6c02016-12-21 14:34:07 -070011687 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011688
11689 VkEvent event;
11690 VkEventCreateInfo event_create_info = {};
11691 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11692 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011693 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011694
Tony Barbour552f6c02016-12-21 14:34:07 -070011695 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060011696 vkDestroyEvent(m_device->device(), event, nullptr);
11697
11698 VkSubmitInfo submit_info = {};
11699 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11700 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011701 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070011702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
11703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "You are submitting command buffer 0x");
Mark Muellerc8d441e2016-08-23 17:36:00 -060011704 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11705 m_errorMonitor->VerifyFound();
11706
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011707 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060011708 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
11709
11710 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11711
Mark Mueller917f6bc2016-08-30 10:57:19 -060011712 VkSemaphoreCreateInfo semaphore_create_info = {};
11713 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
11714 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011715 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011716 VkFenceCreateInfo fence_create_info = {};
11717 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
11718 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011719 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011720
11721 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011722 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011723 descriptor_pool_type_count.descriptorCount = 1;
11724
11725 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
11726 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11727 descriptor_pool_create_info.maxSets = 1;
11728 descriptor_pool_create_info.poolSizeCount = 1;
11729 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011730 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011731
11732 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011733 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011734
11735 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060011736 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011737 descriptorset_layout_binding.descriptorCount = 1;
11738 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
11739
11740 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011741 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011742 descriptorset_layout_create_info.bindingCount = 1;
11743 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
11744
11745 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011746 ASSERT_VK_SUCCESS(
11747 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011748
11749 VkDescriptorSet descriptorset;
11750 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011751 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011752 descriptorset_allocate_info.descriptorSetCount = 1;
11753 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
11754 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011755 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011756
Mark Mueller4042b652016-09-05 22:52:21 -060011757 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
11758
11759 VkDescriptorBufferInfo buffer_info = {};
11760 buffer_info.buffer = buffer_test.GetBuffer();
11761 buffer_info.offset = 0;
11762 buffer_info.range = 1024;
11763
11764 VkWriteDescriptorSet write_descriptor_set = {};
11765 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11766 write_descriptor_set.dstSet = descriptorset;
11767 write_descriptor_set.descriptorCount = 1;
11768 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11769 write_descriptor_set.pBufferInfo = &buffer_info;
11770
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011771 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060011772
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011773 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11774 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011775
11776 VkPipelineObj pipe(m_device);
11777 pipe.AddColorAttachment();
11778 pipe.AddShader(&vs);
11779 pipe.AddShader(&fs);
11780
11781 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011782 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060011783 pipeline_layout_create_info.setLayoutCount = 1;
11784 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
11785
11786 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011787 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060011788
11789 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
11790
Tony Barbour552f6c02016-12-21 14:34:07 -070011791 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011792 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060011793
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011794 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
11795 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
11796 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011797
Tony Barbour552f6c02016-12-21 14:34:07 -070011798 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060011799
Mark Mueller917f6bc2016-08-30 10:57:19 -060011800 submit_info.signalSemaphoreCount = 1;
11801 submit_info.pSignalSemaphores = &semaphore;
11802 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011803 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060011804
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011806 vkDestroyEvent(m_device->device(), event, nullptr);
11807 m_errorMonitor->VerifyFound();
11808
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011810 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11811 m_errorMonitor->VerifyFound();
11812
Jeremy Hayes08369882017-02-02 10:31:06 -070011813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060011814 vkDestroyFence(m_device->device(), fence, nullptr);
11815 m_errorMonitor->VerifyFound();
11816
Tobin Ehlis122207b2016-09-01 08:50:06 -070011817 vkQueueWaitIdle(m_device->m_queue);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011818 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
11819 vkDestroyFence(m_device->device(), fence, nullptr);
11820 vkDestroyEvent(m_device->device(), event, nullptr);
11821 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011822 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060011823 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
11824}
11825
Tobin Ehlis2adda372016-09-01 08:51:06 -070011826TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
11827 TEST_DESCRIPTION("Delete in-use query pool.");
11828
11829 ASSERT_NO_FATAL_FAILURE(InitState());
11830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11831
11832 VkQueryPool query_pool;
11833 VkQueryPoolCreateInfo query_pool_ci{};
11834 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11835 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
11836 query_pool_ci.queryCount = 1;
11837 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070011838 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011839 // Reset query pool to create binding with cmd buffer
11840 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
11841
Tony Barbour552f6c02016-12-21 14:34:07 -070011842 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070011843
11844 VkSubmitInfo submit_info = {};
11845 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11846 submit_info.commandBufferCount = 1;
11847 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11848 // Submit cmd buffer and then destroy query pool while in-flight
11849 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
11850
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070011852 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11853 m_errorMonitor->VerifyFound();
11854
11855 vkQueueWaitIdle(m_device->m_queue);
11856 // Now that cmd buffer done we can safely destroy query_pool
11857 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
11858}
11859
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011860TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
11861 TEST_DESCRIPTION("Delete in-use pipeline.");
11862
11863 ASSERT_NO_FATAL_FAILURE(InitState());
11864 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11865
11866 // Empty pipeline layout used for binding PSO
11867 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11868 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11869 pipeline_layout_ci.setLayoutCount = 0;
11870 pipeline_layout_ci.pSetLayouts = NULL;
11871
11872 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011873 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011874 ASSERT_VK_SUCCESS(err);
11875
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011876 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011877 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011878 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11879 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011880 // Store pipeline handle so we can actually delete it before test finishes
11881 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011882 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011883 VkPipelineObj pipe(m_device);
11884 pipe.AddShader(&vs);
11885 pipe.AddShader(&fs);
11886 pipe.AddColorAttachment();
11887 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11888 delete_this_pipeline = pipe.handle();
11889
Tony Barbour552f6c02016-12-21 14:34:07 -070011890 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011891 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011892 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011893
Tony Barbour552f6c02016-12-21 14:34:07 -070011894 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011895
11896 VkSubmitInfo submit_info = {};
11897 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
11898 submit_info.commandBufferCount = 1;
11899 submit_info.pCommandBuffers = &m_commandBuffer->handle();
11900 // Submit cmd buffer and then pipeline destroyed while in-flight
11901 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011902 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060011903 m_errorMonitor->VerifyFound();
11904 // Make sure queue finished and then actually delete pipeline
11905 vkQueueWaitIdle(m_device->m_queue);
11906 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
11907 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
11908}
11909
Tobin Ehlis7d965da2016-09-19 16:15:45 -060011910TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
11911 TEST_DESCRIPTION("Delete in-use imageView.");
11912
11913 ASSERT_NO_FATAL_FAILURE(InitState());
11914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11915
11916 VkDescriptorPoolSize ds_type_count;
11917 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11918 ds_type_count.descriptorCount = 1;
11919
11920 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11921 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11922 ds_pool_ci.maxSets = 1;
11923 ds_pool_ci.poolSizeCount = 1;
11924 ds_pool_ci.pPoolSizes = &ds_type_count;
11925
11926 VkDescriptorPool ds_pool;
11927 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11928 ASSERT_VK_SUCCESS(err);
11929
11930 VkSamplerCreateInfo sampler_ci = {};
11931 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
11932 sampler_ci.pNext = NULL;
11933 sampler_ci.magFilter = VK_FILTER_NEAREST;
11934 sampler_ci.minFilter = VK_FILTER_NEAREST;
11935 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
11936 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11937 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11938 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
11939 sampler_ci.mipLodBias = 1.0;
11940 sampler_ci.anisotropyEnable = VK_FALSE;
11941 sampler_ci.maxAnisotropy = 1;
11942 sampler_ci.compareEnable = VK_FALSE;
11943 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
11944 sampler_ci.minLod = 1.0;
11945 sampler_ci.maxLod = 1.0;
11946 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
11947 sampler_ci.unnormalizedCoordinates = VK_FALSE;
11948 VkSampler sampler;
11949
11950 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
11951 ASSERT_VK_SUCCESS(err);
11952
11953 VkDescriptorSetLayoutBinding layout_binding;
11954 layout_binding.binding = 0;
11955 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
11956 layout_binding.descriptorCount = 1;
11957 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11958 layout_binding.pImmutableSamplers = NULL;
11959
11960 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11961 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11962 ds_layout_ci.bindingCount = 1;
11963 ds_layout_ci.pBindings = &layout_binding;
11964 VkDescriptorSetLayout ds_layout;
11965 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11966 ASSERT_VK_SUCCESS(err);
11967
11968 VkDescriptorSetAllocateInfo alloc_info = {};
11969 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11970 alloc_info.descriptorSetCount = 1;
11971 alloc_info.descriptorPool = ds_pool;
11972 alloc_info.pSetLayouts = &ds_layout;
11973 VkDescriptorSet descriptor_set;
11974 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11975 ASSERT_VK_SUCCESS(err);
11976
11977 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11978 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11979 pipeline_layout_ci.pNext = NULL;
11980 pipeline_layout_ci.setLayoutCount = 1;
11981 pipeline_layout_ci.pSetLayouts = &ds_layout;
11982
11983 VkPipelineLayout pipeline_layout;
11984 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11985 ASSERT_VK_SUCCESS(err);
11986
11987 VkImageObj image(m_device);
11988 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
11989 ASSERT_TRUE(image.initialized());
11990
11991 VkImageView view;
11992 VkImageViewCreateInfo ivci = {};
11993 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
11994 ivci.image = image.handle();
11995 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
11996 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
11997 ivci.subresourceRange.layerCount = 1;
11998 ivci.subresourceRange.baseMipLevel = 0;
11999 ivci.subresourceRange.levelCount = 1;
12000 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12001
12002 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12003 ASSERT_VK_SUCCESS(err);
12004
12005 VkDescriptorImageInfo image_info{};
12006 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12007 image_info.imageView = view;
12008 image_info.sampler = sampler;
12009
12010 VkWriteDescriptorSet descriptor_write = {};
12011 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12012 descriptor_write.dstSet = descriptor_set;
12013 descriptor_write.dstBinding = 0;
12014 descriptor_write.descriptorCount = 1;
12015 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12016 descriptor_write.pImageInfo = &image_info;
12017
12018 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12019
12020 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012021 char const *vsSource =
12022 "#version 450\n"
12023 "\n"
12024 "out gl_PerVertex { \n"
12025 " vec4 gl_Position;\n"
12026 "};\n"
12027 "void main(){\n"
12028 " gl_Position = vec4(1);\n"
12029 "}\n";
12030 char const *fsSource =
12031 "#version 450\n"
12032 "\n"
12033 "layout(set=0, binding=0) uniform sampler2D s;\n"
12034 "layout(location=0) out vec4 x;\n"
12035 "void main(){\n"
12036 " x = texture(s, vec2(1));\n"
12037 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012038 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12039 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12040 VkPipelineObj pipe(m_device);
12041 pipe.AddShader(&vs);
12042 pipe.AddShader(&fs);
12043 pipe.AddColorAttachment();
12044 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12045
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012047
Tony Barbour552f6c02016-12-21 14:34:07 -070012048 m_commandBuffer->BeginCommandBuffer();
12049 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012050 // Bind pipeline to cmd buffer
12051 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12052 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12053 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012054
12055 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12056 VkRect2D scissor = {{0, 0}, {16, 16}};
12057 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12058 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12059
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012060 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012061 m_commandBuffer->EndRenderPass();
12062 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012063 // Submit cmd buffer then destroy sampler
12064 VkSubmitInfo submit_info = {};
12065 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12066 submit_info.commandBufferCount = 1;
12067 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12068 // Submit cmd buffer and then destroy imageView while in-flight
12069 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12070
12071 vkDestroyImageView(m_device->device(), view, nullptr);
12072 m_errorMonitor->VerifyFound();
12073 vkQueueWaitIdle(m_device->m_queue);
12074 // Now we can actually destroy imageView
12075 vkDestroyImageView(m_device->device(), view, NULL);
12076 vkDestroySampler(m_device->device(), sampler, nullptr);
12077 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12078 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12079 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12080}
12081
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012082TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12083 TEST_DESCRIPTION("Delete in-use bufferView.");
12084
12085 ASSERT_NO_FATAL_FAILURE(InitState());
12086 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12087
12088 VkDescriptorPoolSize ds_type_count;
12089 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12090 ds_type_count.descriptorCount = 1;
12091
12092 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12093 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12094 ds_pool_ci.maxSets = 1;
12095 ds_pool_ci.poolSizeCount = 1;
12096 ds_pool_ci.pPoolSizes = &ds_type_count;
12097
12098 VkDescriptorPool ds_pool;
12099 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12100 ASSERT_VK_SUCCESS(err);
12101
12102 VkDescriptorSetLayoutBinding layout_binding;
12103 layout_binding.binding = 0;
12104 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12105 layout_binding.descriptorCount = 1;
12106 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12107 layout_binding.pImmutableSamplers = NULL;
12108
12109 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12110 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12111 ds_layout_ci.bindingCount = 1;
12112 ds_layout_ci.pBindings = &layout_binding;
12113 VkDescriptorSetLayout ds_layout;
12114 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12115 ASSERT_VK_SUCCESS(err);
12116
12117 VkDescriptorSetAllocateInfo alloc_info = {};
12118 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12119 alloc_info.descriptorSetCount = 1;
12120 alloc_info.descriptorPool = ds_pool;
12121 alloc_info.pSetLayouts = &ds_layout;
12122 VkDescriptorSet descriptor_set;
12123 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12124 ASSERT_VK_SUCCESS(err);
12125
12126 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12127 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12128 pipeline_layout_ci.pNext = NULL;
12129 pipeline_layout_ci.setLayoutCount = 1;
12130 pipeline_layout_ci.pSetLayouts = &ds_layout;
12131
12132 VkPipelineLayout pipeline_layout;
12133 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12134 ASSERT_VK_SUCCESS(err);
12135
12136 VkBuffer buffer;
12137 uint32_t queue_family_index = 0;
12138 VkBufferCreateInfo buffer_create_info = {};
12139 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12140 buffer_create_info.size = 1024;
12141 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12142 buffer_create_info.queueFamilyIndexCount = 1;
12143 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12144
12145 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12146 ASSERT_VK_SUCCESS(err);
12147
12148 VkMemoryRequirements memory_reqs;
12149 VkDeviceMemory buffer_memory;
12150
12151 VkMemoryAllocateInfo memory_info = {};
12152 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12153 memory_info.allocationSize = 0;
12154 memory_info.memoryTypeIndex = 0;
12155
12156 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12157 memory_info.allocationSize = memory_reqs.size;
12158 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12159 ASSERT_TRUE(pass);
12160
12161 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12162 ASSERT_VK_SUCCESS(err);
12163 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12164 ASSERT_VK_SUCCESS(err);
12165
12166 VkBufferView view;
12167 VkBufferViewCreateInfo bvci = {};
12168 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12169 bvci.buffer = buffer;
12170 bvci.format = VK_FORMAT_R8_UNORM;
12171 bvci.range = VK_WHOLE_SIZE;
12172
12173 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12174 ASSERT_VK_SUCCESS(err);
12175
12176 VkWriteDescriptorSet descriptor_write = {};
12177 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12178 descriptor_write.dstSet = descriptor_set;
12179 descriptor_write.dstBinding = 0;
12180 descriptor_write.descriptorCount = 1;
12181 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12182 descriptor_write.pTexelBufferView = &view;
12183
12184 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12185
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012186 char const *vsSource =
12187 "#version 450\n"
12188 "\n"
12189 "out gl_PerVertex { \n"
12190 " vec4 gl_Position;\n"
12191 "};\n"
12192 "void main(){\n"
12193 " gl_Position = vec4(1);\n"
12194 "}\n";
12195 char const *fsSource =
12196 "#version 450\n"
12197 "\n"
12198 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12199 "layout(location=0) out vec4 x;\n"
12200 "void main(){\n"
12201 " x = imageLoad(s, 0);\n"
12202 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012203 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12204 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12205 VkPipelineObj pipe(m_device);
12206 pipe.AddShader(&vs);
12207 pipe.AddShader(&fs);
12208 pipe.AddColorAttachment();
12209 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12210
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012212
Tony Barbour552f6c02016-12-21 14:34:07 -070012213 m_commandBuffer->BeginCommandBuffer();
12214 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012215 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12216 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12217 VkRect2D scissor = {{0, 0}, {16, 16}};
12218 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12219 // Bind pipeline to cmd buffer
12220 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12221 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12222 &descriptor_set, 0, nullptr);
12223 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012224 m_commandBuffer->EndRenderPass();
12225 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012226
12227 VkSubmitInfo submit_info = {};
12228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12229 submit_info.commandBufferCount = 1;
12230 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12231 // Submit cmd buffer and then destroy bufferView while in-flight
12232 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12233
12234 vkDestroyBufferView(m_device->device(), view, nullptr);
12235 m_errorMonitor->VerifyFound();
12236 vkQueueWaitIdle(m_device->m_queue);
12237 // Now we can actually destroy bufferView
12238 vkDestroyBufferView(m_device->device(), view, NULL);
12239 vkDestroyBuffer(m_device->device(), buffer, NULL);
12240 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12241 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12242 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12243 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12244}
12245
Tobin Ehlis209532e2016-09-07 13:52:18 -060012246TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12247 TEST_DESCRIPTION("Delete in-use sampler.");
12248
12249 ASSERT_NO_FATAL_FAILURE(InitState());
12250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12251
12252 VkDescriptorPoolSize ds_type_count;
12253 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12254 ds_type_count.descriptorCount = 1;
12255
12256 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12257 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12258 ds_pool_ci.maxSets = 1;
12259 ds_pool_ci.poolSizeCount = 1;
12260 ds_pool_ci.pPoolSizes = &ds_type_count;
12261
12262 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012263 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012264 ASSERT_VK_SUCCESS(err);
12265
12266 VkSamplerCreateInfo sampler_ci = {};
12267 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12268 sampler_ci.pNext = NULL;
12269 sampler_ci.magFilter = VK_FILTER_NEAREST;
12270 sampler_ci.minFilter = VK_FILTER_NEAREST;
12271 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12272 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12273 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12274 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12275 sampler_ci.mipLodBias = 1.0;
12276 sampler_ci.anisotropyEnable = VK_FALSE;
12277 sampler_ci.maxAnisotropy = 1;
12278 sampler_ci.compareEnable = VK_FALSE;
12279 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12280 sampler_ci.minLod = 1.0;
12281 sampler_ci.maxLod = 1.0;
12282 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12283 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12284 VkSampler sampler;
12285
12286 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12287 ASSERT_VK_SUCCESS(err);
12288
12289 VkDescriptorSetLayoutBinding layout_binding;
12290 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012291 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012292 layout_binding.descriptorCount = 1;
12293 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12294 layout_binding.pImmutableSamplers = NULL;
12295
12296 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12297 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12298 ds_layout_ci.bindingCount = 1;
12299 ds_layout_ci.pBindings = &layout_binding;
12300 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012301 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012302 ASSERT_VK_SUCCESS(err);
12303
12304 VkDescriptorSetAllocateInfo alloc_info = {};
12305 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12306 alloc_info.descriptorSetCount = 1;
12307 alloc_info.descriptorPool = ds_pool;
12308 alloc_info.pSetLayouts = &ds_layout;
12309 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012310 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012311 ASSERT_VK_SUCCESS(err);
12312
12313 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12314 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12315 pipeline_layout_ci.pNext = NULL;
12316 pipeline_layout_ci.setLayoutCount = 1;
12317 pipeline_layout_ci.pSetLayouts = &ds_layout;
12318
12319 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012320 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012321 ASSERT_VK_SUCCESS(err);
12322
12323 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012324 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 -060012325 ASSERT_TRUE(image.initialized());
12326
12327 VkImageView view;
12328 VkImageViewCreateInfo ivci = {};
12329 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12330 ivci.image = image.handle();
12331 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12332 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12333 ivci.subresourceRange.layerCount = 1;
12334 ivci.subresourceRange.baseMipLevel = 0;
12335 ivci.subresourceRange.levelCount = 1;
12336 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12337
12338 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12339 ASSERT_VK_SUCCESS(err);
12340
12341 VkDescriptorImageInfo image_info{};
12342 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12343 image_info.imageView = view;
12344 image_info.sampler = sampler;
12345
12346 VkWriteDescriptorSet descriptor_write = {};
12347 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12348 descriptor_write.dstSet = descriptor_set;
12349 descriptor_write.dstBinding = 0;
12350 descriptor_write.descriptorCount = 1;
12351 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12352 descriptor_write.pImageInfo = &image_info;
12353
12354 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12355
12356 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012357 char const *vsSource =
12358 "#version 450\n"
12359 "\n"
12360 "out gl_PerVertex { \n"
12361 " vec4 gl_Position;\n"
12362 "};\n"
12363 "void main(){\n"
12364 " gl_Position = vec4(1);\n"
12365 "}\n";
12366 char const *fsSource =
12367 "#version 450\n"
12368 "\n"
12369 "layout(set=0, binding=0) uniform sampler2D s;\n"
12370 "layout(location=0) out vec4 x;\n"
12371 "void main(){\n"
12372 " x = texture(s, vec2(1));\n"
12373 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012374 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12375 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12376 VkPipelineObj pipe(m_device);
12377 pipe.AddShader(&vs);
12378 pipe.AddShader(&fs);
12379 pipe.AddColorAttachment();
12380 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12381
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012383
Tony Barbour552f6c02016-12-21 14:34:07 -070012384 m_commandBuffer->BeginCommandBuffer();
12385 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012386 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012387 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12388 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12389 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012390
12391 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12392 VkRect2D scissor = {{0, 0}, {16, 16}};
12393 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12394 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12395
Tobin Ehlis209532e2016-09-07 13:52:18 -060012396 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012397 m_commandBuffer->EndRenderPass();
12398 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012399 // Submit cmd buffer then destroy sampler
12400 VkSubmitInfo submit_info = {};
12401 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12402 submit_info.commandBufferCount = 1;
12403 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12404 // Submit cmd buffer and then destroy sampler while in-flight
12405 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12406
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012407 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012408 m_errorMonitor->VerifyFound();
12409 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012410
Tobin Ehlis209532e2016-09-07 13:52:18 -060012411 // Now we can actually destroy sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012412 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012413 vkDestroyImageView(m_device->device(), view, NULL);
12414 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12415 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12416 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12417}
12418
Mark Mueller1cd9f412016-08-25 13:23:52 -060012419TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012420 TEST_DESCRIPTION(
12421 "Call VkQueueSubmit with a semaphore that is already "
12422 "signaled but not waited on by the queue. Wait on a "
12423 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012424
12425 ASSERT_NO_FATAL_FAILURE(InitState());
12426 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12427
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012428 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 -070012429 const char *invalid_fence_wait_message =
12430 " which has not been submitted on a Queue or during "
12431 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012432
Tony Barbour552f6c02016-12-21 14:34:07 -070012433 m_commandBuffer->BeginCommandBuffer();
12434 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012435
12436 VkSemaphoreCreateInfo semaphore_create_info = {};
12437 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12438 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012439 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012440 VkSubmitInfo submit_info = {};
12441 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12442 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012443 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012444 submit_info.signalSemaphoreCount = 1;
12445 submit_info.pSignalSemaphores = &semaphore;
12446 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012447 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012448 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012449 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012450 m_commandBuffer->BeginCommandBuffer();
12451 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012453 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12454 m_errorMonitor->VerifyFound();
12455
Mark Mueller1cd9f412016-08-25 13:23:52 -060012456 VkFenceCreateInfo fence_create_info = {};
12457 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12458 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012459 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012460
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012461 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012462 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12463 m_errorMonitor->VerifyFound();
12464
Mark Mueller4042b652016-09-05 22:52:21 -060012465 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012466 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012467 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12468}
12469
Tobin Ehlis4af23302016-07-19 10:50:30 -060012470TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012471 TEST_DESCRIPTION(
12472 "Bind a secondary command buffer with with a framebuffer "
12473 "that does not match the framebuffer for the active "
12474 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012475 ASSERT_NO_FATAL_FAILURE(InitState());
12476 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12477
12478 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012479 VkAttachmentDescription attachment = {0,
12480 VK_FORMAT_B8G8R8A8_UNORM,
12481 VK_SAMPLE_COUNT_1_BIT,
12482 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12483 VK_ATTACHMENT_STORE_OP_STORE,
12484 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12485 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12486 VK_IMAGE_LAYOUT_UNDEFINED,
12487 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012489 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012490
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012491 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012492
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012493 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012494
12495 VkRenderPass rp;
12496 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
12497 ASSERT_VK_SUCCESS(err);
12498
12499 // A compatible framebuffer.
12500 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012501 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 -060012502 ASSERT_TRUE(image.initialized());
12503
12504 VkImageViewCreateInfo ivci = {
12505 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
12506 nullptr,
12507 0,
12508 image.handle(),
12509 VK_IMAGE_VIEW_TYPE_2D,
12510 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012511 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
12512 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060012513 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
12514 };
12515 VkImageView view;
12516 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
12517 ASSERT_VK_SUCCESS(err);
12518
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012519 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060012520 VkFramebuffer fb;
12521 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
12522 ASSERT_VK_SUCCESS(err);
12523
12524 VkCommandBufferAllocateInfo cbai = {};
12525 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12526 cbai.commandPool = m_commandPool;
12527 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12528 cbai.commandBufferCount = 1;
12529
12530 VkCommandBuffer sec_cb;
12531 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
12532 ASSERT_VK_SUCCESS(err);
12533 VkCommandBufferBeginInfo cbbi = {};
12534 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130012535 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060012536 cbii.renderPass = renderPass();
12537 cbii.framebuffer = fb;
12538 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12539 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012540 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 -060012541 cbbi.pInheritanceInfo = &cbii;
12542 vkBeginCommandBuffer(sec_cb, &cbbi);
12543 vkEndCommandBuffer(sec_cb);
12544
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012545 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120012546 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
12547 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060012548
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060012550 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012551 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
12552 m_errorMonitor->VerifyFound();
12553 // Cleanup
12554 vkDestroyImageView(m_device->device(), view, NULL);
12555 vkDestroyRenderPass(m_device->device(), rp, NULL);
12556 vkDestroyFramebuffer(m_device->device(), fb, NULL);
12557}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012558
12559TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012560 TEST_DESCRIPTION(
12561 "If logicOp is available on the device, set it to an "
12562 "invalid value. If logicOp is not available, attempt to "
12563 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012564 ASSERT_NO_FATAL_FAILURE(InitState());
12565 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12566
12567 auto features = m_device->phy().features();
12568 // Set the expected error depending on whether or not logicOp available
12569 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012570 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12571 "If logic operations feature not "
12572 "enabled, logicOpEnable must be "
12573 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012574 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130012575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012576 }
12577 // Create a pipeline using logicOp
12578 VkResult err;
12579
12580 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12581 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12582
12583 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012584 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012585 ASSERT_VK_SUCCESS(err);
12586
12587 VkPipelineViewportStateCreateInfo vp_state_ci = {};
12588 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12589 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012590 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012591 vp_state_ci.pViewports = &vp;
12592 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012593 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012594 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012595
12596 VkPipelineShaderStageCreateInfo shaderStages[2];
12597 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
12598
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012599 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12600 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012601 shaderStages[0] = vs.GetStageCreateInfo();
12602 shaderStages[1] = fs.GetStageCreateInfo();
12603
12604 VkPipelineVertexInputStateCreateInfo vi_ci = {};
12605 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12606
12607 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
12608 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12609 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12610
12611 VkPipelineRasterizationStateCreateInfo rs_ci = {};
12612 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130012613 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012614
12615 VkPipelineColorBlendAttachmentState att = {};
12616 att.blendEnable = VK_FALSE;
12617 att.colorWriteMask = 0xf;
12618
12619 VkPipelineColorBlendStateCreateInfo cb_ci = {};
12620 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12621 // Enable logicOp & set logicOp to value 1 beyond allowed entries
12622 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012623 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012624 cb_ci.attachmentCount = 1;
12625 cb_ci.pAttachments = &att;
12626
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012627 VkPipelineMultisampleStateCreateInfo ms_ci = {};
12628 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
12629 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
12630
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012631 VkGraphicsPipelineCreateInfo gp_ci = {};
12632 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12633 gp_ci.stageCount = 2;
12634 gp_ci.pStages = shaderStages;
12635 gp_ci.pVertexInputState = &vi_ci;
12636 gp_ci.pInputAssemblyState = &ia_ci;
12637 gp_ci.pViewportState = &vp_state_ci;
12638 gp_ci.pRasterizationState = &rs_ci;
12639 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130012640 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012641 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12642 gp_ci.layout = pipeline_layout;
12643 gp_ci.renderPass = renderPass();
12644
12645 VkPipelineCacheCreateInfo pc_ci = {};
12646 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12647
12648 VkPipeline pipeline;
12649 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012650 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012651 ASSERT_VK_SUCCESS(err);
12652
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012653 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012654 m_errorMonitor->VerifyFound();
12655 if (VK_SUCCESS == err) {
12656 vkDestroyPipeline(m_device->device(), pipeline, NULL);
12657 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060012658 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
12659 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12660}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012661
Mike Stroyanaccf7692015-05-12 16:00:45 -060012662#if GTEST_IS_THREADSAFE
12663struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012664 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012665 VkEvent event;
12666 bool bailout;
12667};
12668
Karl Schultz6addd812016-02-02 17:17:23 -070012669extern "C" void *AddToCommandBuffer(void *arg) {
12670 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012671
Mike Stroyana6d14942016-07-13 15:10:05 -060012672 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012673 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012674 if (data->bailout) {
12675 break;
12676 }
12677 }
12678 return NULL;
12679}
12680
Karl Schultz6addd812016-02-02 17:17:23 -070012681TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012682 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012683
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012685
Mike Stroyanaccf7692015-05-12 16:00:45 -060012686 ASSERT_NO_FATAL_FAILURE(InitState());
12687 ASSERT_NO_FATAL_FAILURE(InitViewport());
12688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12689
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012690 // Calls AllocateCommandBuffers
12691 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012692
12693 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012694 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012695
12696 VkEventCreateInfo event_info;
12697 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060012698 VkResult err;
12699
12700 memset(&event_info, 0, sizeof(event_info));
12701 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12702
Chia-I Wuf7458c52015-10-26 21:10:41 +080012703 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012704 ASSERT_VK_SUCCESS(err);
12705
Mike Stroyanaccf7692015-05-12 16:00:45 -060012706 err = vkResetEvent(device(), event);
12707 ASSERT_VK_SUCCESS(err);
12708
12709 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012710 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012711 data.event = event;
12712 data.bailout = false;
12713 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060012714
12715 // First do some correct operations using multiple threads.
12716 // Add many entries to command buffer from another thread.
12717 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
12718 // Make non-conflicting calls from this thread at the same time.
12719 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060012720 uint32_t count;
12721 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060012722 }
12723 test_platform_thread_join(thread, NULL);
12724
12725 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060012726 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012727 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012728 // Add many entries to command buffer from this thread at the same time.
12729 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060012730
Mike Stroyan4268d1f2015-07-13 14:45:35 -060012731 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012732 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012733
Mike Stroyan10b8cb72016-01-22 15:22:03 -070012734 m_errorMonitor->SetBailout(NULL);
12735
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012736 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060012737
Chia-I Wuf7458c52015-10-26 21:10:41 +080012738 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060012739}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012740#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060012741
Karl Schultz6addd812016-02-02 17:17:23 -070012742TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012743 TEST_DESCRIPTION(
12744 "Test that an error is produced for a spirv module "
12745 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120012746
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012748
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012749 ASSERT_NO_FATAL_FAILURE(InitState());
12750 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12751
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012752 VkShaderModule module;
12753 VkShaderModuleCreateInfo moduleCreateInfo;
12754 struct icd_spv_header spv;
12755
12756 spv.magic = ICD_SPV_MAGIC;
12757 spv.version = ICD_SPV_VERSION;
12758 spv.gen_magic = 0;
12759
12760 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12761 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012762 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012763 moduleCreateInfo.codeSize = 4;
12764 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012765 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012766
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012767 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012768}
12769
Karl Schultz6addd812016-02-02 17:17:23 -070012770TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012771 TEST_DESCRIPTION(
12772 "Test that an error is produced for a spirv module "
12773 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120012774
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012776
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012777 ASSERT_NO_FATAL_FAILURE(InitState());
12778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12779
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012780 VkShaderModule module;
12781 VkShaderModuleCreateInfo moduleCreateInfo;
12782 struct icd_spv_header spv;
12783
12784 spv.magic = ~ICD_SPV_MAGIC;
12785 spv.version = ICD_SPV_VERSION;
12786 spv.gen_magic = 0;
12787
12788 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12789 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070012790 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012791 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12792 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012793 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012794
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012795 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012796}
12797
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012798#if 0
12799// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070012800TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070012801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012802 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012803
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012804 ASSERT_NO_FATAL_FAILURE(InitState());
12805 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12806
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012807 VkShaderModule module;
12808 VkShaderModuleCreateInfo moduleCreateInfo;
12809 struct icd_spv_header spv;
12810
12811 spv.magic = ICD_SPV_MAGIC;
12812 spv.version = ~ICD_SPV_VERSION;
12813 spv.gen_magic = 0;
12814
12815 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
12816 moduleCreateInfo.pNext = NULL;
12817
Karl Schultz6addd812016-02-02 17:17:23 -070012818 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012819 moduleCreateInfo.codeSize = sizeof(spv) + 10;
12820 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080012821 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012822
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012823 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012824}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120012825#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060012826
Karl Schultz6addd812016-02-02 17:17:23 -070012827TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012828 TEST_DESCRIPTION(
12829 "Test that a warning is produced for a vertex output that "
12830 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060012832
Chris Forbes9f7ff632015-05-25 11:13:08 +120012833 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060012834 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012835
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012836 char const *vsSource =
12837 "#version 450\n"
12838 "\n"
12839 "layout(location=0) out float x;\n"
12840 "out gl_PerVertex {\n"
12841 " vec4 gl_Position;\n"
12842 "};\n"
12843 "void main(){\n"
12844 " gl_Position = vec4(1);\n"
12845 " x = 0;\n"
12846 "}\n";
12847 char const *fsSource =
12848 "#version 450\n"
12849 "\n"
12850 "layout(location=0) out vec4 color;\n"
12851 "void main(){\n"
12852 " color = vec4(1);\n"
12853 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120012854
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060012855 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012857
12858 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080012859 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012860 pipe.AddShader(&vs);
12861 pipe.AddShader(&fs);
12862
Chris Forbes9f7ff632015-05-25 11:13:08 +120012863 VkDescriptorSetObj descriptorSet(m_device);
12864 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080012865 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120012866
Tony Barbour5781e8f2015-08-04 16:23:11 -060012867 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120012868
Chris Forbes8f36a8a2016-04-07 13:21:07 +120012869 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120012870}
Chris Forbes9f7ff632015-05-25 11:13:08 +120012871
Mark Mueller098c9cb2016-09-08 09:01:57 -060012872TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
12873 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12874
12875 ASSERT_NO_FATAL_FAILURE(InitState());
12876 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12877
12878 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012879 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012880
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012881 char const *vsSource =
12882 "#version 450\n"
12883 "\n"
12884 "out gl_PerVertex {\n"
12885 " vec4 gl_Position;\n"
12886 "};\n"
12887 "void main(){\n"
12888 " gl_Position = vec4(1);\n"
12889 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012890
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012891 char const *fsSource =
12892 "#version 450\n"
12893 "\n"
12894 "layout (constant_id = 0) const float r = 0.0f;\n"
12895 "layout(location = 0) out vec4 uFragColor;\n"
12896 "void main(){\n"
12897 " uFragColor = vec4(r,1,0,1);\n"
12898 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060012899
12900 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12901 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12902
12903 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
12904 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12905
12906 VkPipelineLayout pipeline_layout;
12907 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
12908
12909 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
12910 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
12911 vp_state_create_info.viewportCount = 1;
12912 VkViewport viewport = {};
12913 vp_state_create_info.pViewports = &viewport;
12914 vp_state_create_info.scissorCount = 1;
12915 VkRect2D scissors = {};
12916 vp_state_create_info.pScissors = &scissors;
12917
12918 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
12919
12920 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
12921 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
12922 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
12923 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
12924
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012925 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060012926
12927 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
12928 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
12929
12930 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
12931 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
12932 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
12933
12934 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
12935 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
12936 rasterization_state_create_info.pNext = nullptr;
12937 rasterization_state_create_info.lineWidth = 1.0f;
12938 rasterization_state_create_info.rasterizerDiscardEnable = true;
12939
12940 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
12941 color_blend_attachment_state.blendEnable = VK_FALSE;
12942 color_blend_attachment_state.colorWriteMask = 0xf;
12943
12944 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
12945 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
12946 color_blend_state_create_info.attachmentCount = 1;
12947 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
12948
12949 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
12950 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
12951 graphicspipe_create_info.stageCount = 2;
12952 graphicspipe_create_info.pStages = shader_stage_create_info;
12953 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
12954 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
12955 graphicspipe_create_info.pViewportState = &vp_state_create_info;
12956 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
12957 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
12958 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
12959 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
12960 graphicspipe_create_info.layout = pipeline_layout;
12961 graphicspipe_create_info.renderPass = renderPass();
12962
12963 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
12964 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
12965
12966 VkPipelineCache pipelineCache;
12967 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
12968
12969 // This structure maps constant ids to data locations.
12970 const VkSpecializationMapEntry entry =
12971 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012972 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060012973
12974 uint32_t data = 1;
12975
12976 // Set up the info describing spec map and data
12977 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070012978 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060012979 };
12980 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
12981
12982 VkPipeline pipeline;
12983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
12984 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
12985 m_errorMonitor->VerifyFound();
12986
12987 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
12988 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12989}
12990
12991TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
12992 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
12993
12994 ASSERT_NO_FATAL_FAILURE(InitState());
12995 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12996
12997 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
12998
12999 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13000 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13001 descriptor_pool_type_count[0].descriptorCount = 1;
13002 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13003 descriptor_pool_type_count[1].descriptorCount = 1;
13004
13005 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13006 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13007 descriptor_pool_create_info.maxSets = 1;
13008 descriptor_pool_create_info.poolSizeCount = 2;
13009 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13010 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13011
13012 VkDescriptorPool descriptorset_pool;
13013 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13014
13015 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13016 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13017 descriptorset_layout_binding.descriptorCount = 1;
13018 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13019
13020 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13021 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13022 descriptorset_layout_create_info.bindingCount = 1;
13023 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13024
13025 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013026 ASSERT_VK_SUCCESS(
13027 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013028
13029 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13030 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13031 descriptorset_allocate_info.descriptorSetCount = 1;
13032 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13033 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13034 VkDescriptorSet descriptorset;
13035 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13036
13037 // Challenge core_validation with a non uniform buffer type.
13038 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13039
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013040 char const *vsSource =
13041 "#version 450\n"
13042 "\n"
13043 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13044 " mat4 mvp;\n"
13045 "} ubuf;\n"
13046 "out gl_PerVertex {\n"
13047 " vec4 gl_Position;\n"
13048 "};\n"
13049 "void main(){\n"
13050 " gl_Position = ubuf.mvp * vec4(1);\n"
13051 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013052
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013053 char const *fsSource =
13054 "#version 450\n"
13055 "\n"
13056 "layout(location = 0) out vec4 uFragColor;\n"
13057 "void main(){\n"
13058 " uFragColor = vec4(0,1,0,1);\n"
13059 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013060
13061 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13062 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13063
13064 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13065 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13066 pipeline_layout_create_info.setLayoutCount = 1;
13067 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13068
13069 VkPipelineLayout pipeline_layout;
13070 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13071
13072 VkPipelineObj pipe(m_device);
13073 pipe.AddColorAttachment();
13074 pipe.AddShader(&vs);
13075 pipe.AddShader(&fs);
13076
13077 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13078 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13079 m_errorMonitor->VerifyFound();
13080
13081 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13082 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13083 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13084}
13085
13086TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13087 TEST_DESCRIPTION(
13088 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13089
13090 ASSERT_NO_FATAL_FAILURE(InitState());
13091 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13092
13093 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13094
13095 VkDescriptorPoolSize descriptor_pool_type_count = {};
13096 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13097 descriptor_pool_type_count.descriptorCount = 1;
13098
13099 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13100 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13101 descriptor_pool_create_info.maxSets = 1;
13102 descriptor_pool_create_info.poolSizeCount = 1;
13103 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13104 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13105
13106 VkDescriptorPool descriptorset_pool;
13107 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13108
13109 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13110 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13111 descriptorset_layout_binding.descriptorCount = 1;
13112 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13113 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13114
13115 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13116 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13117 descriptorset_layout_create_info.bindingCount = 1;
13118 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13119
13120 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013121 ASSERT_VK_SUCCESS(
13122 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013123
13124 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13125 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13126 descriptorset_allocate_info.descriptorSetCount = 1;
13127 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13128 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13129 VkDescriptorSet descriptorset;
13130 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13131
13132 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13133
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013134 char const *vsSource =
13135 "#version 450\n"
13136 "\n"
13137 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13138 " mat4 mvp;\n"
13139 "} ubuf;\n"
13140 "out gl_PerVertex {\n"
13141 " vec4 gl_Position;\n"
13142 "};\n"
13143 "void main(){\n"
13144 " gl_Position = ubuf.mvp * vec4(1);\n"
13145 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013146
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013147 char const *fsSource =
13148 "#version 450\n"
13149 "\n"
13150 "layout(location = 0) out vec4 uFragColor;\n"
13151 "void main(){\n"
13152 " uFragColor = vec4(0,1,0,1);\n"
13153 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013154
13155 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13156 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13157
13158 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13159 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13160 pipeline_layout_create_info.setLayoutCount = 1;
13161 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13162
13163 VkPipelineLayout pipeline_layout;
13164 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13165
13166 VkPipelineObj pipe(m_device);
13167 pipe.AddColorAttachment();
13168 pipe.AddShader(&vs);
13169 pipe.AddShader(&fs);
13170
13171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13172 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13173 m_errorMonitor->VerifyFound();
13174
13175 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13176 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13177 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13178}
13179
13180TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013181 TEST_DESCRIPTION(
13182 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13183 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013184
13185 ASSERT_NO_FATAL_FAILURE(InitState());
13186 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13187
13188 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013189 "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 -060013190
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013191 char const *vsSource =
13192 "#version 450\n"
13193 "\n"
13194 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13195 "out gl_PerVertex {\n"
13196 " vec4 gl_Position;\n"
13197 "};\n"
13198 "void main(){\n"
13199 " gl_Position = vec4(consts.x);\n"
13200 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013201
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013202 char const *fsSource =
13203 "#version 450\n"
13204 "\n"
13205 "layout(location = 0) out vec4 uFragColor;\n"
13206 "void main(){\n"
13207 " uFragColor = vec4(0,1,0,1);\n"
13208 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013209
13210 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13211 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13212
13213 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13214 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13215
13216 // Set up a push constant range
13217 VkPushConstantRange push_constant_ranges = {};
13218 // Set to the wrong stage to challenge core_validation
13219 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13220 push_constant_ranges.size = 4;
13221
13222 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13223 pipeline_layout_create_info.pushConstantRangeCount = 1;
13224
13225 VkPipelineLayout pipeline_layout;
13226 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13227
13228 VkPipelineObj pipe(m_device);
13229 pipe.AddColorAttachment();
13230 pipe.AddShader(&vs);
13231 pipe.AddShader(&fs);
13232
13233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13234 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13235 m_errorMonitor->VerifyFound();
13236
13237 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13238}
13239
13240TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13241 TEST_DESCRIPTION(
13242 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13243
13244 ASSERT_NO_FATAL_FAILURE(InitState());
13245 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13246
13247 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013248 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013249
13250 // Some awkward steps are required to test with custom device features.
13251 std::vector<const char *> device_extension_names;
13252 auto features = m_device->phy().features();
13253 // Disable support for 64 bit floats
13254 features.shaderFloat64 = false;
13255 // The sacrificial device object
13256 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13257
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013258 char const *vsSource =
13259 "#version 450\n"
13260 "\n"
13261 "out gl_PerVertex {\n"
13262 " vec4 gl_Position;\n"
13263 "};\n"
13264 "void main(){\n"
13265 " gl_Position = vec4(1);\n"
13266 "}\n";
13267 char const *fsSource =
13268 "#version 450\n"
13269 "\n"
13270 "layout(location=0) out vec4 color;\n"
13271 "void main(){\n"
13272 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13273 " color = vec4(green);\n"
13274 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013275
13276 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13277 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13278
13279 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013280
13281 VkPipelineObj pipe(&test_device);
13282 pipe.AddColorAttachment();
13283 pipe.AddShader(&vs);
13284 pipe.AddShader(&fs);
13285
13286 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13287 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13288 VkPipelineLayout pipeline_layout;
13289 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13290
13291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13292 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13293 m_errorMonitor->VerifyFound();
13294
13295 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13296}
13297
13298TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13299 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13300
13301 ASSERT_NO_FATAL_FAILURE(InitState());
13302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13303
13304 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13305
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013306 char const *vsSource =
13307 "#version 450\n"
13308 "\n"
13309 "out gl_PerVertex {\n"
13310 " vec4 gl_Position;\n"
13311 "};\n"
13312 "layout(xfb_buffer = 1) out;"
13313 "void main(){\n"
13314 " gl_Position = vec4(1);\n"
13315 "}\n";
13316 char const *fsSource =
13317 "#version 450\n"
13318 "\n"
13319 "layout(location=0) out vec4 color;\n"
13320 "void main(){\n"
13321 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13322 " color = vec4(green);\n"
13323 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013324
13325 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13326 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13327
13328 VkPipelineObj pipe(m_device);
13329 pipe.AddColorAttachment();
13330 pipe.AddShader(&vs);
13331 pipe.AddShader(&fs);
13332
13333 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13334 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13335 VkPipelineLayout pipeline_layout;
13336 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13337
13338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13339 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13340 m_errorMonitor->VerifyFound();
13341
13342 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13343}
13344
Karl Schultz6addd812016-02-02 17:17:23 -070013345TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013346 TEST_DESCRIPTION(
13347 "Test that an error is produced for a fragment shader input "
13348 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013351
Chris Forbes59cb88d2015-05-25 11:13:13 +120013352 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013353 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013355 char const *vsSource =
13356 "#version 450\n"
13357 "\n"
13358 "out gl_PerVertex {\n"
13359 " vec4 gl_Position;\n"
13360 "};\n"
13361 "void main(){\n"
13362 " gl_Position = vec4(1);\n"
13363 "}\n";
13364 char const *fsSource =
13365 "#version 450\n"
13366 "\n"
13367 "layout(location=0) in float x;\n"
13368 "layout(location=0) out vec4 color;\n"
13369 "void main(){\n"
13370 " color = vec4(x);\n"
13371 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013372
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013373 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13374 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013375
13376 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013377 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013378 pipe.AddShader(&vs);
13379 pipe.AddShader(&fs);
13380
Chris Forbes59cb88d2015-05-25 11:13:13 +120013381 VkDescriptorSetObj descriptorSet(m_device);
13382 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013383 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013384
Tony Barbour5781e8f2015-08-04 16:23:11 -060013385 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013386
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013387 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013388}
13389
Karl Schultz6addd812016-02-02 17:17:23 -070013390TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013391 TEST_DESCRIPTION(
13392 "Test that an error is produced for a fragment shader input "
13393 "within an interace block, which is not present in the outputs "
13394 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013396
13397 ASSERT_NO_FATAL_FAILURE(InitState());
13398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13399
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013400 char const *vsSource =
13401 "#version 450\n"
13402 "\n"
13403 "out gl_PerVertex {\n"
13404 " vec4 gl_Position;\n"
13405 "};\n"
13406 "void main(){\n"
13407 " gl_Position = vec4(1);\n"
13408 "}\n";
13409 char const *fsSource =
13410 "#version 450\n"
13411 "\n"
13412 "in block { layout(location=0) float x; } ins;\n"
13413 "layout(location=0) out vec4 color;\n"
13414 "void main(){\n"
13415 " color = vec4(ins.x);\n"
13416 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013417
13418 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13419 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13420
13421 VkPipelineObj pipe(m_device);
13422 pipe.AddColorAttachment();
13423 pipe.AddShader(&vs);
13424 pipe.AddShader(&fs);
13425
13426 VkDescriptorSetObj descriptorSet(m_device);
13427 descriptorSet.AppendDummy();
13428 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13429
13430 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13431
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013432 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013433}
13434
Karl Schultz6addd812016-02-02 17:17:23 -070013435TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013436 TEST_DESCRIPTION(
13437 "Test that an error is produced for mismatched array sizes "
13438 "across the vertex->fragment shader interface");
13439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13440 "Type mismatch on location 0.0: 'ptr to "
13441 "output arr[2] of float32' vs 'ptr to "
13442 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013443
13444 ASSERT_NO_FATAL_FAILURE(InitState());
13445 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13446
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013447 char const *vsSource =
13448 "#version 450\n"
13449 "\n"
13450 "layout(location=0) out float x[2];\n"
13451 "out gl_PerVertex {\n"
13452 " vec4 gl_Position;\n"
13453 "};\n"
13454 "void main(){\n"
13455 " x[0] = 0; x[1] = 0;\n"
13456 " gl_Position = vec4(1);\n"
13457 "}\n";
13458 char const *fsSource =
13459 "#version 450\n"
13460 "\n"
13461 "layout(location=0) in float x[1];\n"
13462 "layout(location=0) out vec4 color;\n"
13463 "void main(){\n"
13464 " color = vec4(x[0]);\n"
13465 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013466
13467 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13468 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13469
13470 VkPipelineObj pipe(m_device);
13471 pipe.AddColorAttachment();
13472 pipe.AddShader(&vs);
13473 pipe.AddShader(&fs);
13474
13475 VkDescriptorSetObj descriptorSet(m_device);
13476 descriptorSet.AppendDummy();
13477 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13478
13479 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13480
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013481 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013482}
13483
Karl Schultz6addd812016-02-02 17:17:23 -070013484TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013485 TEST_DESCRIPTION(
13486 "Test that an error is produced for mismatched types across "
13487 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013489
Chris Forbesb56af562015-05-25 11:13:17 +120013490 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013491 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120013492
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013493 char const *vsSource =
13494 "#version 450\n"
13495 "\n"
13496 "layout(location=0) out int x;\n"
13497 "out gl_PerVertex {\n"
13498 " vec4 gl_Position;\n"
13499 "};\n"
13500 "void main(){\n"
13501 " x = 0;\n"
13502 " gl_Position = vec4(1);\n"
13503 "}\n";
13504 char const *fsSource =
13505 "#version 450\n"
13506 "\n"
13507 "layout(location=0) in float x;\n" /* VS writes int */
13508 "layout(location=0) out vec4 color;\n"
13509 "void main(){\n"
13510 " color = vec4(x);\n"
13511 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120013512
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013513 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13514 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120013515
13516 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013517 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120013518 pipe.AddShader(&vs);
13519 pipe.AddShader(&fs);
13520
Chris Forbesb56af562015-05-25 11:13:17 +120013521 VkDescriptorSetObj descriptorSet(m_device);
13522 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013523 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120013524
Tony Barbour5781e8f2015-08-04 16:23:11 -060013525 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120013526
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013527 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120013528}
13529
Karl Schultz6addd812016-02-02 17:17:23 -070013530TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013531 TEST_DESCRIPTION(
13532 "Test that an error is produced for mismatched types across "
13533 "the vertex->fragment shader interface, when the variable is contained within "
13534 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013536
13537 ASSERT_NO_FATAL_FAILURE(InitState());
13538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13539
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013540 char const *vsSource =
13541 "#version 450\n"
13542 "\n"
13543 "out block { layout(location=0) int x; } outs;\n"
13544 "out gl_PerVertex {\n"
13545 " vec4 gl_Position;\n"
13546 "};\n"
13547 "void main(){\n"
13548 " outs.x = 0;\n"
13549 " gl_Position = vec4(1);\n"
13550 "}\n";
13551 char const *fsSource =
13552 "#version 450\n"
13553 "\n"
13554 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
13555 "layout(location=0) out vec4 color;\n"
13556 "void main(){\n"
13557 " color = vec4(ins.x);\n"
13558 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013559
13560 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13561 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13562
13563 VkPipelineObj pipe(m_device);
13564 pipe.AddColorAttachment();
13565 pipe.AddShader(&vs);
13566 pipe.AddShader(&fs);
13567
13568 VkDescriptorSetObj descriptorSet(m_device);
13569 descriptorSet.AppendDummy();
13570 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13571
13572 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13573
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013574 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013575}
13576
13577TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013578 TEST_DESCRIPTION(
13579 "Test that an error is produced for location mismatches across "
13580 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
13581 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013582 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 +130013583
13584 ASSERT_NO_FATAL_FAILURE(InitState());
13585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13586
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013587 char const *vsSource =
13588 "#version 450\n"
13589 "\n"
13590 "out block { layout(location=1) float x; } outs;\n"
13591 "out gl_PerVertex {\n"
13592 " vec4 gl_Position;\n"
13593 "};\n"
13594 "void main(){\n"
13595 " outs.x = 0;\n"
13596 " gl_Position = vec4(1);\n"
13597 "}\n";
13598 char const *fsSource =
13599 "#version 450\n"
13600 "\n"
13601 "in block { layout(location=0) float x; } ins;\n"
13602 "layout(location=0) out vec4 color;\n"
13603 "void main(){\n"
13604 " color = vec4(ins.x);\n"
13605 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013606
13607 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13608 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13609
13610 VkPipelineObj pipe(m_device);
13611 pipe.AddColorAttachment();
13612 pipe.AddShader(&vs);
13613 pipe.AddShader(&fs);
13614
13615 VkDescriptorSetObj descriptorSet(m_device);
13616 descriptorSet.AppendDummy();
13617 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13618
13619 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13620
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013621 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130013622}
13623
13624TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013625 TEST_DESCRIPTION(
13626 "Test that an error is produced for component mismatches across the "
13627 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
13628 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013629 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 +130013630
13631 ASSERT_NO_FATAL_FAILURE(InitState());
13632 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13633
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013634 char const *vsSource =
13635 "#version 450\n"
13636 "\n"
13637 "out block { layout(location=0, component=0) float x; } outs;\n"
13638 "out gl_PerVertex {\n"
13639 " vec4 gl_Position;\n"
13640 "};\n"
13641 "void main(){\n"
13642 " outs.x = 0;\n"
13643 " gl_Position = vec4(1);\n"
13644 "}\n";
13645 char const *fsSource =
13646 "#version 450\n"
13647 "\n"
13648 "in block { layout(location=0, component=1) float x; } ins;\n"
13649 "layout(location=0) out vec4 color;\n"
13650 "void main(){\n"
13651 " color = vec4(ins.x);\n"
13652 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130013653
13654 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13655 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13656
13657 VkPipelineObj pipe(m_device);
13658 pipe.AddColorAttachment();
13659 pipe.AddShader(&vs);
13660 pipe.AddShader(&fs);
13661
13662 VkDescriptorSetObj descriptorSet(m_device);
13663 descriptorSet.AppendDummy();
13664 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13665
13666 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13667
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013668 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013669}
13670
Chris Forbes1f3b0152016-11-30 12:48:40 +130013671TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
13672 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13673
13674 ASSERT_NO_FATAL_FAILURE(InitState());
13675 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13676
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013677 char const *vsSource =
13678 "#version 450\n"
13679 "layout(location=0) out mediump float x;\n"
13680 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13681 char const *fsSource =
13682 "#version 450\n"
13683 "layout(location=0) in highp float x;\n"
13684 "layout(location=0) out vec4 color;\n"
13685 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130013686
13687 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13688 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13689
13690 VkPipelineObj pipe(m_device);
13691 pipe.AddColorAttachment();
13692 pipe.AddShader(&vs);
13693 pipe.AddShader(&fs);
13694
13695 VkDescriptorSetObj descriptorSet(m_device);
13696 descriptorSet.AppendDummy();
13697 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13698
13699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13700
13701 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13702
13703 m_errorMonitor->VerifyFound();
13704}
13705
Chris Forbes870a39e2016-11-30 12:55:56 +130013706TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
13707 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
13708
13709 ASSERT_NO_FATAL_FAILURE(InitState());
13710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13711
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013712 char const *vsSource =
13713 "#version 450\n"
13714 "out block { layout(location=0) mediump float x; };\n"
13715 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
13716 char const *fsSource =
13717 "#version 450\n"
13718 "in block { layout(location=0) highp float x; };\n"
13719 "layout(location=0) out vec4 color;\n"
13720 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130013721
13722 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13723 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13724
13725 VkPipelineObj pipe(m_device);
13726 pipe.AddColorAttachment();
13727 pipe.AddShader(&vs);
13728 pipe.AddShader(&fs);
13729
13730 VkDescriptorSetObj descriptorSet(m_device);
13731 descriptorSet.AppendDummy();
13732 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13733
13734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
13735
13736 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13737
13738 m_errorMonitor->VerifyFound();
13739}
13740
Karl Schultz6addd812016-02-02 17:17:23 -070013741TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013742 TEST_DESCRIPTION(
13743 "Test that a warning is produced for a vertex attribute which is "
13744 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013746
Chris Forbesde136e02015-05-25 11:13:28 +120013747 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120013749
13750 VkVertexInputBindingDescription input_binding;
13751 memset(&input_binding, 0, sizeof(input_binding));
13752
13753 VkVertexInputAttributeDescription input_attrib;
13754 memset(&input_attrib, 0, sizeof(input_attrib));
13755 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13756
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013757 char const *vsSource =
13758 "#version 450\n"
13759 "\n"
13760 "out gl_PerVertex {\n"
13761 " vec4 gl_Position;\n"
13762 "};\n"
13763 "void main(){\n"
13764 " gl_Position = vec4(1);\n"
13765 "}\n";
13766 char const *fsSource =
13767 "#version 450\n"
13768 "\n"
13769 "layout(location=0) out vec4 color;\n"
13770 "void main(){\n"
13771 " color = vec4(1);\n"
13772 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120013773
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013774 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13775 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120013776
13777 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013778 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120013779 pipe.AddShader(&vs);
13780 pipe.AddShader(&fs);
13781
13782 pipe.AddVertexInputBindings(&input_binding, 1);
13783 pipe.AddVertexInputAttribs(&input_attrib, 1);
13784
Chris Forbesde136e02015-05-25 11:13:28 +120013785 VkDescriptorSetObj descriptorSet(m_device);
13786 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013787 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120013788
Tony Barbour5781e8f2015-08-04 16:23:11 -060013789 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120013790
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013791 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120013792}
13793
Karl Schultz6addd812016-02-02 17:17:23 -070013794TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013795 TEST_DESCRIPTION(
13796 "Test that a warning is produced for a location mismatch on "
13797 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060013798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130013799
13800 ASSERT_NO_FATAL_FAILURE(InitState());
13801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13802
13803 VkVertexInputBindingDescription input_binding;
13804 memset(&input_binding, 0, sizeof(input_binding));
13805
13806 VkVertexInputAttributeDescription input_attrib;
13807 memset(&input_attrib, 0, sizeof(input_attrib));
13808 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13809
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013810 char const *vsSource =
13811 "#version 450\n"
13812 "\n"
13813 "layout(location=1) in float x;\n"
13814 "out gl_PerVertex {\n"
13815 " vec4 gl_Position;\n"
13816 "};\n"
13817 "void main(){\n"
13818 " gl_Position = vec4(x);\n"
13819 "}\n";
13820 char const *fsSource =
13821 "#version 450\n"
13822 "\n"
13823 "layout(location=0) out vec4 color;\n"
13824 "void main(){\n"
13825 " color = vec4(1);\n"
13826 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130013827
13828 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13829 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13830
13831 VkPipelineObj pipe(m_device);
13832 pipe.AddColorAttachment();
13833 pipe.AddShader(&vs);
13834 pipe.AddShader(&fs);
13835
13836 pipe.AddVertexInputBindings(&input_binding, 1);
13837 pipe.AddVertexInputAttribs(&input_attrib, 1);
13838
13839 VkDescriptorSetObj descriptorSet(m_device);
13840 descriptorSet.AppendDummy();
13841 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13842
13843 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13844
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013845 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130013846}
13847
Karl Schultz6addd812016-02-02 17:17:23 -070013848TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013849 TEST_DESCRIPTION(
13850 "Test that an error is produced for a vertex shader input which is not "
13851 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13853 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013854
Chris Forbes62e8e502015-05-25 11:13:29 +120013855 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120013857
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013858 char const *vsSource =
13859 "#version 450\n"
13860 "\n"
13861 "layout(location=0) in vec4 x;\n" /* not provided */
13862 "out gl_PerVertex {\n"
13863 " vec4 gl_Position;\n"
13864 "};\n"
13865 "void main(){\n"
13866 " gl_Position = x;\n"
13867 "}\n";
13868 char const *fsSource =
13869 "#version 450\n"
13870 "\n"
13871 "layout(location=0) out vec4 color;\n"
13872 "void main(){\n"
13873 " color = vec4(1);\n"
13874 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120013875
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013876 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13877 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120013878
13879 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013880 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120013881 pipe.AddShader(&vs);
13882 pipe.AddShader(&fs);
13883
Chris Forbes62e8e502015-05-25 11:13:29 +120013884 VkDescriptorSetObj descriptorSet(m_device);
13885 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013886 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120013887
Tony Barbour5781e8f2015-08-04 16:23:11 -060013888 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120013889
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013890 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120013891}
13892
Karl Schultz6addd812016-02-02 17:17:23 -070013893TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013894 TEST_DESCRIPTION(
13895 "Test that an error is produced for a mismatch between the "
13896 "fundamental type (float/int/uint) of an attribute and the "
13897 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060013898 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 -060013899
Chris Forbesc97d98e2015-05-25 11:13:31 +120013900 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013902
13903 VkVertexInputBindingDescription input_binding;
13904 memset(&input_binding, 0, sizeof(input_binding));
13905
13906 VkVertexInputAttributeDescription input_attrib;
13907 memset(&input_attrib, 0, sizeof(input_attrib));
13908 input_attrib.format = VK_FORMAT_R32_SFLOAT;
13909
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013910 char const *vsSource =
13911 "#version 450\n"
13912 "\n"
13913 "layout(location=0) in int x;\n" /* attrib provided float */
13914 "out gl_PerVertex {\n"
13915 " vec4 gl_Position;\n"
13916 "};\n"
13917 "void main(){\n"
13918 " gl_Position = vec4(x);\n"
13919 "}\n";
13920 char const *fsSource =
13921 "#version 450\n"
13922 "\n"
13923 "layout(location=0) out vec4 color;\n"
13924 "void main(){\n"
13925 " color = vec4(1);\n"
13926 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120013927
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013928 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13929 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013930
13931 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013932 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013933 pipe.AddShader(&vs);
13934 pipe.AddShader(&fs);
13935
13936 pipe.AddVertexInputBindings(&input_binding, 1);
13937 pipe.AddVertexInputAttribs(&input_attrib, 1);
13938
Chris Forbesc97d98e2015-05-25 11:13:31 +120013939 VkDescriptorSetObj descriptorSet(m_device);
13940 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013941 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120013942
Tony Barbour5781e8f2015-08-04 16:23:11 -060013943 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120013944
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013945 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120013946}
13947
Chris Forbesc68b43c2016-04-06 11:18:47 +120013948TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013949 TEST_DESCRIPTION(
13950 "Test that an error is produced for a pipeline containing multiple "
13951 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13953 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120013954
13955 ASSERT_NO_FATAL_FAILURE(InitState());
13956 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13957
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013958 char const *vsSource =
13959 "#version 450\n"
13960 "\n"
13961 "out gl_PerVertex {\n"
13962 " vec4 gl_Position;\n"
13963 "};\n"
13964 "void main(){\n"
13965 " gl_Position = vec4(1);\n"
13966 "}\n";
13967 char const *fsSource =
13968 "#version 450\n"
13969 "\n"
13970 "layout(location=0) out vec4 color;\n"
13971 "void main(){\n"
13972 " color = vec4(1);\n"
13973 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120013974
13975 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13976 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13977
13978 VkPipelineObj pipe(m_device);
13979 pipe.AddColorAttachment();
13980 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013981 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120013982 pipe.AddShader(&fs);
13983
13984 VkDescriptorSetObj descriptorSet(m_device);
13985 descriptorSet.AppendDummy();
13986 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13987
13988 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13989
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013990 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120013991}
13992
Chris Forbes82ff92a2016-09-09 10:50:24 +120013993TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120013995
13996 ASSERT_NO_FATAL_FAILURE(InitState());
13997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13998
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013999 char const *vsSource =
14000 "#version 450\n"
14001 "out gl_PerVertex {\n"
14002 " vec4 gl_Position;\n"
14003 "};\n"
14004 "void main(){\n"
14005 " gl_Position = vec4(0);\n"
14006 "}\n";
14007 char const *fsSource =
14008 "#version 450\n"
14009 "\n"
14010 "layout(location=0) out vec4 color;\n"
14011 "void main(){\n"
14012 " color = vec4(1);\n"
14013 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014014
14015 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14016 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14017
14018 VkPipelineObj pipe(m_device);
14019 pipe.AddColorAttachment();
14020 pipe.AddShader(&vs);
14021 pipe.AddShader(&fs);
14022
14023 VkDescriptorSetObj descriptorSet(m_device);
14024 descriptorSet.AppendDummy();
14025 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14026
14027 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14028
14029 m_errorMonitor->VerifyFound();
14030}
14031
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014032TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14034 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14035 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014036
14037 ASSERT_NO_FATAL_FAILURE(InitState());
14038 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14039
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014040 char const *vsSource =
14041 "#version 450\n"
14042 "void main(){ gl_Position = vec4(0); }\n";
14043 char const *fsSource =
14044 "#version 450\n"
14045 "\n"
14046 "layout(location=0) out vec4 color;\n"
14047 "void main(){\n"
14048 " color = vec4(1);\n"
14049 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014050
14051 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14052 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14053
14054 VkPipelineObj pipe(m_device);
14055 pipe.AddColorAttachment();
14056 pipe.AddShader(&vs);
14057 pipe.AddShader(&fs);
14058
14059 VkDescriptorSetObj descriptorSet(m_device);
14060 descriptorSet.AppendDummy();
14061 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14062
14063 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014064 {
14065 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14066 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14067 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014068 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014069 {
14070 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14071 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14072 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014073 },
14074 };
14075 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014076 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014077 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014078 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14079 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014080 VkRenderPass rp;
14081 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14082 ASSERT_VK_SUCCESS(err);
14083
14084 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14085
14086 m_errorMonitor->VerifyFound();
14087
14088 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14089}
14090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014091TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014092 TEST_DESCRIPTION(
14093 "Test that an error is produced for a variable output from "
14094 "the TCS without the patch decoration, but consumed in the TES "
14095 "with the decoration.");
14096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14097 "is per-vertex in tessellation control shader stage "
14098 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014099
14100 ASSERT_NO_FATAL_FAILURE(InitState());
14101 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14102
Chris Forbesc1e852d2016-04-04 19:26:42 +120014103 if (!m_device->phy().features().tessellationShader) {
14104 printf("Device does not support tessellation shaders; skipped.\n");
14105 return;
14106 }
14107
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014108 char const *vsSource =
14109 "#version 450\n"
14110 "void main(){}\n";
14111 char const *tcsSource =
14112 "#version 450\n"
14113 "layout(location=0) out int x[];\n"
14114 "layout(vertices=3) out;\n"
14115 "void main(){\n"
14116 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14117 " gl_TessLevelInner[0] = 1;\n"
14118 " x[gl_InvocationID] = gl_InvocationID;\n"
14119 "}\n";
14120 char const *tesSource =
14121 "#version 450\n"
14122 "layout(triangles, equal_spacing, cw) in;\n"
14123 "layout(location=0) patch in int x;\n"
14124 "out gl_PerVertex { vec4 gl_Position; };\n"
14125 "void main(){\n"
14126 " gl_Position.xyz = gl_TessCoord;\n"
14127 " gl_Position.w = x;\n"
14128 "}\n";
14129 char const *fsSource =
14130 "#version 450\n"
14131 "layout(location=0) out vec4 color;\n"
14132 "void main(){\n"
14133 " color = vec4(1);\n"
14134 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014135
14136 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14137 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14138 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14139 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14140
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014141 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14142 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014144 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014145
14146 VkPipelineObj pipe(m_device);
14147 pipe.SetInputAssembly(&iasci);
14148 pipe.SetTessellation(&tsci);
14149 pipe.AddColorAttachment();
14150 pipe.AddShader(&vs);
14151 pipe.AddShader(&tcs);
14152 pipe.AddShader(&tes);
14153 pipe.AddShader(&fs);
14154
14155 VkDescriptorSetObj descriptorSet(m_device);
14156 descriptorSet.AppendDummy();
14157 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14158
14159 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14160
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014161 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014162}
14163
Karl Schultz6addd812016-02-02 17:17:23 -070014164TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014165 TEST_DESCRIPTION(
14166 "Test that an error is produced for a vertex attribute setup where multiple "
14167 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14169 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014170
Chris Forbes280ba2c2015-06-12 11:16:41 +120014171 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014173
14174 /* Two binding descriptions for binding 0 */
14175 VkVertexInputBindingDescription input_bindings[2];
14176 memset(input_bindings, 0, sizeof(input_bindings));
14177
14178 VkVertexInputAttributeDescription input_attrib;
14179 memset(&input_attrib, 0, sizeof(input_attrib));
14180 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14181
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014182 char const *vsSource =
14183 "#version 450\n"
14184 "\n"
14185 "layout(location=0) in float x;\n" /* attrib provided float */
14186 "out gl_PerVertex {\n"
14187 " vec4 gl_Position;\n"
14188 "};\n"
14189 "void main(){\n"
14190 " gl_Position = vec4(x);\n"
14191 "}\n";
14192 char const *fsSource =
14193 "#version 450\n"
14194 "\n"
14195 "layout(location=0) out vec4 color;\n"
14196 "void main(){\n"
14197 " color = vec4(1);\n"
14198 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014199
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014202
14203 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014204 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014205 pipe.AddShader(&vs);
14206 pipe.AddShader(&fs);
14207
14208 pipe.AddVertexInputBindings(input_bindings, 2);
14209 pipe.AddVertexInputAttribs(&input_attrib, 1);
14210
Chris Forbes280ba2c2015-06-12 11:16:41 +120014211 VkDescriptorSetObj descriptorSet(m_device);
14212 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014213 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014214
Tony Barbour5781e8f2015-08-04 16:23:11 -060014215 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014216
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014217 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014218}
Chris Forbes8f68b562015-05-25 11:13:32 +120014219
Karl Schultz6addd812016-02-02 17:17:23 -070014220TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014221 TEST_DESCRIPTION(
14222 "Test that an error is produced for a fragment shader which does not "
14223 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014225
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014226 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014227
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014228 char const *vsSource =
14229 "#version 450\n"
14230 "\n"
14231 "out gl_PerVertex {\n"
14232 " vec4 gl_Position;\n"
14233 "};\n"
14234 "void main(){\n"
14235 " gl_Position = vec4(1);\n"
14236 "}\n";
14237 char const *fsSource =
14238 "#version 450\n"
14239 "\n"
14240 "void main(){\n"
14241 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014242
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014243 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14244 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014245
14246 VkPipelineObj pipe(m_device);
14247 pipe.AddShader(&vs);
14248 pipe.AddShader(&fs);
14249
Chia-I Wu08accc62015-07-07 11:50:03 +080014250 /* set up CB 0, not written */
14251 pipe.AddColorAttachment();
14252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014253
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014254 VkDescriptorSetObj descriptorSet(m_device);
14255 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014256 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014257
Tony Barbour5781e8f2015-08-04 16:23:11 -060014258 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014259
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014260 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014261}
14262
Karl Schultz6addd812016-02-02 17:17:23 -070014263TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014264 TEST_DESCRIPTION(
14265 "Test that a warning is produced for a fragment shader which provides a spurious "
14266 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014268 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014269
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014270 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014271
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014272 char const *vsSource =
14273 "#version 450\n"
14274 "\n"
14275 "out gl_PerVertex {\n"
14276 " vec4 gl_Position;\n"
14277 "};\n"
14278 "void main(){\n"
14279 " gl_Position = vec4(1);\n"
14280 "}\n";
14281 char const *fsSource =
14282 "#version 450\n"
14283 "\n"
14284 "layout(location=0) out vec4 x;\n"
14285 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14286 "void main(){\n"
14287 " x = vec4(1);\n"
14288 " y = vec4(1);\n"
14289 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014290
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014291 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14292 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014293
14294 VkPipelineObj pipe(m_device);
14295 pipe.AddShader(&vs);
14296 pipe.AddShader(&fs);
14297
Chia-I Wu08accc62015-07-07 11:50:03 +080014298 /* set up CB 0, not written */
14299 pipe.AddColorAttachment();
14300 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014301 /* FS writes CB 1, but we don't configure it */
14302
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014303 VkDescriptorSetObj descriptorSet(m_device);
14304 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014305 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014306
Tony Barbour5781e8f2015-08-04 16:23:11 -060014307 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014308
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014309 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014310}
14311
Karl Schultz6addd812016-02-02 17:17:23 -070014312TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014313 TEST_DESCRIPTION(
14314 "Test that an error is produced for a mismatch between the fundamental "
14315 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014317
Chris Forbesa36d69e2015-05-25 11:13:44 +120014318 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014319
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014320 char const *vsSource =
14321 "#version 450\n"
14322 "\n"
14323 "out gl_PerVertex {\n"
14324 " vec4 gl_Position;\n"
14325 "};\n"
14326 "void main(){\n"
14327 " gl_Position = vec4(1);\n"
14328 "}\n";
14329 char const *fsSource =
14330 "#version 450\n"
14331 "\n"
14332 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14333 "void main(){\n"
14334 " x = ivec4(1);\n"
14335 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014336
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014337 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14338 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014339
14340 VkPipelineObj pipe(m_device);
14341 pipe.AddShader(&vs);
14342 pipe.AddShader(&fs);
14343
Chia-I Wu08accc62015-07-07 11:50:03 +080014344 /* set up CB 0; type is UNORM by default */
14345 pipe.AddColorAttachment();
14346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014347
Chris Forbesa36d69e2015-05-25 11:13:44 +120014348 VkDescriptorSetObj descriptorSet(m_device);
14349 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014350 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014351
Tony Barbour5781e8f2015-08-04 16:23:11 -060014352 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014353
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014354 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014355}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014356
Karl Schultz6addd812016-02-02 17:17:23 -070014357TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014358 TEST_DESCRIPTION(
14359 "Test that an error is produced for a shader consuming a uniform "
14360 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014362
Chris Forbes556c76c2015-08-14 12:04:59 +120014363 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014364
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014365 char const *vsSource =
14366 "#version 450\n"
14367 "\n"
14368 "out gl_PerVertex {\n"
14369 " vec4 gl_Position;\n"
14370 "};\n"
14371 "void main(){\n"
14372 " gl_Position = vec4(1);\n"
14373 "}\n";
14374 char const *fsSource =
14375 "#version 450\n"
14376 "\n"
14377 "layout(location=0) out vec4 x;\n"
14378 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14379 "void main(){\n"
14380 " x = vec4(bar.y);\n"
14381 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014382
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014383 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14384 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014385
Chris Forbes556c76c2015-08-14 12:04:59 +120014386 VkPipelineObj pipe(m_device);
14387 pipe.AddShader(&vs);
14388 pipe.AddShader(&fs);
14389
14390 /* set up CB 0; type is UNORM by default */
14391 pipe.AddColorAttachment();
14392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14393
14394 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014395 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014396
14397 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14398
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014399 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014400}
14401
Chris Forbes5c59e902016-02-26 16:56:09 +130014402TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014403 TEST_DESCRIPTION(
14404 "Test that an error is produced for a shader consuming push constants "
14405 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014407
14408 ASSERT_NO_FATAL_FAILURE(InitState());
14409
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014410 char const *vsSource =
14411 "#version 450\n"
14412 "\n"
14413 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14414 "out gl_PerVertex {\n"
14415 " vec4 gl_Position;\n"
14416 "};\n"
14417 "void main(){\n"
14418 " gl_Position = vec4(consts.x);\n"
14419 "}\n";
14420 char const *fsSource =
14421 "#version 450\n"
14422 "\n"
14423 "layout(location=0) out vec4 x;\n"
14424 "void main(){\n"
14425 " x = vec4(1);\n"
14426 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014427
14428 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14429 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14430
14431 VkPipelineObj pipe(m_device);
14432 pipe.AddShader(&vs);
14433 pipe.AddShader(&fs);
14434
14435 /* set up CB 0; type is UNORM by default */
14436 pipe.AddColorAttachment();
14437 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14438
14439 VkDescriptorSetObj descriptorSet(m_device);
14440 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14441
14442 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14443
14444 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014445 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014446}
14447
Chris Forbes3fb17902016-08-22 14:57:55 +120014448TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014449 TEST_DESCRIPTION(
14450 "Test that an error is produced for a shader consuming an input attachment "
14451 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014452 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14453 "consumes input attachment index 0 but not provided in subpass");
14454
14455 ASSERT_NO_FATAL_FAILURE(InitState());
14456
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014457 char const *vsSource =
14458 "#version 450\n"
14459 "\n"
14460 "out gl_PerVertex {\n"
14461 " vec4 gl_Position;\n"
14462 "};\n"
14463 "void main(){\n"
14464 " gl_Position = vec4(1);\n"
14465 "}\n";
14466 char const *fsSource =
14467 "#version 450\n"
14468 "\n"
14469 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14470 "layout(location=0) out vec4 color;\n"
14471 "void main() {\n"
14472 " color = subpassLoad(x);\n"
14473 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014474
14475 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14476 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14477
14478 VkPipelineObj pipe(m_device);
14479 pipe.AddShader(&vs);
14480 pipe.AddShader(&fs);
14481 pipe.AddColorAttachment();
14482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14483
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014484 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14485 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120014486 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014487 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014488 ASSERT_VK_SUCCESS(err);
14489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014490 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120014491 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014492 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120014493 ASSERT_VK_SUCCESS(err);
14494
14495 // error here.
14496 pipe.CreateVKPipeline(pl, renderPass());
14497
14498 m_errorMonitor->VerifyFound();
14499
14500 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14501 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14502}
14503
Chris Forbes5a9a0472016-08-22 16:02:09 +120014504TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014505 TEST_DESCRIPTION(
14506 "Test that an error is produced for a shader consuming an input attachment "
14507 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120014508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14509 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
14510
14511 ASSERT_NO_FATAL_FAILURE(InitState());
14512
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014513 char const *vsSource =
14514 "#version 450\n"
14515 "\n"
14516 "out gl_PerVertex {\n"
14517 " vec4 gl_Position;\n"
14518 "};\n"
14519 "void main(){\n"
14520 " gl_Position = vec4(1);\n"
14521 "}\n";
14522 char const *fsSource =
14523 "#version 450\n"
14524 "\n"
14525 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14526 "layout(location=0) out vec4 color;\n"
14527 "void main() {\n"
14528 " color = subpassLoad(x);\n"
14529 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120014530
14531 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14532 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14533
14534 VkPipelineObj pipe(m_device);
14535 pipe.AddShader(&vs);
14536 pipe.AddShader(&fs);
14537 pipe.AddColorAttachment();
14538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14539
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014540 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14541 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014542 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014543 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014544 ASSERT_VK_SUCCESS(err);
14545
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014546 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014547 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014548 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120014549 ASSERT_VK_SUCCESS(err);
14550
14551 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014552 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14553 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14554 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
14555 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
14556 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 +120014557 };
14558 VkAttachmentReference color = {
14559 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
14560 };
14561 VkAttachmentReference input = {
14562 1, VK_IMAGE_LAYOUT_GENERAL,
14563 };
14564
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014565 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014566
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014567 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120014568 VkRenderPass rp;
14569 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14570 ASSERT_VK_SUCCESS(err);
14571
14572 // error here.
14573 pipe.CreateVKPipeline(pl, rp);
14574
14575 m_errorMonitor->VerifyFound();
14576
14577 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14578 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14579 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14580}
14581
Chris Forbes541f7b02016-08-22 15:30:27 +120014582TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014583 TEST_DESCRIPTION(
14584 "Test that an error is produced for a shader consuming an input attachment "
14585 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120014586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070014587 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120014588
14589 ASSERT_NO_FATAL_FAILURE(InitState());
14590
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014591 char const *vsSource =
14592 "#version 450\n"
14593 "\n"
14594 "out gl_PerVertex {\n"
14595 " vec4 gl_Position;\n"
14596 "};\n"
14597 "void main(){\n"
14598 " gl_Position = vec4(1);\n"
14599 "}\n";
14600 char const *fsSource =
14601 "#version 450\n"
14602 "\n"
14603 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
14604 "layout(location=0) out vec4 color;\n"
14605 "void main() {\n"
14606 " color = subpassLoad(xs[0]);\n"
14607 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120014608
14609 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14610 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14611
14612 VkPipelineObj pipe(m_device);
14613 pipe.AddShader(&vs);
14614 pipe.AddShader(&fs);
14615 pipe.AddColorAttachment();
14616 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14617
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014618 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14619 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120014620 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014621 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014622 ASSERT_VK_SUCCESS(err);
14623
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014624 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120014625 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014626 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120014627 ASSERT_VK_SUCCESS(err);
14628
14629 // error here.
14630 pipe.CreateVKPipeline(pl, renderPass());
14631
14632 m_errorMonitor->VerifyFound();
14633
14634 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14635 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14636}
14637
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014638TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014639 TEST_DESCRIPTION(
14640 "Test that an error is produced for a compute pipeline consuming a "
14641 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014643
14644 ASSERT_NO_FATAL_FAILURE(InitState());
14645
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014646 char const *csSource =
14647 "#version 450\n"
14648 "\n"
14649 "layout(local_size_x=1) in;\n"
14650 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14651 "void main(){\n"
14652 " x = vec4(1);\n"
14653 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014654
14655 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14656
14657 VkDescriptorSetObj descriptorSet(m_device);
14658 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014660 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14661 nullptr,
14662 0,
14663 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14664 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14665 descriptorSet.GetPipelineLayout(),
14666 VK_NULL_HANDLE,
14667 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014668
14669 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014670 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120014671
14672 m_errorMonitor->VerifyFound();
14673
14674 if (err == VK_SUCCESS) {
14675 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14676 }
14677}
14678
Chris Forbes22a9b092016-07-19 14:34:05 +120014679TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014680 TEST_DESCRIPTION(
14681 "Test that an error is produced for a pipeline consuming a "
14682 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14684 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120014685
14686 ASSERT_NO_FATAL_FAILURE(InitState());
14687
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014688 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
14689 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120014690 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014691 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014692 ASSERT_VK_SUCCESS(err);
14693
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014694 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120014695 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014696 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120014697 ASSERT_VK_SUCCESS(err);
14698
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014699 char const *csSource =
14700 "#version 450\n"
14701 "\n"
14702 "layout(local_size_x=1) in;\n"
14703 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
14704 "void main() {\n"
14705 " x.x = 1.0f;\n"
14706 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120014707 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
14708
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014709 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
14710 nullptr,
14711 0,
14712 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
14713 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
14714 pl,
14715 VK_NULL_HANDLE,
14716 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120014717
14718 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014719 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120014720
14721 m_errorMonitor->VerifyFound();
14722
14723 if (err == VK_SUCCESS) {
14724 vkDestroyPipeline(m_device->device(), pipe, nullptr);
14725 }
14726
14727 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
14728 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
14729}
14730
Chris Forbes50020592016-07-27 13:52:41 +120014731TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014732 TEST_DESCRIPTION(
14733 "Test that an error is produced when an image view type "
14734 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120014735
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014736 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 +120014737
14738 ASSERT_NO_FATAL_FAILURE(InitState());
14739 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14740
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014741 char const *vsSource =
14742 "#version 450\n"
14743 "\n"
14744 "out gl_PerVertex { vec4 gl_Position; };\n"
14745 "void main() { gl_Position = vec4(0); }\n";
14746 char const *fsSource =
14747 "#version 450\n"
14748 "\n"
14749 "layout(set=0, binding=0) uniform sampler3D s;\n"
14750 "layout(location=0) out vec4 color;\n"
14751 "void main() {\n"
14752 " color = texture(s, vec3(0));\n"
14753 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120014754 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14755 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14756
14757 VkPipelineObj pipe(m_device);
14758 pipe.AddShader(&vs);
14759 pipe.AddShader(&fs);
14760 pipe.AddColorAttachment();
14761
14762 VkTextureObj texture(m_device, nullptr);
14763 VkSamplerObj sampler(m_device);
14764
14765 VkDescriptorSetObj descriptorSet(m_device);
14766 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14767 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14768
14769 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14770 ASSERT_VK_SUCCESS(err);
14771
Tony Barbour552f6c02016-12-21 14:34:07 -070014772 m_commandBuffer->BeginCommandBuffer();
14773 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120014774
14775 m_commandBuffer->BindPipeline(pipe);
14776 m_commandBuffer->BindDescriptorSet(descriptorSet);
14777
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014778 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120014779 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014780 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120014781 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14782
14783 // error produced here.
14784 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14785
14786 m_errorMonitor->VerifyFound();
14787
Tony Barbour552f6c02016-12-21 14:34:07 -070014788 m_commandBuffer->EndRenderPass();
14789 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120014790}
14791
Chris Forbes5533bfc2016-07-27 14:12:34 +120014792TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014793 TEST_DESCRIPTION(
14794 "Test that an error is produced when a multisampled images "
14795 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014796
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120014798
14799 ASSERT_NO_FATAL_FAILURE(InitState());
14800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14801
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014802 char const *vsSource =
14803 "#version 450\n"
14804 "\n"
14805 "out gl_PerVertex { vec4 gl_Position; };\n"
14806 "void main() { gl_Position = vec4(0); }\n";
14807 char const *fsSource =
14808 "#version 450\n"
14809 "\n"
14810 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
14811 "layout(location=0) out vec4 color;\n"
14812 "void main() {\n"
14813 " color = texelFetch(s, ivec2(0), 0);\n"
14814 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120014815 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14816 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14817
14818 VkPipelineObj pipe(m_device);
14819 pipe.AddShader(&vs);
14820 pipe.AddShader(&fs);
14821 pipe.AddColorAttachment();
14822
14823 VkTextureObj texture(m_device, nullptr);
14824 VkSamplerObj sampler(m_device);
14825
14826 VkDescriptorSetObj descriptorSet(m_device);
14827 descriptorSet.AppendSamplerTexture(&sampler, &texture);
14828 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14829
14830 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14831 ASSERT_VK_SUCCESS(err);
14832
Tony Barbour552f6c02016-12-21 14:34:07 -070014833 m_commandBuffer->BeginCommandBuffer();
14834 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120014835
14836 m_commandBuffer->BindPipeline(pipe);
14837 m_commandBuffer->BindDescriptorSet(descriptorSet);
14838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014839 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014840 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014841 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120014842 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
14843
14844 // error produced here.
14845 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
14846
14847 m_errorMonitor->VerifyFound();
14848
Tony Barbour552f6c02016-12-21 14:34:07 -070014849 m_commandBuffer->EndRenderPass();
14850 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120014851}
14852
Mark Youngc48c4c12016-04-11 14:26:49 -060014853TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014855
14856 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014857
14858 // Create an image
14859 VkImage image;
14860
Karl Schultz6addd812016-02-02 17:17:23 -070014861 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14862 const int32_t tex_width = 32;
14863 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014864
14865 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014866 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14867 image_create_info.pNext = NULL;
14868 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14869 image_create_info.format = tex_format;
14870 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014871 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070014872 image_create_info.extent.depth = 1;
14873 image_create_info.mipLevels = 1;
14874 image_create_info.arrayLayers = 1;
14875 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14876 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14877 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14878 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014879
14880 // Introduce error by sending down a bogus width extent
14881 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080014882 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014883
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014884 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060014885}
14886
Mark Youngc48c4c12016-04-11 14:26:49 -060014887TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070014888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060014889
14890 ASSERT_NO_FATAL_FAILURE(InitState());
14891
14892 // Create an image
14893 VkImage image;
14894
14895 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14896 const int32_t tex_width = 32;
14897 const int32_t tex_height = 32;
14898
14899 VkImageCreateInfo image_create_info = {};
14900 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14901 image_create_info.pNext = NULL;
14902 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14903 image_create_info.format = tex_format;
14904 image_create_info.extent.width = tex_width;
14905 image_create_info.extent.height = tex_height;
14906 image_create_info.extent.depth = 1;
14907 image_create_info.mipLevels = 1;
14908 image_create_info.arrayLayers = 1;
14909 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14910 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14911 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14912 image_create_info.flags = 0;
14913
14914 // Introduce error by sending down a bogus width extent
14915 image_create_info.extent.width = 0;
14916 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
14917
14918 m_errorMonitor->VerifyFound();
14919}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070014920
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014921TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014922 TEST_DESCRIPTION(
14923 "Create a render pass with an attachment description "
14924 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014925
14926 ASSERT_NO_FATAL_FAILURE(InitState());
14927 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14928
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014929 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060014930
14931 VkAttachmentReference color_attach = {};
14932 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
14933 color_attach.attachment = 0;
14934 VkSubpassDescription subpass = {};
14935 subpass.colorAttachmentCount = 1;
14936 subpass.pColorAttachments = &color_attach;
14937
14938 VkRenderPassCreateInfo rpci = {};
14939 rpci.subpassCount = 1;
14940 rpci.pSubpasses = &subpass;
14941 rpci.attachmentCount = 1;
14942 VkAttachmentDescription attach_desc = {};
14943 attach_desc.format = VK_FORMAT_UNDEFINED;
14944 rpci.pAttachments = &attach_desc;
14945 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
14946 VkRenderPass rp;
14947 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
14948
14949 m_errorMonitor->VerifyFound();
14950
14951 if (result == VK_SUCCESS) {
14952 vkDestroyRenderPass(m_device->device(), rp, NULL);
14953 }
14954}
14955
Karl Schultz6addd812016-02-02 17:17:23 -070014956TEST_F(VkLayerTest, InvalidImageView) {
14957 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060014958
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070014959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014960
Tobin Ehliscde08892015-09-22 10:11:37 -060014961 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060014962
Mike Stroyana3082432015-09-25 13:39:21 -060014963 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070014964 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060014965
Karl Schultz6addd812016-02-02 17:17:23 -070014966 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
14967 const int32_t tex_width = 32;
14968 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060014969
14970 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070014971 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
14972 image_create_info.pNext = NULL;
14973 image_create_info.imageType = VK_IMAGE_TYPE_2D;
14974 image_create_info.format = tex_format;
14975 image_create_info.extent.width = tex_width;
14976 image_create_info.extent.height = tex_height;
14977 image_create_info.extent.depth = 1;
14978 image_create_info.mipLevels = 1;
14979 image_create_info.arrayLayers = 1;
14980 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
14981 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
14982 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
14983 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060014984
Chia-I Wuf7458c52015-10-26 21:10:41 +080014985 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060014986 ASSERT_VK_SUCCESS(err);
14987
14988 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130014989 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070014990 image_view_create_info.image = image;
14991 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
14992 image_view_create_info.format = tex_format;
14993 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014994 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070014995 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014996 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060014997
14998 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014999 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015000
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015001 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015002 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015003}
Mike Stroyana3082432015-09-25 13:39:21 -060015004
Mark Youngd339ba32016-05-30 13:28:35 -060015005TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15006 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015008 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015009
15010 ASSERT_NO_FATAL_FAILURE(InitState());
15011
15012 // Create an image and try to create a view with no memory backing the image
15013 VkImage image;
15014
15015 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15016 const int32_t tex_width = 32;
15017 const int32_t tex_height = 32;
15018
15019 VkImageCreateInfo image_create_info = {};
15020 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15021 image_create_info.pNext = NULL;
15022 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15023 image_create_info.format = tex_format;
15024 image_create_info.extent.width = tex_width;
15025 image_create_info.extent.height = tex_height;
15026 image_create_info.extent.depth = 1;
15027 image_create_info.mipLevels = 1;
15028 image_create_info.arrayLayers = 1;
15029 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15030 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15031 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15032 image_create_info.flags = 0;
15033
15034 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15035 ASSERT_VK_SUCCESS(err);
15036
15037 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015038 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015039 image_view_create_info.image = image;
15040 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15041 image_view_create_info.format = tex_format;
15042 image_view_create_info.subresourceRange.layerCount = 1;
15043 image_view_create_info.subresourceRange.baseMipLevel = 0;
15044 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015045 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015046
15047 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015048 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015049
15050 m_errorMonitor->VerifyFound();
15051 vkDestroyImage(m_device->device(), image, NULL);
15052 // If last error is success, it still created the view, so delete it.
15053 if (err == VK_SUCCESS) {
15054 vkDestroyImageView(m_device->device(), view, NULL);
15055 }
Mark Youngd339ba32016-05-30 13:28:35 -060015056}
15057
Karl Schultz6addd812016-02-02 17:17:23 -070015058TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015059 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015061
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015062 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015063
Karl Schultz6addd812016-02-02 17:17:23 -070015064 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015065 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015066 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015067 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015068
15069 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015070 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015071 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015072 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15073 image_view_create_info.format = tex_format;
15074 image_view_create_info.subresourceRange.baseMipLevel = 0;
15075 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015076 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015077 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015078 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015079
15080 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015081 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015082
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015083 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015084}
15085
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015086TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015087 VkResult err;
15088 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015089
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015091
Mike Stroyana3082432015-09-25 13:39:21 -060015092 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015093
15094 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015095 VkImage srcImage;
15096 VkImage dstImage;
15097 VkDeviceMemory srcMem;
15098 VkDeviceMemory destMem;
15099 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015100
15101 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015102 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15103 image_create_info.pNext = NULL;
15104 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15105 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15106 image_create_info.extent.width = 32;
15107 image_create_info.extent.height = 32;
15108 image_create_info.extent.depth = 1;
15109 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015110 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015111 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15112 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15113 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15114 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015116 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015117 ASSERT_VK_SUCCESS(err);
15118
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015119 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015120 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015121 ASSERT_VK_SUCCESS(err);
15122
15123 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015124 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015125 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15126 memAlloc.pNext = NULL;
15127 memAlloc.allocationSize = 0;
15128 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015129
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015130 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015131 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015133 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015134 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015135 ASSERT_VK_SUCCESS(err);
15136
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015137 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015138 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015139 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015140 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015141 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015142 ASSERT_VK_SUCCESS(err);
15143
15144 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15145 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015146 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015147 ASSERT_VK_SUCCESS(err);
15148
Tony Barbour552f6c02016-12-21 14:34:07 -070015149 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015150 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015151 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015152 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015153 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015154 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015155 copyRegion.srcOffset.x = 0;
15156 copyRegion.srcOffset.y = 0;
15157 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015158 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015159 copyRegion.dstSubresource.mipLevel = 0;
15160 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015161 // Introduce failure by forcing the dst layerCount to differ from src
15162 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015163 copyRegion.dstOffset.x = 0;
15164 copyRegion.dstOffset.y = 0;
15165 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015166 copyRegion.extent.width = 1;
15167 copyRegion.extent.height = 1;
15168 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015169 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015170 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015171
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015172 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015173
Chia-I Wuf7458c52015-10-26 21:10:41 +080015174 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015175 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015176 vkFreeMemory(m_device->device(), srcMem, NULL);
15177 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015178}
15179
Tony Barbourd6673642016-05-05 14:46:39 -060015180TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015181 TEST_DESCRIPTION("Creating images with unsuported formats ");
15182
15183 ASSERT_NO_FATAL_FAILURE(InitState());
15184 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15185 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015186 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 -060015187 VK_IMAGE_TILING_OPTIMAL, 0);
15188 ASSERT_TRUE(image.initialized());
15189
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015190 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015191 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015192 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015193 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15194 image_create_info.format = VK_FORMAT_UNDEFINED;
15195 image_create_info.extent.width = 32;
15196 image_create_info.extent.height = 32;
15197 image_create_info.extent.depth = 1;
15198 image_create_info.mipLevels = 1;
15199 image_create_info.arrayLayers = 1;
15200 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15201 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15202 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015203
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015204 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15205 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015206
15207 VkImage localImage;
15208 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15209 m_errorMonitor->VerifyFound();
15210
Tony Barbourd6673642016-05-05 14:46:39 -060015211 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015212 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015213 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15214 VkFormat format = static_cast<VkFormat>(f);
15215 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015216 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015217 unsupported = format;
15218 break;
15219 }
15220 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015221
Tony Barbourd6673642016-05-05 14:46:39 -060015222 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015223 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015225
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015226 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015227 m_errorMonitor->VerifyFound();
15228 }
15229}
15230
15231TEST_F(VkLayerTest, ImageLayerViewTests) {
15232 VkResult ret;
15233 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15234
15235 ASSERT_NO_FATAL_FAILURE(InitState());
15236
15237 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015238 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 -060015239 VK_IMAGE_TILING_OPTIMAL, 0);
15240 ASSERT_TRUE(image.initialized());
15241
15242 VkImageView imgView;
15243 VkImageViewCreateInfo imgViewInfo = {};
15244 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15245 imgViewInfo.image = image.handle();
15246 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15247 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15248 imgViewInfo.subresourceRange.layerCount = 1;
15249 imgViewInfo.subresourceRange.baseMipLevel = 0;
15250 imgViewInfo.subresourceRange.levelCount = 1;
15251 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15252
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015253 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015254 // View can't have baseMipLevel >= image's mipLevels - Expect
15255 // VIEW_CREATE_ERROR
15256 imgViewInfo.subresourceRange.baseMipLevel = 1;
15257 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15258 m_errorMonitor->VerifyFound();
15259 imgViewInfo.subresourceRange.baseMipLevel = 0;
15260
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015261 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015262 // View can't have baseArrayLayer >= image's arraySize - Expect
15263 // VIEW_CREATE_ERROR
15264 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15265 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15266 m_errorMonitor->VerifyFound();
15267 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15268
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015270 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15271 imgViewInfo.subresourceRange.levelCount = 0;
15272 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15273 m_errorMonitor->VerifyFound();
15274 imgViewInfo.subresourceRange.levelCount = 1;
15275
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015276 m_errorMonitor->SetDesiredFailureMsg(
15277 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15278 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015279 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15280 imgViewInfo.subresourceRange.layerCount = 0;
15281 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15282 m_errorMonitor->VerifyFound();
15283 imgViewInfo.subresourceRange.layerCount = 1;
15284
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15286 "Formats MUST be IDENTICAL unless "
15287 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15288 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015289 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15290 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15291 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15292 m_errorMonitor->VerifyFound();
15293 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15294
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015296 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15297 // VIEW_CREATE_ERROR
15298 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15299 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15300 m_errorMonitor->VerifyFound();
15301 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15302
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015304 // TODO: Update framework to easily passing mutable flag into ImageObj init
15305 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015306 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15307 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15308 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015309 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15310 // VIEW_CREATE_ERROR
15311 VkImageCreateInfo mutImgInfo = image.create_info();
15312 VkImage mutImage;
15313 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015314 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015315 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15316 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15317 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15318 ASSERT_VK_SUCCESS(ret);
15319 imgViewInfo.image = mutImage;
15320 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15321 m_errorMonitor->VerifyFound();
15322 imgViewInfo.image = image.handle();
15323 vkDestroyImage(m_device->handle(), mutImage, NULL);
15324}
15325
15326TEST_F(VkLayerTest, MiscImageLayerTests) {
Tony Barbourd6673642016-05-05 14:46:39 -060015327 TEST_DESCRIPTION("Image layer tests that don't belong elsewhare");
15328
15329 ASSERT_NO_FATAL_FAILURE(InitState());
15330
Rene Lindsay135204f2016-12-22 17:11:09 -070015331 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060015332 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070015333 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 -070015334 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060015335 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060015336 vk_testing::Buffer buffer;
15337 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070015338 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060015339 VkBufferImageCopy region = {};
15340 region.bufferRowLength = 128;
15341 region.bufferImageHeight = 128;
15342 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15343 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070015344 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015345 region.imageExtent.height = 4;
15346 region.imageExtent.width = 4;
15347 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070015348
15349 VkImageObj image2(m_device);
15350 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 -070015351 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070015352 ASSERT_TRUE(image2.initialized());
15353 vk_testing::Buffer buffer2;
15354 VkMemoryPropertyFlags reqs2 = 0;
15355 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
15356 VkBufferImageCopy region2 = {};
15357 region2.bufferRowLength = 128;
15358 region2.bufferImageHeight = 128;
15359 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15360 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
15361 region2.imageSubresource.layerCount = 1;
15362 region2.imageExtent.height = 4;
15363 region2.imageExtent.width = 4;
15364 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015365 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060015366
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015367 // Image must have offset.z of 0 and extent.depth of 1
15368 // Introduce failure by setting imageExtent.depth to 0
15369 region.imageExtent.depth = 0;
15370 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15371 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015372 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015373 m_errorMonitor->VerifyFound();
15374
15375 region.imageExtent.depth = 1;
15376
15377 // Image must have offset.z of 0 and extent.depth of 1
15378 // Introduce failure by setting imageOffset.z to 4
15379 region.imageOffset.z = 4;
15380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01269);
15381 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070015382 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070015383 m_errorMonitor->VerifyFound();
15384
15385 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015386 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
15387 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070015388 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015390 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15391 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015392 m_errorMonitor->VerifyFound();
15393
15394 // BufferOffset must be a multiple of 4
15395 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070015396 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070015398 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
15399 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015400 m_errorMonitor->VerifyFound();
15401
15402 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
15403 region.bufferOffset = 0;
15404 region.imageExtent.height = 128;
15405 region.imageExtent.width = 128;
15406 // Introduce failure by setting bufferRowLength > 0 but less than width
15407 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015409 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15410 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015411 m_errorMonitor->VerifyFound();
15412
15413 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
15414 region.bufferRowLength = 128;
15415 // Introduce failure by setting bufferRowHeight > 0 but less than height
15416 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070015417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015418 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
15419 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060015420 m_errorMonitor->VerifyFound();
15421
15422 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060015423 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015424 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
15425 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015426 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070015427 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15428 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060015429 VkImageBlit blitRegion = {};
15430 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15431 blitRegion.srcSubresource.baseArrayLayer = 0;
15432 blitRegion.srcSubresource.layerCount = 1;
15433 blitRegion.srcSubresource.mipLevel = 0;
15434 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15435 blitRegion.dstSubresource.baseArrayLayer = 0;
15436 blitRegion.dstSubresource.layerCount = 1;
15437 blitRegion.dstSubresource.mipLevel = 0;
15438
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015439 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
15441 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
15442 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060015443 m_errorMonitor->VerifyFound();
15444
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070015445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015446 VkImageMemoryBarrier img_barrier;
15447 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
15448 img_barrier.pNext = NULL;
15449 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
15450 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
15451 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15452 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15453 img_barrier.image = image.handle();
15454 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15455 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
15456 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15457 img_barrier.subresourceRange.baseArrayLayer = 0;
15458 img_barrier.subresourceRange.baseMipLevel = 0;
15459 // layerCount should not be 0 - Expect INVALID_IMAGE_RESOURCE
15460 img_barrier.subresourceRange.layerCount = 0;
15461 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015462 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
15463 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060015464 m_errorMonitor->VerifyFound();
15465 img_barrier.subresourceRange.layerCount = 1;
15466}
15467
15468TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060015469 TEST_DESCRIPTION("Exceed the limits of image format ");
15470
Cody Northropc31a84f2016-08-22 10:41:47 -060015471 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060015473 VkImageCreateInfo image_create_info = {};
15474 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15475 image_create_info.pNext = NULL;
15476 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15477 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15478 image_create_info.extent.width = 32;
15479 image_create_info.extent.height = 32;
15480 image_create_info.extent.depth = 1;
15481 image_create_info.mipLevels = 1;
15482 image_create_info.arrayLayers = 1;
15483 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15484 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15485 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15486 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15487 image_create_info.flags = 0;
15488
15489 VkImage nullImg;
15490 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015491 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
15492 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070015493 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015494 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15495 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15496 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070015497 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060015498
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015500 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
15501 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15502 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15503 m_errorMonitor->VerifyFound();
15504 image_create_info.mipLevels = 1;
15505
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060015507 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
15508 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15509 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15510 m_errorMonitor->VerifyFound();
15511 image_create_info.arrayLayers = 1;
15512
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060015514 int samples = imgFmtProps.sampleCounts >> 1;
15515 image_create_info.samples = (VkSampleCountFlagBits)samples;
15516 // Expect INVALID_FORMAT_LIMITS_VIOLATION
15517 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15518 m_errorMonitor->VerifyFound();
15519 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15520
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15522 "pCreateInfo->initialLayout, must be "
15523 "VK_IMAGE_LAYOUT_UNDEFINED or "
15524 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060015525 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
15526 // Expect INVALID_LAYOUT
15527 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
15528 m_errorMonitor->VerifyFound();
15529 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
15530}
15531
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015532TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015533 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015535
15536 ASSERT_NO_FATAL_FAILURE(InitState());
15537
15538 VkImageObj src_image(m_device);
15539 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15540 VkImageObj dst_image(m_device);
15541 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15542
Tony Barbour552f6c02016-12-21 14:34:07 -070015543 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015544 VkImageCopy copy_region;
15545 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15546 copy_region.srcSubresource.mipLevel = 0;
15547 copy_region.srcSubresource.baseArrayLayer = 0;
15548 copy_region.srcSubresource.layerCount = 0;
15549 copy_region.srcOffset.x = 0;
15550 copy_region.srcOffset.y = 0;
15551 copy_region.srcOffset.z = 0;
15552 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15553 copy_region.dstSubresource.mipLevel = 0;
15554 copy_region.dstSubresource.baseArrayLayer = 0;
15555 copy_region.dstSubresource.layerCount = 0;
15556 copy_region.dstOffset.x = 0;
15557 copy_region.dstOffset.y = 0;
15558 copy_region.dstOffset.z = 0;
15559 copy_region.extent.width = 64;
15560 copy_region.extent.height = 64;
15561 copy_region.extent.depth = 1;
15562 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15563 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015564 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015565
15566 m_errorMonitor->VerifyFound();
15567}
15568
15569TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015570 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060015571 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015572
15573 ASSERT_NO_FATAL_FAILURE(InitState());
15574
15575 VkImageObj src_image(m_device);
15576 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
15577 VkImageObj dst_image(m_device);
15578 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
15579
Tony Barbour552f6c02016-12-21 14:34:07 -070015580 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015581 VkImageCopy copy_region;
15582 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15583 copy_region.srcSubresource.mipLevel = 0;
15584 copy_region.srcSubresource.baseArrayLayer = 0;
15585 copy_region.srcSubresource.layerCount = 0;
15586 copy_region.srcOffset.x = 0;
15587 copy_region.srcOffset.y = 0;
15588 copy_region.srcOffset.z = 0;
15589 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15590 copy_region.dstSubresource.mipLevel = 0;
15591 copy_region.dstSubresource.baseArrayLayer = 0;
15592 copy_region.dstSubresource.layerCount = 0;
15593 copy_region.dstOffset.x = 0;
15594 copy_region.dstOffset.y = 0;
15595 copy_region.dstOffset.z = 0;
15596 copy_region.extent.width = 64;
15597 copy_region.extent.height = 64;
15598 copy_region.extent.depth = 1;
15599 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
15600 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070015601 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060015602
15603 m_errorMonitor->VerifyFound();
15604}
15605
Karl Schultz6addd812016-02-02 17:17:23 -070015606TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060015607 VkResult err;
15608 bool pass;
15609
15610 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015611 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060015612
15613 ASSERT_NO_FATAL_FAILURE(InitState());
15614
15615 // Create two images of different types and try to copy between them
15616 VkImage srcImage;
15617 VkImage dstImage;
15618 VkDeviceMemory srcMem;
15619 VkDeviceMemory destMem;
15620 VkMemoryRequirements memReqs;
15621
15622 VkImageCreateInfo image_create_info = {};
15623 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15624 image_create_info.pNext = NULL;
15625 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15626 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15627 image_create_info.extent.width = 32;
15628 image_create_info.extent.height = 32;
15629 image_create_info.extent.depth = 1;
15630 image_create_info.mipLevels = 1;
15631 image_create_info.arrayLayers = 1;
15632 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15633 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15634 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15635 image_create_info.flags = 0;
15636
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015637 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015638 ASSERT_VK_SUCCESS(err);
15639
15640 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15641 // Introduce failure by creating second image with a different-sized format.
15642 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
15643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015644 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060015645 ASSERT_VK_SUCCESS(err);
15646
15647 // Allocate memory
15648 VkMemoryAllocateInfo memAlloc = {};
15649 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15650 memAlloc.pNext = NULL;
15651 memAlloc.allocationSize = 0;
15652 memAlloc.memoryTypeIndex = 0;
15653
15654 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
15655 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015656 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015657 ASSERT_TRUE(pass);
15658 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
15659 ASSERT_VK_SUCCESS(err);
15660
15661 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
15662 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015663 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060015664 ASSERT_TRUE(pass);
15665 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
15666 ASSERT_VK_SUCCESS(err);
15667
15668 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15669 ASSERT_VK_SUCCESS(err);
15670 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
15671 ASSERT_VK_SUCCESS(err);
15672
Tony Barbour552f6c02016-12-21 14:34:07 -070015673 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015674 VkImageCopy copyRegion;
15675 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15676 copyRegion.srcSubresource.mipLevel = 0;
15677 copyRegion.srcSubresource.baseArrayLayer = 0;
15678 copyRegion.srcSubresource.layerCount = 0;
15679 copyRegion.srcOffset.x = 0;
15680 copyRegion.srcOffset.y = 0;
15681 copyRegion.srcOffset.z = 0;
15682 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15683 copyRegion.dstSubresource.mipLevel = 0;
15684 copyRegion.dstSubresource.baseArrayLayer = 0;
15685 copyRegion.dstSubresource.layerCount = 0;
15686 copyRegion.dstOffset.x = 0;
15687 copyRegion.dstOffset.y = 0;
15688 copyRegion.dstOffset.z = 0;
15689 copyRegion.extent.width = 1;
15690 copyRegion.extent.height = 1;
15691 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015692 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015693 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060015694
15695 m_errorMonitor->VerifyFound();
15696
15697 vkDestroyImage(m_device->device(), srcImage, NULL);
15698 vkDestroyImage(m_device->device(), dstImage, NULL);
15699 vkFreeMemory(m_device->device(), srcMem, NULL);
15700 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015701}
15702
Karl Schultz6addd812016-02-02 17:17:23 -070015703TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
15704 VkResult err;
15705 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015706
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015707 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15709 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015710
Mike Stroyana3082432015-09-25 13:39:21 -060015711 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015712
15713 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015714 VkImage srcImage;
15715 VkImage dstImage;
15716 VkDeviceMemory srcMem;
15717 VkDeviceMemory destMem;
15718 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015719
15720 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015721 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15722 image_create_info.pNext = NULL;
15723 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15724 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15725 image_create_info.extent.width = 32;
15726 image_create_info.extent.height = 32;
15727 image_create_info.extent.depth = 1;
15728 image_create_info.mipLevels = 1;
15729 image_create_info.arrayLayers = 1;
15730 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15731 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15732 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15733 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015734
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015735 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015736 ASSERT_VK_SUCCESS(err);
15737
Karl Schultzbdb75952016-04-19 11:36:49 -060015738 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
15739
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015740 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070015741 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015742 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015743 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015744
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015745 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015746 ASSERT_VK_SUCCESS(err);
15747
15748 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015749 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015750 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15751 memAlloc.pNext = NULL;
15752 memAlloc.allocationSize = 0;
15753 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015754
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015755 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015756 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015757 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015758 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015759 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015760 ASSERT_VK_SUCCESS(err);
15761
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015762 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015763 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015764 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015765 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015766 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015767 ASSERT_VK_SUCCESS(err);
15768
15769 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15770 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015771 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015772 ASSERT_VK_SUCCESS(err);
15773
Tony Barbour552f6c02016-12-21 14:34:07 -070015774 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015775 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015776 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015777 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015778 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015779 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015780 copyRegion.srcOffset.x = 0;
15781 copyRegion.srcOffset.y = 0;
15782 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015783 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015784 copyRegion.dstSubresource.mipLevel = 0;
15785 copyRegion.dstSubresource.baseArrayLayer = 0;
15786 copyRegion.dstSubresource.layerCount = 0;
15787 copyRegion.dstOffset.x = 0;
15788 copyRegion.dstOffset.y = 0;
15789 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015790 copyRegion.extent.width = 1;
15791 copyRegion.extent.height = 1;
15792 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015793 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015794 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015795
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015796 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015797
Chia-I Wuf7458c52015-10-26 21:10:41 +080015798 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015799 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015800 vkFreeMemory(m_device->device(), srcMem, NULL);
15801 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015802}
15803
Karl Schultz6addd812016-02-02 17:17:23 -070015804TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
15805 VkResult err;
15806 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015807
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15809 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015810
Mike Stroyana3082432015-09-25 13:39:21 -060015811 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015812
15813 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015814 VkImage srcImage;
15815 VkImage dstImage;
15816 VkDeviceMemory srcMem;
15817 VkDeviceMemory destMem;
15818 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015819
15820 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015821 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15822 image_create_info.pNext = NULL;
15823 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15824 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15825 image_create_info.extent.width = 32;
15826 image_create_info.extent.height = 1;
15827 image_create_info.extent.depth = 1;
15828 image_create_info.mipLevels = 1;
15829 image_create_info.arrayLayers = 1;
15830 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15831 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15832 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15833 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015835 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015836 ASSERT_VK_SUCCESS(err);
15837
Karl Schultz6addd812016-02-02 17:17:23 -070015838 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015839
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015840 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015841 ASSERT_VK_SUCCESS(err);
15842
15843 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015844 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015845 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15846 memAlloc.pNext = NULL;
15847 memAlloc.allocationSize = 0;
15848 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015849
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015850 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015851 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015852 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015853 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015854 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015855 ASSERT_VK_SUCCESS(err);
15856
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015857 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015858 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015859 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015860 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015861 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015862 ASSERT_VK_SUCCESS(err);
15863
15864 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15865 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015866 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015867 ASSERT_VK_SUCCESS(err);
15868
Tony Barbour552f6c02016-12-21 14:34:07 -070015869 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015870 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015871 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15872 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015873 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015874 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015875 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015876 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015877 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015878 resolveRegion.srcOffset.x = 0;
15879 resolveRegion.srcOffset.y = 0;
15880 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015881 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015882 resolveRegion.dstSubresource.mipLevel = 0;
15883 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015884 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015885 resolveRegion.dstOffset.x = 0;
15886 resolveRegion.dstOffset.y = 0;
15887 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015888 resolveRegion.extent.width = 1;
15889 resolveRegion.extent.height = 1;
15890 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015891 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015892 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015893
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015894 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015895
Chia-I Wuf7458c52015-10-26 21:10:41 +080015896 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015897 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015898 vkFreeMemory(m_device->device(), srcMem, NULL);
15899 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015900}
15901
Karl Schultz6addd812016-02-02 17:17:23 -070015902TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
15903 VkResult err;
15904 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015905
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15907 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015908
Mike Stroyana3082432015-09-25 13:39:21 -060015909 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015910
Chris Forbesa7530692016-05-08 12:35:39 +120015911 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070015912 VkImage srcImage;
15913 VkImage dstImage;
15914 VkDeviceMemory srcMem;
15915 VkDeviceMemory destMem;
15916 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015917
15918 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015919 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15920 image_create_info.pNext = NULL;
15921 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15922 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15923 image_create_info.extent.width = 32;
15924 image_create_info.extent.height = 1;
15925 image_create_info.extent.depth = 1;
15926 image_create_info.mipLevels = 1;
15927 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120015928 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015929 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15930 // Note: Some implementations expect color attachment usage for any
15931 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015932 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070015933 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015934
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015935 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015936 ASSERT_VK_SUCCESS(err);
15937
Karl Schultz6addd812016-02-02 17:17:23 -070015938 // Note: Some implementations expect color attachment usage for any
15939 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015940 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015942 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015943 ASSERT_VK_SUCCESS(err);
15944
15945 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015946 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015947 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15948 memAlloc.pNext = NULL;
15949 memAlloc.allocationSize = 0;
15950 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015951
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015952 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015953 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015954 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015955 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015956 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015957 ASSERT_VK_SUCCESS(err);
15958
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015959 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015960 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015961 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015962 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015963 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015964 ASSERT_VK_SUCCESS(err);
15965
15966 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15967 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015968 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015969 ASSERT_VK_SUCCESS(err);
15970
Tony Barbour552f6c02016-12-21 14:34:07 -070015971 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015972 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070015973 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
15974 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060015975 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015976 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015977 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015978 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015979 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015980 resolveRegion.srcOffset.x = 0;
15981 resolveRegion.srcOffset.y = 0;
15982 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015983 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015984 resolveRegion.dstSubresource.mipLevel = 0;
15985 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130015986 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015987 resolveRegion.dstOffset.x = 0;
15988 resolveRegion.dstOffset.y = 0;
15989 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015990 resolveRegion.extent.width = 1;
15991 resolveRegion.extent.height = 1;
15992 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015993 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015994 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015995
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015996 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015997
Chia-I Wuf7458c52015-10-26 21:10:41 +080015998 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015999 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016000 vkFreeMemory(m_device->device(), srcMem, NULL);
16001 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016002}
16003
Karl Schultz6addd812016-02-02 17:17:23 -070016004TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16005 VkResult err;
16006 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016007
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016009 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016010
Mike Stroyana3082432015-09-25 13:39:21 -060016011 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016012
16013 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016014 VkImage srcImage;
16015 VkImage dstImage;
16016 VkDeviceMemory srcMem;
16017 VkDeviceMemory destMem;
16018 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016019
16020 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016021 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16022 image_create_info.pNext = NULL;
16023 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16024 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16025 image_create_info.extent.width = 32;
16026 image_create_info.extent.height = 1;
16027 image_create_info.extent.depth = 1;
16028 image_create_info.mipLevels = 1;
16029 image_create_info.arrayLayers = 1;
16030 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16031 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16032 // Note: Some implementations expect color attachment usage for any
16033 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016034 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016035 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016036
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016037 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016038 ASSERT_VK_SUCCESS(err);
16039
Karl Schultz6addd812016-02-02 17:17:23 -070016040 // Set format to something other than source image
16041 image_create_info.format = VK_FORMAT_R32_SFLOAT;
16042 // Note: Some implementations expect color attachment usage for any
16043 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016044 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016045 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016047 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016048 ASSERT_VK_SUCCESS(err);
16049
16050 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016051 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016052 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16053 memAlloc.pNext = NULL;
16054 memAlloc.allocationSize = 0;
16055 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016056
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016057 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016058 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016059 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016060 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016061 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016062 ASSERT_VK_SUCCESS(err);
16063
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016064 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016065 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016066 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016067 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016068 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016069 ASSERT_VK_SUCCESS(err);
16070
16071 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16072 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016073 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016074 ASSERT_VK_SUCCESS(err);
16075
Tony Barbour552f6c02016-12-21 14:34:07 -070016076 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016077 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016078 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16079 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016080 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016081 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016082 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016083 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016084 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016085 resolveRegion.srcOffset.x = 0;
16086 resolveRegion.srcOffset.y = 0;
16087 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016088 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016089 resolveRegion.dstSubresource.mipLevel = 0;
16090 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016091 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016092 resolveRegion.dstOffset.x = 0;
16093 resolveRegion.dstOffset.y = 0;
16094 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016095 resolveRegion.extent.width = 1;
16096 resolveRegion.extent.height = 1;
16097 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016098 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016099 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016100
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016101 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016102
Chia-I Wuf7458c52015-10-26 21:10:41 +080016103 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016104 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016105 vkFreeMemory(m_device->device(), srcMem, NULL);
16106 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016107}
16108
Karl Schultz6addd812016-02-02 17:17:23 -070016109TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
16110 VkResult err;
16111 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016112
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016114 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016115
Mike Stroyana3082432015-09-25 13:39:21 -060016116 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016117
16118 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016119 VkImage srcImage;
16120 VkImage dstImage;
16121 VkDeviceMemory srcMem;
16122 VkDeviceMemory destMem;
16123 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016124
16125 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016126 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16127 image_create_info.pNext = NULL;
16128 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16129 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16130 image_create_info.extent.width = 32;
16131 image_create_info.extent.height = 1;
16132 image_create_info.extent.depth = 1;
16133 image_create_info.mipLevels = 1;
16134 image_create_info.arrayLayers = 1;
16135 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16136 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16137 // Note: Some implementations expect color attachment usage for any
16138 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016139 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016140 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016141
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016142 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016143 ASSERT_VK_SUCCESS(err);
16144
Karl Schultz6addd812016-02-02 17:17:23 -070016145 image_create_info.imageType = VK_IMAGE_TYPE_1D;
16146 // Note: Some implementations expect color attachment usage for any
16147 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016148 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016149 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016150
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016151 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016152 ASSERT_VK_SUCCESS(err);
16153
16154 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016155 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016156 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16157 memAlloc.pNext = NULL;
16158 memAlloc.allocationSize = 0;
16159 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016160
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016161 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016162 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016163 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016164 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016165 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016166 ASSERT_VK_SUCCESS(err);
16167
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016168 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016169 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016170 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016171 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016172 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016173 ASSERT_VK_SUCCESS(err);
16174
16175 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16176 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016177 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016178 ASSERT_VK_SUCCESS(err);
16179
Tony Barbour552f6c02016-12-21 14:34:07 -070016180 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016181 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016182 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16183 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016184 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016185 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016186 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016187 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016188 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016189 resolveRegion.srcOffset.x = 0;
16190 resolveRegion.srcOffset.y = 0;
16191 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016192 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016193 resolveRegion.dstSubresource.mipLevel = 0;
16194 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016195 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016196 resolveRegion.dstOffset.x = 0;
16197 resolveRegion.dstOffset.y = 0;
16198 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016199 resolveRegion.extent.width = 1;
16200 resolveRegion.extent.height = 1;
16201 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016202 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016203 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016204
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016205 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016206
Chia-I Wuf7458c52015-10-26 21:10:41 +080016207 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016208 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016209 vkFreeMemory(m_device->device(), srcMem, NULL);
16210 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016211}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016212
Karl Schultz6addd812016-02-02 17:17:23 -070016213TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016214 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070016215 // to using a DS format, then cause it to hit error due to COLOR_BIT not
16216 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016217 // The image format check comes 2nd in validation so we trigger it first,
16218 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070016219 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016220
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16222 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016223
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016224 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016225
Chia-I Wu1b99bb22015-10-27 19:25:11 +080016226 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016227 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16228 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016229
16230 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016231 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16232 ds_pool_ci.pNext = NULL;
16233 ds_pool_ci.maxSets = 1;
16234 ds_pool_ci.poolSizeCount = 1;
16235 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016236
16237 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016238 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016239 ASSERT_VK_SUCCESS(err);
16240
16241 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016242 dsl_binding.binding = 0;
16243 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16244 dsl_binding.descriptorCount = 1;
16245 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16246 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016247
16248 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016249 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16250 ds_layout_ci.pNext = NULL;
16251 ds_layout_ci.bindingCount = 1;
16252 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016253 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016254 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016255 ASSERT_VK_SUCCESS(err);
16256
16257 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016258 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080016259 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070016260 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016261 alloc_info.descriptorPool = ds_pool;
16262 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016263 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016264 ASSERT_VK_SUCCESS(err);
16265
Karl Schultz6addd812016-02-02 17:17:23 -070016266 VkImage image_bad;
16267 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016268 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060016269 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016270 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070016271 const int32_t tex_width = 32;
16272 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016273
16274 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016275 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16276 image_create_info.pNext = NULL;
16277 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16278 image_create_info.format = tex_format_bad;
16279 image_create_info.extent.width = tex_width;
16280 image_create_info.extent.height = tex_height;
16281 image_create_info.extent.depth = 1;
16282 image_create_info.mipLevels = 1;
16283 image_create_info.arrayLayers = 1;
16284 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16285 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016286 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016287 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016289 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016290 ASSERT_VK_SUCCESS(err);
16291 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016292 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16293 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016294 ASSERT_VK_SUCCESS(err);
16295
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016296 // ---Bind image memory---
16297 VkMemoryRequirements img_mem_reqs;
16298 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
16299 VkMemoryAllocateInfo image_alloc_info = {};
16300 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16301 image_alloc_info.pNext = NULL;
16302 image_alloc_info.memoryTypeIndex = 0;
16303 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016304 bool pass =
16305 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 -070016306 ASSERT_TRUE(pass);
16307 VkDeviceMemory mem;
16308 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
16309 ASSERT_VK_SUCCESS(err);
16310 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
16311 ASSERT_VK_SUCCESS(err);
16312 // -----------------------
16313
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016314 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130016315 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070016316 image_view_create_info.image = image_bad;
16317 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16318 image_view_create_info.format = tex_format_bad;
16319 image_view_create_info.subresourceRange.baseArrayLayer = 0;
16320 image_view_create_info.subresourceRange.baseMipLevel = 0;
16321 image_view_create_info.subresourceRange.layerCount = 1;
16322 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016323 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016324
16325 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016326 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016327
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016328 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016329
Chia-I Wuf7458c52015-10-26 21:10:41 +080016330 vkDestroyImage(m_device->device(), image_bad, NULL);
16331 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016332 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16333 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070016334
16335 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060016336}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016337
16338TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016339 TEST_DESCRIPTION(
16340 "Call ClearColorImage w/ a depth|stencil image and "
16341 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016342
16343 ASSERT_NO_FATAL_FAILURE(InitState());
16344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16345
Tony Barbour552f6c02016-12-21 14:34:07 -070016346 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016347
16348 // Color image
16349 VkClearColorValue clear_color;
16350 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
16351 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
16352 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
16353 const int32_t img_width = 32;
16354 const int32_t img_height = 32;
16355 VkImageCreateInfo image_create_info = {};
16356 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16357 image_create_info.pNext = NULL;
16358 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16359 image_create_info.format = color_format;
16360 image_create_info.extent.width = img_width;
16361 image_create_info.extent.height = img_height;
16362 image_create_info.extent.depth = 1;
16363 image_create_info.mipLevels = 1;
16364 image_create_info.arrayLayers = 1;
16365 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16366 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16367 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16368
16369 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016370 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016372 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016373
16374 // Depth/Stencil image
16375 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016376 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016377 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
16378 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
16379 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
16380 ds_image_create_info.extent.width = 64;
16381 ds_image_create_info.extent.height = 64;
16382 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016383 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 -060016384
16385 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016386 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016388 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 -060016389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016391
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016392 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016393 &color_range);
16394
16395 m_errorMonitor->VerifyFound();
16396
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16398 "vkCmdClearColorImage called with "
16399 "image created without "
16400 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060016401
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070016402 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060016403 &color_range);
16404
16405 m_errorMonitor->VerifyFound();
16406
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016407 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16409 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016410
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016411 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
16412 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060016413
16414 m_errorMonitor->VerifyFound();
16415}
Tobin Ehliscde08892015-09-22 10:11:37 -060016416
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016417// WSI Enabled Tests
16418//
Chris Forbes09368e42016-10-13 11:59:22 +130016419#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016420TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
16421
16422#if defined(VK_USE_PLATFORM_XCB_KHR)
16423 VkSurfaceKHR surface = VK_NULL_HANDLE;
16424
16425 VkResult err;
16426 bool pass;
16427 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
16428 VkSwapchainCreateInfoKHR swapchain_create_info = {};
16429 // uint32_t swapchain_image_count = 0;
16430 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
16431 // uint32_t image_index = 0;
16432 // VkPresentInfoKHR present_info = {};
16433
16434 ASSERT_NO_FATAL_FAILURE(InitState());
16435
16436 // Use the create function from one of the VK_KHR_*_surface extension in
16437 // order to create a surface, testing all known errors in the process,
16438 // before successfully creating a surface:
16439 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
16440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
16441 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
16442 pass = (err != VK_SUCCESS);
16443 ASSERT_TRUE(pass);
16444 m_errorMonitor->VerifyFound();
16445
16446 // Next, try to create a surface with the wrong
16447 // VkXcbSurfaceCreateInfoKHR::sType:
16448 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
16449 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16451 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16452 pass = (err != VK_SUCCESS);
16453 ASSERT_TRUE(pass);
16454 m_errorMonitor->VerifyFound();
16455
16456 // Create a native window, and then correctly create a surface:
16457 xcb_connection_t *connection;
16458 xcb_screen_t *screen;
16459 xcb_window_t xcb_window;
16460 xcb_intern_atom_reply_t *atom_wm_delete_window;
16461
16462 const xcb_setup_t *setup;
16463 xcb_screen_iterator_t iter;
16464 int scr;
16465 uint32_t value_mask, value_list[32];
16466 int width = 1;
16467 int height = 1;
16468
16469 connection = xcb_connect(NULL, &scr);
16470 ASSERT_TRUE(connection != NULL);
16471 setup = xcb_get_setup(connection);
16472 iter = xcb_setup_roots_iterator(setup);
16473 while (scr-- > 0)
16474 xcb_screen_next(&iter);
16475 screen = iter.data;
16476
16477 xcb_window = xcb_generate_id(connection);
16478
16479 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
16480 value_list[0] = screen->black_pixel;
16481 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
16482
16483 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
16484 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
16485
16486 /* Magic code that will send notification when window is destroyed */
16487 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
16488 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
16489
16490 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
16491 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
16492 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
16493 free(reply);
16494
16495 xcb_map_window(connection, xcb_window);
16496
16497 // Force the x/y coordinates to 100,100 results are identical in consecutive
16498 // runs
16499 const uint32_t coords[] = { 100, 100 };
16500 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
16501
16502 // Finally, try to correctly create a surface:
16503 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
16504 xcb_create_info.pNext = NULL;
16505 xcb_create_info.flags = 0;
16506 xcb_create_info.connection = connection;
16507 xcb_create_info.window = xcb_window;
16508 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
16509 pass = (err == VK_SUCCESS);
16510 ASSERT_TRUE(pass);
16511
16512 // Check if surface supports presentation:
16513
16514 // 1st, do so without having queried the queue families:
16515 VkBool32 supported = false;
16516 // TODO: Get the following error to come out:
16517 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16518 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
16519 "function");
16520 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16521 pass = (err != VK_SUCCESS);
16522 // ASSERT_TRUE(pass);
16523 // m_errorMonitor->VerifyFound();
16524
16525 // Next, query a queue family index that's too large:
16526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16527 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
16528 pass = (err != VK_SUCCESS);
16529 ASSERT_TRUE(pass);
16530 m_errorMonitor->VerifyFound();
16531
16532 // Finally, do so correctly:
16533 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16534 // SUPPORTED
16535 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
16536 pass = (err == VK_SUCCESS);
16537 ASSERT_TRUE(pass);
16538
16539 // Before proceeding, try to create a swapchain without having called
16540 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
16541 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16542 swapchain_create_info.pNext = NULL;
16543 swapchain_create_info.flags = 0;
16544 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16545 swapchain_create_info.surface = surface;
16546 swapchain_create_info.imageArrayLayers = 1;
16547 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
16548 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
16549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16550 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
16551 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16552 pass = (err != VK_SUCCESS);
16553 ASSERT_TRUE(pass);
16554 m_errorMonitor->VerifyFound();
16555
16556 // Get the surface capabilities:
16557 VkSurfaceCapabilitiesKHR surface_capabilities;
16558
16559 // Do so correctly (only error logged by this entrypoint is if the
16560 // extension isn't enabled):
16561 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
16562 pass = (err == VK_SUCCESS);
16563 ASSERT_TRUE(pass);
16564
16565 // Get the surface formats:
16566 uint32_t surface_format_count;
16567
16568 // First, try without a pointer to surface_format_count:
16569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
16570 "specified as NULL");
16571 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
16572 pass = (err == VK_SUCCESS);
16573 ASSERT_TRUE(pass);
16574 m_errorMonitor->VerifyFound();
16575
16576 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
16577 // correctly done a 1st try (to get the count):
16578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16579 surface_format_count = 0;
16580 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
16581 pass = (err == VK_SUCCESS);
16582 ASSERT_TRUE(pass);
16583 m_errorMonitor->VerifyFound();
16584
16585 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16586 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16587 pass = (err == VK_SUCCESS);
16588 ASSERT_TRUE(pass);
16589
16590 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16591 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
16592
16593 // Next, do a 2nd try with surface_format_count being set too high:
16594 surface_format_count += 5;
16595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16596 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16597 pass = (err == VK_SUCCESS);
16598 ASSERT_TRUE(pass);
16599 m_errorMonitor->VerifyFound();
16600
16601 // Finally, do a correct 1st and 2nd try:
16602 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
16603 pass = (err == VK_SUCCESS);
16604 ASSERT_TRUE(pass);
16605 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
16606 pass = (err == VK_SUCCESS);
16607 ASSERT_TRUE(pass);
16608
16609 // Get the surface present modes:
16610 uint32_t surface_present_mode_count;
16611
16612 // First, try without a pointer to surface_format_count:
16613 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
16614 "specified as NULL");
16615
16616 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
16617 pass = (err == VK_SUCCESS);
16618 ASSERT_TRUE(pass);
16619 m_errorMonitor->VerifyFound();
16620
16621 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
16622 // correctly done a 1st try (to get the count):
16623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
16624 surface_present_mode_count = 0;
16625 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
16626 (VkPresentModeKHR *)&surface_present_mode_count);
16627 pass = (err == VK_SUCCESS);
16628 ASSERT_TRUE(pass);
16629 m_errorMonitor->VerifyFound();
16630
16631 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
16632 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16633 pass = (err == VK_SUCCESS);
16634 ASSERT_TRUE(pass);
16635
16636 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
16637 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
16638
16639 // Next, do a 2nd try with surface_format_count being set too high:
16640 surface_present_mode_count += 5;
16641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
16642 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16643 pass = (err == VK_SUCCESS);
16644 ASSERT_TRUE(pass);
16645 m_errorMonitor->VerifyFound();
16646
16647 // Finally, do a correct 1st and 2nd try:
16648 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
16649 pass = (err == VK_SUCCESS);
16650 ASSERT_TRUE(pass);
16651 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
16652 pass = (err == VK_SUCCESS);
16653 ASSERT_TRUE(pass);
16654
16655 // Create a swapchain:
16656
16657 // First, try without a pointer to swapchain_create_info:
16658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
16659 "specified as NULL");
16660
16661 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
16662 pass = (err != VK_SUCCESS);
16663 ASSERT_TRUE(pass);
16664 m_errorMonitor->VerifyFound();
16665
16666 // Next, call with a non-NULL swapchain_create_info, that has the wrong
16667 // sType:
16668 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
16669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
16670
16671 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16672 pass = (err != VK_SUCCESS);
16673 ASSERT_TRUE(pass);
16674 m_errorMonitor->VerifyFound();
16675
16676 // Next, call with a NULL swapchain pointer:
16677 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
16678 swapchain_create_info.pNext = NULL;
16679 swapchain_create_info.flags = 0;
16680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
16681 "specified as NULL");
16682
16683 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
16684 pass = (err != VK_SUCCESS);
16685 ASSERT_TRUE(pass);
16686 m_errorMonitor->VerifyFound();
16687
16688 // TODO: Enhance swapchain layer so that
16689 // swapchain_create_info.queueFamilyIndexCount is checked against something?
16690
16691 // Next, call with a queue family index that's too large:
16692 uint32_t queueFamilyIndex[2] = { 100000, 0 };
16693 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16694 swapchain_create_info.queueFamilyIndexCount = 2;
16695 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
16696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
16697 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16698 pass = (err != VK_SUCCESS);
16699 ASSERT_TRUE(pass);
16700 m_errorMonitor->VerifyFound();
16701
16702 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
16703 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
16704 swapchain_create_info.queueFamilyIndexCount = 1;
16705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16706 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
16707 "pCreateInfo->pQueueFamilyIndices).");
16708 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16709 pass = (err != VK_SUCCESS);
16710 ASSERT_TRUE(pass);
16711 m_errorMonitor->VerifyFound();
16712
16713 // Next, call with an invalid imageSharingMode:
16714 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
16715 swapchain_create_info.queueFamilyIndexCount = 1;
16716 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16717 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
16718 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
16719 pass = (err != VK_SUCCESS);
16720 ASSERT_TRUE(pass);
16721 m_errorMonitor->VerifyFound();
16722 // Fix for the future:
16723 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
16724 // SUPPORTED
16725 swapchain_create_info.queueFamilyIndexCount = 0;
16726 queueFamilyIndex[0] = 0;
16727 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
16728
16729 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
16730 // Get the images from a swapchain:
16731 // Acquire an image from a swapchain:
16732 // Present an image to a swapchain:
16733 // Destroy the swapchain:
16734
16735 // TODOs:
16736 //
16737 // - Try destroying the device without first destroying the swapchain
16738 //
16739 // - Try destroying the device without first destroying the surface
16740 //
16741 // - Try destroying the surface without first destroying the swapchain
16742
16743 // Destroy the surface:
16744 vkDestroySurfaceKHR(instance(), surface, NULL);
16745
16746 // Tear down the window:
16747 xcb_destroy_window(connection, xcb_window);
16748 xcb_disconnect(connection);
16749
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016750#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016751 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016752#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016753}
Chris Forbes09368e42016-10-13 11:59:22 +130016754#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016755
16756//
16757// POSITIVE VALIDATION TESTS
16758//
16759// These tests do not expect to encounter ANY validation errors pass only if this is true
16760
Tobin Ehlise0006882016-11-03 10:14:28 -060016761TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016762 TEST_DESCRIPTION(
16763 "Perform an image layout transition in a secondary command buffer followed "
16764 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060016765 VkResult err;
16766 m_errorMonitor->ExpectSuccess();
16767 ASSERT_NO_FATAL_FAILURE(InitState());
16768 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
16769 // Allocate a secondary and primary cmd buffer
16770 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
16771 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
16772 command_buffer_allocate_info.commandPool = m_commandPool;
16773 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
16774 command_buffer_allocate_info.commandBufferCount = 1;
16775
16776 VkCommandBuffer secondary_command_buffer;
16777 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
16778 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
16779 VkCommandBuffer primary_command_buffer;
16780 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
16781 VkCommandBufferBeginInfo command_buffer_begin_info = {};
16782 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
16783 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
16784 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
16785 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
16786 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
16787
16788 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
16789 ASSERT_VK_SUCCESS(err);
16790 VkImageObj image(m_device);
16791 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16792 ASSERT_TRUE(image.initialized());
16793 VkImageMemoryBarrier img_barrier = {};
16794 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16795 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16796 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16797 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16798 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16799 img_barrier.image = image.handle();
16800 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16801 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16802 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16803 img_barrier.subresourceRange.baseArrayLayer = 0;
16804 img_barrier.subresourceRange.baseMipLevel = 0;
16805 img_barrier.subresourceRange.layerCount = 1;
16806 img_barrier.subresourceRange.levelCount = 1;
16807 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
16808 0, nullptr, 1, &img_barrier);
16809 err = vkEndCommandBuffer(secondary_command_buffer);
16810 ASSERT_VK_SUCCESS(err);
16811
16812 // Now update primary cmd buffer to execute secondary and transitions image
16813 command_buffer_begin_info.pInheritanceInfo = nullptr;
16814 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
16815 ASSERT_VK_SUCCESS(err);
16816 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
16817 VkImageMemoryBarrier img_barrier2 = {};
16818 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16819 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16820 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16821 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16822 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
16823 img_barrier2.image = image.handle();
16824 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16825 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16826 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16827 img_barrier2.subresourceRange.baseArrayLayer = 0;
16828 img_barrier2.subresourceRange.baseMipLevel = 0;
16829 img_barrier2.subresourceRange.layerCount = 1;
16830 img_barrier2.subresourceRange.levelCount = 1;
16831 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
16832 nullptr, 1, &img_barrier2);
16833 err = vkEndCommandBuffer(primary_command_buffer);
16834 ASSERT_VK_SUCCESS(err);
16835 VkSubmitInfo submit_info = {};
16836 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
16837 submit_info.commandBufferCount = 1;
16838 submit_info.pCommandBuffers = &primary_command_buffer;
16839 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
16840 ASSERT_VK_SUCCESS(err);
16841 m_errorMonitor->VerifyNotFound();
16842 err = vkDeviceWaitIdle(m_device->device());
16843 ASSERT_VK_SUCCESS(err);
16844 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
16845 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
16846}
16847
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016848// This is a positive test. No failures are expected.
16849TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016850 TEST_DESCRIPTION(
16851 "Ensure that the vkUpdateDescriptorSets validation code "
16852 "is ignoring VkWriteDescriptorSet members that are not "
16853 "related to the descriptor type specified by "
16854 "VkWriteDescriptorSet::descriptorType. Correct "
16855 "validation behavior will result in the test running to "
16856 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060016857
16858 const uintptr_t invalid_ptr = 0xcdcdcdcd;
16859
16860 ASSERT_NO_FATAL_FAILURE(InitState());
16861
16862 // Image Case
16863 {
16864 m_errorMonitor->ExpectSuccess();
16865
16866 VkImage image;
16867 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
16868 const int32_t tex_width = 32;
16869 const int32_t tex_height = 32;
16870 VkImageCreateInfo image_create_info = {};
16871 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16872 image_create_info.pNext = NULL;
16873 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16874 image_create_info.format = tex_format;
16875 image_create_info.extent.width = tex_width;
16876 image_create_info.extent.height = tex_height;
16877 image_create_info.extent.depth = 1;
16878 image_create_info.mipLevels = 1;
16879 image_create_info.arrayLayers = 1;
16880 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16881 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16882 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
16883 image_create_info.flags = 0;
16884 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
16885 ASSERT_VK_SUCCESS(err);
16886
16887 VkMemoryRequirements memory_reqs;
16888 VkDeviceMemory image_memory;
16889 bool pass;
16890 VkMemoryAllocateInfo memory_info = {};
16891 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16892 memory_info.pNext = NULL;
16893 memory_info.allocationSize = 0;
16894 memory_info.memoryTypeIndex = 0;
16895 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
16896 memory_info.allocationSize = memory_reqs.size;
16897 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
16898 ASSERT_TRUE(pass);
16899 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
16900 ASSERT_VK_SUCCESS(err);
16901 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
16902 ASSERT_VK_SUCCESS(err);
16903
16904 VkImageViewCreateInfo image_view_create_info = {};
16905 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
16906 image_view_create_info.image = image;
16907 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
16908 image_view_create_info.format = tex_format;
16909 image_view_create_info.subresourceRange.layerCount = 1;
16910 image_view_create_info.subresourceRange.baseMipLevel = 0;
16911 image_view_create_info.subresourceRange.levelCount = 1;
16912 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16913
16914 VkImageView view;
16915 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
16916 ASSERT_VK_SUCCESS(err);
16917
16918 VkDescriptorPoolSize ds_type_count = {};
16919 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16920 ds_type_count.descriptorCount = 1;
16921
16922 VkDescriptorPoolCreateInfo ds_pool_ci = {};
16923 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
16924 ds_pool_ci.pNext = NULL;
16925 ds_pool_ci.maxSets = 1;
16926 ds_pool_ci.poolSizeCount = 1;
16927 ds_pool_ci.pPoolSizes = &ds_type_count;
16928
16929 VkDescriptorPool ds_pool;
16930 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
16931 ASSERT_VK_SUCCESS(err);
16932
16933 VkDescriptorSetLayoutBinding dsl_binding = {};
16934 dsl_binding.binding = 0;
16935 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16936 dsl_binding.descriptorCount = 1;
16937 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
16938 dsl_binding.pImmutableSamplers = NULL;
16939
16940 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
16941 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
16942 ds_layout_ci.pNext = NULL;
16943 ds_layout_ci.bindingCount = 1;
16944 ds_layout_ci.pBindings = &dsl_binding;
16945 VkDescriptorSetLayout ds_layout;
16946 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
16947 ASSERT_VK_SUCCESS(err);
16948
16949 VkDescriptorSet descriptor_set;
16950 VkDescriptorSetAllocateInfo alloc_info = {};
16951 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
16952 alloc_info.descriptorSetCount = 1;
16953 alloc_info.descriptorPool = ds_pool;
16954 alloc_info.pSetLayouts = &ds_layout;
16955 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
16956 ASSERT_VK_SUCCESS(err);
16957
16958 VkDescriptorImageInfo image_info = {};
16959 image_info.imageView = view;
16960 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
16961
16962 VkWriteDescriptorSet descriptor_write;
16963 memset(&descriptor_write, 0, sizeof(descriptor_write));
16964 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
16965 descriptor_write.dstSet = descriptor_set;
16966 descriptor_write.dstBinding = 0;
16967 descriptor_write.descriptorCount = 1;
16968 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
16969 descriptor_write.pImageInfo = &image_info;
16970
16971 // Set pBufferInfo and pTexelBufferView to invalid values, which should
16972 // be
16973 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
16974 // This will most likely produce a crash if the parameter_validation
16975 // layer
16976 // does not correctly ignore pBufferInfo.
16977 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
16978 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
16979
16980 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
16981
16982 m_errorMonitor->VerifyNotFound();
16983
16984 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
16985 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
16986 vkDestroyImageView(m_device->device(), view, NULL);
16987 vkDestroyImage(m_device->device(), image, NULL);
16988 vkFreeMemory(m_device->device(), image_memory, NULL);
16989 }
16990
16991 // Buffer Case
16992 {
16993 m_errorMonitor->ExpectSuccess();
16994
16995 VkBuffer buffer;
16996 uint32_t queue_family_index = 0;
16997 VkBufferCreateInfo buffer_create_info = {};
16998 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
16999 buffer_create_info.size = 1024;
17000 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17001 buffer_create_info.queueFamilyIndexCount = 1;
17002 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17003
17004 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17005 ASSERT_VK_SUCCESS(err);
17006
17007 VkMemoryRequirements memory_reqs;
17008 VkDeviceMemory buffer_memory;
17009 bool pass;
17010 VkMemoryAllocateInfo memory_info = {};
17011 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17012 memory_info.pNext = NULL;
17013 memory_info.allocationSize = 0;
17014 memory_info.memoryTypeIndex = 0;
17015
17016 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17017 memory_info.allocationSize = memory_reqs.size;
17018 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17019 ASSERT_TRUE(pass);
17020
17021 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17022 ASSERT_VK_SUCCESS(err);
17023 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17024 ASSERT_VK_SUCCESS(err);
17025
17026 VkDescriptorPoolSize ds_type_count = {};
17027 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17028 ds_type_count.descriptorCount = 1;
17029
17030 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17031 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17032 ds_pool_ci.pNext = NULL;
17033 ds_pool_ci.maxSets = 1;
17034 ds_pool_ci.poolSizeCount = 1;
17035 ds_pool_ci.pPoolSizes = &ds_type_count;
17036
17037 VkDescriptorPool ds_pool;
17038 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17039 ASSERT_VK_SUCCESS(err);
17040
17041 VkDescriptorSetLayoutBinding dsl_binding = {};
17042 dsl_binding.binding = 0;
17043 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17044 dsl_binding.descriptorCount = 1;
17045 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17046 dsl_binding.pImmutableSamplers = NULL;
17047
17048 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17049 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17050 ds_layout_ci.pNext = NULL;
17051 ds_layout_ci.bindingCount = 1;
17052 ds_layout_ci.pBindings = &dsl_binding;
17053 VkDescriptorSetLayout ds_layout;
17054 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17055 ASSERT_VK_SUCCESS(err);
17056
17057 VkDescriptorSet descriptor_set;
17058 VkDescriptorSetAllocateInfo alloc_info = {};
17059 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17060 alloc_info.descriptorSetCount = 1;
17061 alloc_info.descriptorPool = ds_pool;
17062 alloc_info.pSetLayouts = &ds_layout;
17063 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17064 ASSERT_VK_SUCCESS(err);
17065
17066 VkDescriptorBufferInfo buffer_info = {};
17067 buffer_info.buffer = buffer;
17068 buffer_info.offset = 0;
17069 buffer_info.range = 1024;
17070
17071 VkWriteDescriptorSet descriptor_write;
17072 memset(&descriptor_write, 0, sizeof(descriptor_write));
17073 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17074 descriptor_write.dstSet = descriptor_set;
17075 descriptor_write.dstBinding = 0;
17076 descriptor_write.descriptorCount = 1;
17077 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17078 descriptor_write.pBufferInfo = &buffer_info;
17079
17080 // Set pImageInfo and pTexelBufferView to invalid values, which should
17081 // be
17082 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
17083 // This will most likely produce a crash if the parameter_validation
17084 // layer
17085 // does not correctly ignore pImageInfo.
17086 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17087 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17088
17089 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17090
17091 m_errorMonitor->VerifyNotFound();
17092
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017093 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17094 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17095 vkDestroyBuffer(m_device->device(), buffer, NULL);
17096 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17097 }
17098
17099 // Texel Buffer Case
17100 {
17101 m_errorMonitor->ExpectSuccess();
17102
17103 VkBuffer buffer;
17104 uint32_t queue_family_index = 0;
17105 VkBufferCreateInfo buffer_create_info = {};
17106 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17107 buffer_create_info.size = 1024;
17108 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
17109 buffer_create_info.queueFamilyIndexCount = 1;
17110 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
17111
17112 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
17113 ASSERT_VK_SUCCESS(err);
17114
17115 VkMemoryRequirements memory_reqs;
17116 VkDeviceMemory buffer_memory;
17117 bool pass;
17118 VkMemoryAllocateInfo memory_info = {};
17119 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17120 memory_info.pNext = NULL;
17121 memory_info.allocationSize = 0;
17122 memory_info.memoryTypeIndex = 0;
17123
17124 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
17125 memory_info.allocationSize = memory_reqs.size;
17126 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17127 ASSERT_TRUE(pass);
17128
17129 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
17130 ASSERT_VK_SUCCESS(err);
17131 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
17132 ASSERT_VK_SUCCESS(err);
17133
17134 VkBufferViewCreateInfo buff_view_ci = {};
17135 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
17136 buff_view_ci.buffer = buffer;
17137 buff_view_ci.format = VK_FORMAT_R8_UNORM;
17138 buff_view_ci.range = VK_WHOLE_SIZE;
17139 VkBufferView buffer_view;
17140 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
17141
17142 VkDescriptorPoolSize ds_type_count = {};
17143 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17144 ds_type_count.descriptorCount = 1;
17145
17146 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17147 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17148 ds_pool_ci.pNext = NULL;
17149 ds_pool_ci.maxSets = 1;
17150 ds_pool_ci.poolSizeCount = 1;
17151 ds_pool_ci.pPoolSizes = &ds_type_count;
17152
17153 VkDescriptorPool ds_pool;
17154 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17155 ASSERT_VK_SUCCESS(err);
17156
17157 VkDescriptorSetLayoutBinding dsl_binding = {};
17158 dsl_binding.binding = 0;
17159 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17160 dsl_binding.descriptorCount = 1;
17161 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17162 dsl_binding.pImmutableSamplers = NULL;
17163
17164 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17165 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17166 ds_layout_ci.pNext = NULL;
17167 ds_layout_ci.bindingCount = 1;
17168 ds_layout_ci.pBindings = &dsl_binding;
17169 VkDescriptorSetLayout ds_layout;
17170 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17171 ASSERT_VK_SUCCESS(err);
17172
17173 VkDescriptorSet descriptor_set;
17174 VkDescriptorSetAllocateInfo alloc_info = {};
17175 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17176 alloc_info.descriptorSetCount = 1;
17177 alloc_info.descriptorPool = ds_pool;
17178 alloc_info.pSetLayouts = &ds_layout;
17179 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17180 ASSERT_VK_SUCCESS(err);
17181
17182 VkWriteDescriptorSet descriptor_write;
17183 memset(&descriptor_write, 0, sizeof(descriptor_write));
17184 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17185 descriptor_write.dstSet = descriptor_set;
17186 descriptor_write.dstBinding = 0;
17187 descriptor_write.descriptorCount = 1;
17188 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
17189 descriptor_write.pTexelBufferView = &buffer_view;
17190
17191 // Set pImageInfo and pBufferInfo to invalid values, which should be
17192 // ignored for descriptorType ==
17193 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
17194 // This will most likely produce a crash if the parameter_validation
17195 // layer
17196 // does not correctly ignore pImageInfo and pBufferInfo.
17197 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
17198 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17199
17200 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17201
17202 m_errorMonitor->VerifyNotFound();
17203
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017204 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17205 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17206 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
17207 vkDestroyBuffer(m_device->device(), buffer, NULL);
17208 vkFreeMemory(m_device->device(), buffer_memory, NULL);
17209 }
17210}
17211
Tobin Ehlisf7428442016-10-25 07:58:24 -060017212TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
17213 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
17214
17215 ASSERT_NO_FATAL_FAILURE(InitState());
17216 // Create layout where two binding #s are "1"
17217 static const uint32_t NUM_BINDINGS = 3;
17218 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17219 dsl_binding[0].binding = 1;
17220 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17221 dsl_binding[0].descriptorCount = 1;
17222 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17223 dsl_binding[0].pImmutableSamplers = NULL;
17224 dsl_binding[1].binding = 0;
17225 dsl_binding[1].descriptorCount = 1;
17226 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17227 dsl_binding[1].descriptorCount = 1;
17228 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17229 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017230 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060017231 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17232 dsl_binding[2].descriptorCount = 1;
17233 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17234 dsl_binding[2].pImmutableSamplers = NULL;
17235
17236 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17237 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17238 ds_layout_ci.pNext = NULL;
17239 ds_layout_ci.bindingCount = NUM_BINDINGS;
17240 ds_layout_ci.pBindings = dsl_binding;
17241 VkDescriptorSetLayout ds_layout;
17242 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
17243 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17244 m_errorMonitor->VerifyFound();
17245}
17246
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017247TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017248 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
17249
17250 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017251
Tony Barbour552f6c02016-12-21 14:34:07 -070017252 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017253
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060017254 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
17255
17256 {
17257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
17258 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
17259 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17260 m_errorMonitor->VerifyFound();
17261 }
17262
17263 {
17264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
17265 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
17266 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17267 m_errorMonitor->VerifyFound();
17268 }
17269
17270 {
17271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17272 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
17273 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17274 m_errorMonitor->VerifyFound();
17275 }
17276
17277 {
17278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
17279 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
17280 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17281 m_errorMonitor->VerifyFound();
17282 }
17283
17284 {
17285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
17286 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
17287 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17288 m_errorMonitor->VerifyFound();
17289 }
17290
17291 {
17292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
17293 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
17294 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
17295 m_errorMonitor->VerifyFound();
17296 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017297
17298 {
17299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17300 VkRect2D scissor = {{-1, 0}, {16, 16}};
17301 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17302 m_errorMonitor->VerifyFound();
17303 }
17304
17305 {
17306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
17307 VkRect2D scissor = {{0, -2}, {16, 16}};
17308 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17309 m_errorMonitor->VerifyFound();
17310 }
17311
17312 {
17313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
17314 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
17315 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17316 m_errorMonitor->VerifyFound();
17317 }
17318
17319 {
17320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
17321 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
17322 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
17323 m_errorMonitor->VerifyFound();
17324 }
17325
Tony Barbour552f6c02016-12-21 14:34:07 -070017326 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060017327}
17328
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017329// This is a positive test. No failures are expected.
17330TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
17331 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
17332 VkResult err;
17333
17334 ASSERT_NO_FATAL_FAILURE(InitState());
17335 m_errorMonitor->ExpectSuccess();
17336 VkDescriptorPoolSize ds_type_count = {};
17337 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17338 ds_type_count.descriptorCount = 2;
17339
17340 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17341 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17342 ds_pool_ci.pNext = NULL;
17343 ds_pool_ci.maxSets = 1;
17344 ds_pool_ci.poolSizeCount = 1;
17345 ds_pool_ci.pPoolSizes = &ds_type_count;
17346
17347 VkDescriptorPool ds_pool;
17348 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17349 ASSERT_VK_SUCCESS(err);
17350
17351 // Create layout with two uniform buffer descriptors w/ empty binding between them
17352 static const uint32_t NUM_BINDINGS = 3;
17353 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
17354 dsl_binding[0].binding = 0;
17355 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17356 dsl_binding[0].descriptorCount = 1;
17357 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
17358 dsl_binding[0].pImmutableSamplers = NULL;
17359 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017360 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017361 dsl_binding[2].binding = 2;
17362 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17363 dsl_binding[2].descriptorCount = 1;
17364 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
17365 dsl_binding[2].pImmutableSamplers = NULL;
17366
17367 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17368 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17369 ds_layout_ci.pNext = NULL;
17370 ds_layout_ci.bindingCount = NUM_BINDINGS;
17371 ds_layout_ci.pBindings = dsl_binding;
17372 VkDescriptorSetLayout ds_layout;
17373 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17374 ASSERT_VK_SUCCESS(err);
17375
17376 VkDescriptorSet descriptor_set = {};
17377 VkDescriptorSetAllocateInfo alloc_info = {};
17378 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17379 alloc_info.descriptorSetCount = 1;
17380 alloc_info.descriptorPool = ds_pool;
17381 alloc_info.pSetLayouts = &ds_layout;
17382 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17383 ASSERT_VK_SUCCESS(err);
17384
17385 // Create a buffer to be used for update
17386 VkBufferCreateInfo buff_ci = {};
17387 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17388 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17389 buff_ci.size = 256;
17390 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17391 VkBuffer buffer;
17392 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
17393 ASSERT_VK_SUCCESS(err);
17394 // Have to bind memory to buffer before descriptor update
17395 VkMemoryAllocateInfo mem_alloc = {};
17396 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17397 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017398 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017399 mem_alloc.memoryTypeIndex = 0;
17400
17401 VkMemoryRequirements mem_reqs;
17402 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17403 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
17404 if (!pass) {
17405 vkDestroyBuffer(m_device->device(), buffer, NULL);
17406 return;
17407 }
17408
17409 VkDeviceMemory mem;
17410 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
17411 ASSERT_VK_SUCCESS(err);
17412 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17413 ASSERT_VK_SUCCESS(err);
17414
17415 // Only update the descriptor at binding 2
17416 VkDescriptorBufferInfo buff_info = {};
17417 buff_info.buffer = buffer;
17418 buff_info.offset = 0;
17419 buff_info.range = VK_WHOLE_SIZE;
17420 VkWriteDescriptorSet descriptor_write = {};
17421 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17422 descriptor_write.dstBinding = 2;
17423 descriptor_write.descriptorCount = 1;
17424 descriptor_write.pTexelBufferView = nullptr;
17425 descriptor_write.pBufferInfo = &buff_info;
17426 descriptor_write.pImageInfo = nullptr;
17427 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
17428 descriptor_write.dstSet = descriptor_set;
17429
17430 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17431
17432 m_errorMonitor->VerifyNotFound();
17433 // Cleanup
17434 vkFreeMemory(m_device->device(), mem, NULL);
17435 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17436 vkDestroyBuffer(m_device->device(), buffer, NULL);
17437 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17438}
17439
17440// This is a positive test. No failures are expected.
17441TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
17442 VkResult err;
17443 bool pass;
17444
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017445 TEST_DESCRIPTION(
17446 "Create a buffer, allocate memory, bind memory, destroy "
17447 "the buffer, create an image, and bind the same memory to "
17448 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017449
17450 m_errorMonitor->ExpectSuccess();
17451
17452 ASSERT_NO_FATAL_FAILURE(InitState());
17453
17454 VkBuffer buffer;
17455 VkImage image;
17456 VkDeviceMemory mem;
17457 VkMemoryRequirements mem_reqs;
17458
17459 VkBufferCreateInfo buf_info = {};
17460 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17461 buf_info.pNext = NULL;
17462 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17463 buf_info.size = 256;
17464 buf_info.queueFamilyIndexCount = 0;
17465 buf_info.pQueueFamilyIndices = NULL;
17466 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17467 buf_info.flags = 0;
17468 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
17469 ASSERT_VK_SUCCESS(err);
17470
17471 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
17472
17473 VkMemoryAllocateInfo alloc_info = {};
17474 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17475 alloc_info.pNext = NULL;
17476 alloc_info.memoryTypeIndex = 0;
17477
17478 // Ensure memory is big enough for both bindings
17479 alloc_info.allocationSize = 0x10000;
17480
17481 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17482 if (!pass) {
17483 vkDestroyBuffer(m_device->device(), buffer, NULL);
17484 return;
17485 }
17486
17487 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17488 ASSERT_VK_SUCCESS(err);
17489
17490 uint8_t *pData;
17491 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
17492 ASSERT_VK_SUCCESS(err);
17493
17494 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
17495
17496 vkUnmapMemory(m_device->device(), mem);
17497
17498 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
17499 ASSERT_VK_SUCCESS(err);
17500
17501 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
17502 // memory. In fact, it was never used by the GPU.
17503 // Just be be sure, wait for idle.
17504 vkDestroyBuffer(m_device->device(), buffer, NULL);
17505 vkDeviceWaitIdle(m_device->device());
17506
Tobin Ehlis6a005702016-12-28 15:25:56 -070017507 // Use optimal as some platforms report linear support but then fail image creation
17508 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
17509 VkImageFormatProperties image_format_properties;
17510 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
17511 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
17512 if (image_format_properties.maxExtent.width == 0) {
17513 printf("Image format not supported; skipped.\n");
17514 vkFreeMemory(m_device->device(), mem, NULL);
17515 return;
17516 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017517 VkImageCreateInfo image_create_info = {};
17518 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17519 image_create_info.pNext = NULL;
17520 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17521 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
17522 image_create_info.extent.width = 64;
17523 image_create_info.extent.height = 64;
17524 image_create_info.extent.depth = 1;
17525 image_create_info.mipLevels = 1;
17526 image_create_info.arrayLayers = 1;
17527 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070017528 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017529 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
17530 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17531 image_create_info.queueFamilyIndexCount = 0;
17532 image_create_info.pQueueFamilyIndices = NULL;
17533 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
17534 image_create_info.flags = 0;
17535
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017536 /* Create a mappable image. It will be the texture if linear images are ok
17537 * to be textures or it will be the staging image if they are not.
17538 */
17539 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17540 ASSERT_VK_SUCCESS(err);
17541
17542 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
17543
Tobin Ehlis6a005702016-12-28 15:25:56 -070017544 VkMemoryAllocateInfo mem_alloc = {};
17545 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17546 mem_alloc.pNext = NULL;
17547 mem_alloc.allocationSize = 0;
17548 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017549 mem_alloc.allocationSize = mem_reqs.size;
17550
17551 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
17552 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070017553 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017554 vkDestroyImage(m_device->device(), image, NULL);
17555 return;
17556 }
17557
17558 // VALIDATION FAILURE:
17559 err = vkBindImageMemory(m_device->device(), image, mem, 0);
17560 ASSERT_VK_SUCCESS(err);
17561
17562 m_errorMonitor->VerifyNotFound();
17563
17564 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017565 vkDestroyImage(m_device->device(), image, NULL);
17566}
17567
Tony Barbourab713912017-02-02 14:17:35 -070017568// This is a positive test. No failures are expected.
17569TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
17570 VkResult err;
17571
17572 TEST_DESCRIPTION(
17573 "Call all applicable destroy and free routines with NULL"
17574 "handles, expecting no validation errors");
17575
17576 m_errorMonitor->ExpectSuccess();
17577
17578 ASSERT_NO_FATAL_FAILURE(InitState());
17579 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
17580 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
17581 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
17582 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
17583 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
17584 vkDestroyDevice(VK_NULL_HANDLE, NULL);
17585 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
17586 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
17587 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
17588 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
17589 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
17590 vkDestroyInstance(VK_NULL_HANDLE, NULL);
17591 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
17592 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
17593 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
17594 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
17595 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
17596 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
17597 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
17598 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
17599
17600 VkCommandPool command_pool;
17601 VkCommandPoolCreateInfo pool_create_info{};
17602 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
17603 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
17604 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
17605 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
17606 VkCommandBuffer command_buffers[3] = {};
17607 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
17608 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17609 command_buffer_allocate_info.commandPool = command_pool;
17610 command_buffer_allocate_info.commandBufferCount = 1;
17611 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17612 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
17613 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
17614 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
17615
17616 VkDescriptorPoolSize ds_type_count = {};
17617 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17618 ds_type_count.descriptorCount = 1;
17619
17620 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17621 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17622 ds_pool_ci.pNext = NULL;
17623 ds_pool_ci.maxSets = 1;
17624 ds_pool_ci.poolSizeCount = 1;
17625 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
17626 ds_pool_ci.pPoolSizes = &ds_type_count;
17627
17628 VkDescriptorPool ds_pool;
17629 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17630 ASSERT_VK_SUCCESS(err);
17631
17632 VkDescriptorSetLayoutBinding dsl_binding = {};
17633 dsl_binding.binding = 2;
17634 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17635 dsl_binding.descriptorCount = 1;
17636 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17637 dsl_binding.pImmutableSamplers = NULL;
17638 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17639 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17640 ds_layout_ci.pNext = NULL;
17641 ds_layout_ci.bindingCount = 1;
17642 ds_layout_ci.pBindings = &dsl_binding;
17643 VkDescriptorSetLayout ds_layout;
17644 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17645 ASSERT_VK_SUCCESS(err);
17646
17647 VkDescriptorSet descriptor_sets[3] = {};
17648 VkDescriptorSetAllocateInfo alloc_info = {};
17649 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17650 alloc_info.descriptorSetCount = 1;
17651 alloc_info.descriptorPool = ds_pool;
17652 alloc_info.pSetLayouts = &ds_layout;
17653 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
17654 ASSERT_VK_SUCCESS(err);
17655 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
17656 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17657 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17658
17659 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
17660
17661 m_errorMonitor->VerifyNotFound();
17662}
17663
Tobin Ehlis953e8392016-11-17 10:54:13 -070017664TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
17665 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
17666 // We previously had a bug where dynamic offset of inactive bindings was still being used
17667 VkResult err;
17668 m_errorMonitor->ExpectSuccess();
17669
17670 ASSERT_NO_FATAL_FAILURE(InitState());
17671 ASSERT_NO_FATAL_FAILURE(InitViewport());
17672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17673
17674 VkDescriptorPoolSize ds_type_count = {};
17675 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17676 ds_type_count.descriptorCount = 3;
17677
17678 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17679 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17680 ds_pool_ci.pNext = NULL;
17681 ds_pool_ci.maxSets = 1;
17682 ds_pool_ci.poolSizeCount = 1;
17683 ds_pool_ci.pPoolSizes = &ds_type_count;
17684
17685 VkDescriptorPool ds_pool;
17686 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17687 ASSERT_VK_SUCCESS(err);
17688
17689 const uint32_t BINDING_COUNT = 3;
17690 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017691 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017692 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17693 dsl_binding[0].descriptorCount = 1;
17694 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17695 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017696 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017697 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17698 dsl_binding[1].descriptorCount = 1;
17699 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17700 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070017701 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070017702 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17703 dsl_binding[2].descriptorCount = 1;
17704 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
17705 dsl_binding[2].pImmutableSamplers = NULL;
17706
17707 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17708 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17709 ds_layout_ci.pNext = NULL;
17710 ds_layout_ci.bindingCount = BINDING_COUNT;
17711 ds_layout_ci.pBindings = dsl_binding;
17712 VkDescriptorSetLayout ds_layout;
17713 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17714 ASSERT_VK_SUCCESS(err);
17715
17716 VkDescriptorSet descriptor_set;
17717 VkDescriptorSetAllocateInfo alloc_info = {};
17718 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17719 alloc_info.descriptorSetCount = 1;
17720 alloc_info.descriptorPool = ds_pool;
17721 alloc_info.pSetLayouts = &ds_layout;
17722 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17723 ASSERT_VK_SUCCESS(err);
17724
17725 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
17726 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
17727 pipeline_layout_ci.pNext = NULL;
17728 pipeline_layout_ci.setLayoutCount = 1;
17729 pipeline_layout_ci.pSetLayouts = &ds_layout;
17730
17731 VkPipelineLayout pipeline_layout;
17732 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
17733 ASSERT_VK_SUCCESS(err);
17734
17735 // Create two buffers to update the descriptors with
17736 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
17737 uint32_t qfi = 0;
17738 VkBufferCreateInfo buffCI = {};
17739 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
17740 buffCI.size = 2048;
17741 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
17742 buffCI.queueFamilyIndexCount = 1;
17743 buffCI.pQueueFamilyIndices = &qfi;
17744
17745 VkBuffer dyub1;
17746 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
17747 ASSERT_VK_SUCCESS(err);
17748 // buffer2
17749 buffCI.size = 1024;
17750 VkBuffer dyub2;
17751 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
17752 ASSERT_VK_SUCCESS(err);
17753 // Allocate memory and bind to buffers
17754 VkMemoryAllocateInfo mem_alloc[2] = {};
17755 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17756 mem_alloc[0].pNext = NULL;
17757 mem_alloc[0].memoryTypeIndex = 0;
17758 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17759 mem_alloc[1].pNext = NULL;
17760 mem_alloc[1].memoryTypeIndex = 0;
17761
17762 VkMemoryRequirements mem_reqs1;
17763 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
17764 VkMemoryRequirements mem_reqs2;
17765 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
17766 mem_alloc[0].allocationSize = mem_reqs1.size;
17767 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
17768 mem_alloc[1].allocationSize = mem_reqs2.size;
17769 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
17770 if (!pass) {
17771 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17772 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17773 return;
17774 }
17775
17776 VkDeviceMemory mem1;
17777 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
17778 ASSERT_VK_SUCCESS(err);
17779 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
17780 ASSERT_VK_SUCCESS(err);
17781 VkDeviceMemory mem2;
17782 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
17783 ASSERT_VK_SUCCESS(err);
17784 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
17785 ASSERT_VK_SUCCESS(err);
17786 // Update descriptors
17787 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
17788 buff_info[0].buffer = dyub1;
17789 buff_info[0].offset = 0;
17790 buff_info[0].range = 256;
17791 buff_info[1].buffer = dyub1;
17792 buff_info[1].offset = 256;
17793 buff_info[1].range = 512;
17794 buff_info[2].buffer = dyub2;
17795 buff_info[2].offset = 0;
17796 buff_info[2].range = 512;
17797
17798 VkWriteDescriptorSet descriptor_write;
17799 memset(&descriptor_write, 0, sizeof(descriptor_write));
17800 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17801 descriptor_write.dstSet = descriptor_set;
17802 descriptor_write.dstBinding = 0;
17803 descriptor_write.descriptorCount = BINDING_COUNT;
17804 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
17805 descriptor_write.pBufferInfo = buff_info;
17806
17807 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17808
Tony Barbour552f6c02016-12-21 14:34:07 -070017809 m_commandBuffer->BeginCommandBuffer();
17810 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070017811
17812 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017813 char const *vsSource =
17814 "#version 450\n"
17815 "\n"
17816 "out gl_PerVertex { \n"
17817 " vec4 gl_Position;\n"
17818 "};\n"
17819 "void main(){\n"
17820 " gl_Position = vec4(1);\n"
17821 "}\n";
17822 char const *fsSource =
17823 "#version 450\n"
17824 "\n"
17825 "layout(location=0) out vec4 x;\n"
17826 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
17827 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
17828 "void main(){\n"
17829 " x = vec4(bar1.y) + vec4(bar2.y);\n"
17830 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070017831 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
17832 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
17833 VkPipelineObj pipe(m_device);
17834 pipe.SetViewport(m_viewports);
17835 pipe.SetScissor(m_scissors);
17836 pipe.AddShader(&vs);
17837 pipe.AddShader(&fs);
17838 pipe.AddColorAttachment();
17839 pipe.CreateVKPipeline(pipeline_layout, renderPass());
17840
17841 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
17842 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
17843 // we used to have a bug in this case.
17844 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
17845 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
17846 &descriptor_set, BINDING_COUNT, dyn_off);
17847 Draw(1, 0, 0, 0);
17848 m_errorMonitor->VerifyNotFound();
17849
17850 vkDestroyBuffer(m_device->device(), dyub1, NULL);
17851 vkDestroyBuffer(m_device->device(), dyub2, NULL);
17852 vkFreeMemory(m_device->device(), mem1, NULL);
17853 vkFreeMemory(m_device->device(), mem2, NULL);
17854
17855 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
17856 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17857 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17858}
17859
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017860TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017861 TEST_DESCRIPTION(
17862 "Ensure that validations handling of non-coherent memory "
17863 "mapping while using VK_WHOLE_SIZE does not cause access "
17864 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017865 VkResult err;
17866 uint8_t *pData;
17867 ASSERT_NO_FATAL_FAILURE(InitState());
17868
17869 VkDeviceMemory mem;
17870 VkMemoryRequirements mem_reqs;
17871 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017872 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017873 VkMemoryAllocateInfo alloc_info = {};
17874 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17875 alloc_info.pNext = NULL;
17876 alloc_info.memoryTypeIndex = 0;
17877
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017878 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017879 alloc_info.allocationSize = allocation_size;
17880
17881 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
17882 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 -070017883 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017884 if (!pass) {
17885 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017886 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
17887 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017888 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017889 pass = m_device->phy().set_memory_type(
17890 mem_reqs.memoryTypeBits, &alloc_info,
17891 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
17892 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017893 if (!pass) {
17894 return;
17895 }
17896 }
17897 }
17898
17899 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
17900 ASSERT_VK_SUCCESS(err);
17901
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017902 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017903 m_errorMonitor->ExpectSuccess();
17904 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17905 ASSERT_VK_SUCCESS(err);
17906 VkMappedMemoryRange mmr = {};
17907 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17908 mmr.memory = mem;
17909 mmr.offset = 0;
17910 mmr.size = VK_WHOLE_SIZE;
17911 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17912 ASSERT_VK_SUCCESS(err);
17913 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17914 ASSERT_VK_SUCCESS(err);
17915 m_errorMonitor->VerifyNotFound();
17916 vkUnmapMemory(m_device->device(), mem);
17917
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017918 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017919 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017920 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017921 ASSERT_VK_SUCCESS(err);
17922 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17923 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017924 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017925 mmr.size = VK_WHOLE_SIZE;
17926 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17927 ASSERT_VK_SUCCESS(err);
17928 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17929 ASSERT_VK_SUCCESS(err);
17930 m_errorMonitor->VerifyNotFound();
17931 vkUnmapMemory(m_device->device(), mem);
17932
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017933 // Map with offset and size
17934 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017935 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017936 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017937 ASSERT_VK_SUCCESS(err);
17938 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17939 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017940 mmr.offset = 4 * atom_size;
17941 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017942 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17943 ASSERT_VK_SUCCESS(err);
17944 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
17945 ASSERT_VK_SUCCESS(err);
17946 m_errorMonitor->VerifyNotFound();
17947 vkUnmapMemory(m_device->device(), mem);
17948
17949 // Map without offset and flush WHOLE_SIZE with two separate offsets
17950 m_errorMonitor->ExpectSuccess();
17951 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
17952 ASSERT_VK_SUCCESS(err);
17953 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
17954 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017955 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017956 mmr.size = VK_WHOLE_SIZE;
17957 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17958 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070017959 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017960 mmr.size = VK_WHOLE_SIZE;
17961 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
17962 ASSERT_VK_SUCCESS(err);
17963 m_errorMonitor->VerifyNotFound();
17964 vkUnmapMemory(m_device->device(), mem);
17965
17966 vkFreeMemory(m_device->device(), mem, NULL);
17967}
17968
17969// This is a positive test. We used to expect error in this case but spec now allows it
17970TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
17971 m_errorMonitor->ExpectSuccess();
17972 vk_testing::Fence testFence;
17973 VkFenceCreateInfo fenceInfo = {};
17974 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
17975 fenceInfo.pNext = NULL;
17976
17977 ASSERT_NO_FATAL_FAILURE(InitState());
17978 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017979 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017980 VkResult result = vkResetFences(m_device->device(), 1, fences);
17981 ASSERT_VK_SUCCESS(result);
17982
17983 m_errorMonitor->VerifyNotFound();
17984}
17985
17986TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
17987 m_errorMonitor->ExpectSuccess();
17988
17989 ASSERT_NO_FATAL_FAILURE(InitState());
17990 VkResult err;
17991
17992 // Record (empty!) command buffer that can be submitted multiple times
17993 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017994 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
17995 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017996 m_commandBuffer->BeginCommandBuffer(&cbbi);
17997 m_commandBuffer->EndCommandBuffer();
17998
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017999 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018000 VkFence fence;
18001 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
18002 ASSERT_VK_SUCCESS(err);
18003
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018004 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018005 VkSemaphore s1, s2;
18006 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
18007 ASSERT_VK_SUCCESS(err);
18008 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
18009 ASSERT_VK_SUCCESS(err);
18010
18011 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018012 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018013 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
18014 ASSERT_VK_SUCCESS(err);
18015
18016 // Submit CB again, signaling s2.
18017 si.pSignalSemaphores = &s2;
18018 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
18019 ASSERT_VK_SUCCESS(err);
18020
18021 // Wait for fence.
18022 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18023 ASSERT_VK_SUCCESS(err);
18024
18025 // CB is still in flight from second submission, but semaphore s1 is no
18026 // longer in flight. delete it.
18027 vkDestroySemaphore(m_device->device(), s1, nullptr);
18028
18029 m_errorMonitor->VerifyNotFound();
18030
18031 // Force device idle and clean up remaining objects
18032 vkDeviceWaitIdle(m_device->device());
18033 vkDestroySemaphore(m_device->device(), s2, nullptr);
18034 vkDestroyFence(m_device->device(), fence, nullptr);
18035}
18036
18037TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
18038 m_errorMonitor->ExpectSuccess();
18039
18040 ASSERT_NO_FATAL_FAILURE(InitState());
18041 VkResult err;
18042
18043 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018044 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018045 VkFence f1;
18046 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
18047 ASSERT_VK_SUCCESS(err);
18048
18049 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018050 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018051 VkFence f2;
18052 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
18053 ASSERT_VK_SUCCESS(err);
18054
18055 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018056 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018057 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
18058
18059 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018060 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018061 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
18062
18063 // Should have both retired!
18064 vkDestroyFence(m_device->device(), f1, nullptr);
18065 vkDestroyFence(m_device->device(), f2, nullptr);
18066
18067 m_errorMonitor->VerifyNotFound();
18068}
18069
18070TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018071 TEST_DESCRIPTION(
18072 "Verify that creating an image view from an image with valid usage "
18073 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018074
18075 ASSERT_NO_FATAL_FAILURE(InitState());
18076
18077 m_errorMonitor->ExpectSuccess();
18078 // Verify that we can create a view with usage INPUT_ATTACHMENT
18079 VkImageObj image(m_device);
18080 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18081 ASSERT_TRUE(image.initialized());
18082 VkImageView imageView;
18083 VkImageViewCreateInfo ivci = {};
18084 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18085 ivci.image = image.handle();
18086 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
18087 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
18088 ivci.subresourceRange.layerCount = 1;
18089 ivci.subresourceRange.baseMipLevel = 0;
18090 ivci.subresourceRange.levelCount = 1;
18091 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18092
18093 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
18094 m_errorMonitor->VerifyNotFound();
18095 vkDestroyImageView(m_device->device(), imageView, NULL);
18096}
18097
18098// This is a positive test. No failures are expected.
18099TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018100 TEST_DESCRIPTION(
18101 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
18102 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018103
18104 ASSERT_NO_FATAL_FAILURE(InitState());
18105
18106 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018107 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018108
18109 m_errorMonitor->ExpectSuccess();
18110
18111 VkImage image;
18112 VkImageCreateInfo image_create_info = {};
18113 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18114 image_create_info.pNext = NULL;
18115 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18116 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
18117 image_create_info.extent.width = 64;
18118 image_create_info.extent.height = 64;
18119 image_create_info.extent.depth = 1;
18120 image_create_info.mipLevels = 1;
18121 image_create_info.arrayLayers = 1;
18122 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18123 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18124 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
18125 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
18126 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18127 ASSERT_VK_SUCCESS(err);
18128
18129 VkMemoryRequirements memory_reqs;
18130 VkDeviceMemory memory_one, memory_two;
18131 bool pass;
18132 VkMemoryAllocateInfo memory_info = {};
18133 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18134 memory_info.pNext = NULL;
18135 memory_info.allocationSize = 0;
18136 memory_info.memoryTypeIndex = 0;
18137 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18138 // Find an image big enough to allow sparse mapping of 2 memory regions
18139 // Increase the image size until it is at least twice the
18140 // size of the required alignment, to ensure we can bind both
18141 // allocated memory blocks to the image on aligned offsets.
18142 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
18143 vkDestroyImage(m_device->device(), image, nullptr);
18144 image_create_info.extent.width *= 2;
18145 image_create_info.extent.height *= 2;
18146 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
18147 ASSERT_VK_SUCCESS(err);
18148 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18149 }
18150 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
18151 // at the end of the first
18152 memory_info.allocationSize = memory_reqs.alignment;
18153 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18154 ASSERT_TRUE(pass);
18155 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
18156 ASSERT_VK_SUCCESS(err);
18157 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
18158 ASSERT_VK_SUCCESS(err);
18159 VkSparseMemoryBind binds[2];
18160 binds[0].flags = 0;
18161 binds[0].memory = memory_one;
18162 binds[0].memoryOffset = 0;
18163 binds[0].resourceOffset = 0;
18164 binds[0].size = memory_info.allocationSize;
18165 binds[1].flags = 0;
18166 binds[1].memory = memory_two;
18167 binds[1].memoryOffset = 0;
18168 binds[1].resourceOffset = memory_info.allocationSize;
18169 binds[1].size = memory_info.allocationSize;
18170
18171 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
18172 opaqueBindInfo.image = image;
18173 opaqueBindInfo.bindCount = 2;
18174 opaqueBindInfo.pBinds = binds;
18175
18176 VkFence fence = VK_NULL_HANDLE;
18177 VkBindSparseInfo bindSparseInfo = {};
18178 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
18179 bindSparseInfo.imageOpaqueBindCount = 1;
18180 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
18181
18182 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
18183 vkQueueWaitIdle(m_device->m_queue);
18184 vkDestroyImage(m_device->device(), image, NULL);
18185 vkFreeMemory(m_device->device(), memory_one, NULL);
18186 vkFreeMemory(m_device->device(), memory_two, NULL);
18187 m_errorMonitor->VerifyNotFound();
18188}
18189
18190TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018191 TEST_DESCRIPTION(
18192 "Ensure that CmdBeginRenderPass with an attachment's "
18193 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
18194 "the command buffer has prior knowledge of that "
18195 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018196
18197 m_errorMonitor->ExpectSuccess();
18198
18199 ASSERT_NO_FATAL_FAILURE(InitState());
18200
18201 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018202 VkAttachmentDescription attachment = {0,
18203 VK_FORMAT_R8G8B8A8_UNORM,
18204 VK_SAMPLE_COUNT_1_BIT,
18205 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18206 VK_ATTACHMENT_STORE_OP_STORE,
18207 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18208 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18209 VK_IMAGE_LAYOUT_UNDEFINED,
18210 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018211
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018212 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018213
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018214 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018215
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018216 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018217
18218 VkRenderPass rp;
18219 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18220 ASSERT_VK_SUCCESS(err);
18221
18222 // A compatible framebuffer.
18223 VkImageObj image(m_device);
18224 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18225 ASSERT_TRUE(image.initialized());
18226
18227 VkImageViewCreateInfo ivci = {
18228 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18229 nullptr,
18230 0,
18231 image.handle(),
18232 VK_IMAGE_VIEW_TYPE_2D,
18233 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018234 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18235 VK_COMPONENT_SWIZZLE_IDENTITY},
18236 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018237 };
18238 VkImageView view;
18239 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18240 ASSERT_VK_SUCCESS(err);
18241
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018242 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018243 VkFramebuffer fb;
18244 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18245 ASSERT_VK_SUCCESS(err);
18246
18247 // Record a single command buffer which uses this renderpass twice. The
18248 // bug is triggered at the beginning of the second renderpass, when the
18249 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018250 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 -070018251 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018252 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18253 vkCmdEndRenderPass(m_commandBuffer->handle());
18254 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18255
18256 m_errorMonitor->VerifyNotFound();
18257
18258 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018259 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018260
18261 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18262 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18263 vkDestroyImageView(m_device->device(), view, nullptr);
18264}
18265
18266TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018267 TEST_DESCRIPTION(
18268 "This test should pass. Create a Framebuffer and "
18269 "command buffer, bind them together, then destroy "
18270 "command pool and framebuffer and verify there are no "
18271 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018272
18273 m_errorMonitor->ExpectSuccess();
18274
18275 ASSERT_NO_FATAL_FAILURE(InitState());
18276
18277 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018278 VkAttachmentDescription attachment = {0,
18279 VK_FORMAT_R8G8B8A8_UNORM,
18280 VK_SAMPLE_COUNT_1_BIT,
18281 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18282 VK_ATTACHMENT_STORE_OP_STORE,
18283 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18284 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18285 VK_IMAGE_LAYOUT_UNDEFINED,
18286 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018287
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018288 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018289
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018290 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018291
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018292 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018293
18294 VkRenderPass rp;
18295 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18296 ASSERT_VK_SUCCESS(err);
18297
18298 // A compatible framebuffer.
18299 VkImageObj image(m_device);
18300 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18301 ASSERT_TRUE(image.initialized());
18302
18303 VkImageViewCreateInfo ivci = {
18304 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18305 nullptr,
18306 0,
18307 image.handle(),
18308 VK_IMAGE_VIEW_TYPE_2D,
18309 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018310 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18311 VK_COMPONENT_SWIZZLE_IDENTITY},
18312 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018313 };
18314 VkImageView view;
18315 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18316 ASSERT_VK_SUCCESS(err);
18317
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018318 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018319 VkFramebuffer fb;
18320 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18321 ASSERT_VK_SUCCESS(err);
18322
18323 // Explicitly create a command buffer to bind the FB to so that we can then
18324 // destroy the command pool in order to implicitly free command buffer
18325 VkCommandPool command_pool;
18326 VkCommandPoolCreateInfo pool_create_info{};
18327 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18328 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18329 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18330 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18331
18332 VkCommandBuffer command_buffer;
18333 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18334 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18335 command_buffer_allocate_info.commandPool = command_pool;
18336 command_buffer_allocate_info.commandBufferCount = 1;
18337 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18338 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18339
18340 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018341 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 -060018342 VkCommandBufferBeginInfo begin_info{};
18343 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18344 vkBeginCommandBuffer(command_buffer, &begin_info);
18345
18346 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18347 vkCmdEndRenderPass(command_buffer);
18348 vkEndCommandBuffer(command_buffer);
18349 vkDestroyImageView(m_device->device(), view, nullptr);
18350 // Destroy command pool to implicitly free command buffer
18351 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18352 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18353 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18354 m_errorMonitor->VerifyNotFound();
18355}
18356
18357TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018358 TEST_DESCRIPTION(
18359 "Ensure that CmdBeginRenderPass applies the layout "
18360 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018361
18362 m_errorMonitor->ExpectSuccess();
18363
18364 ASSERT_NO_FATAL_FAILURE(InitState());
18365
18366 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018367 VkAttachmentDescription attachment = {0,
18368 VK_FORMAT_R8G8B8A8_UNORM,
18369 VK_SAMPLE_COUNT_1_BIT,
18370 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18371 VK_ATTACHMENT_STORE_OP_STORE,
18372 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18373 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18374 VK_IMAGE_LAYOUT_UNDEFINED,
18375 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018376
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018377 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018378
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018379 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018380
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018381 VkSubpassDependency dep = {0,
18382 0,
18383 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18384 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18385 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18386 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18387 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018388
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018389 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018390
18391 VkResult err;
18392 VkRenderPass rp;
18393 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18394 ASSERT_VK_SUCCESS(err);
18395
18396 // A compatible framebuffer.
18397 VkImageObj image(m_device);
18398 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18399 ASSERT_TRUE(image.initialized());
18400
18401 VkImageViewCreateInfo ivci = {
18402 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18403 nullptr,
18404 0,
18405 image.handle(),
18406 VK_IMAGE_VIEW_TYPE_2D,
18407 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018408 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
18409 VK_COMPONENT_SWIZZLE_IDENTITY},
18410 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018411 };
18412 VkImageView view;
18413 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18414 ASSERT_VK_SUCCESS(err);
18415
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018416 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018417 VkFramebuffer fb;
18418 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18419 ASSERT_VK_SUCCESS(err);
18420
18421 // Record a single command buffer which issues a pipeline barrier w/
18422 // image memory barrier for the attachment. This detects the previously
18423 // missing tracking of the subpass layout by throwing a validation error
18424 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018425 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 -070018426 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018427 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18428
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018429 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
18430 nullptr,
18431 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18432 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18433 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18434 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
18435 VK_QUEUE_FAMILY_IGNORED,
18436 VK_QUEUE_FAMILY_IGNORED,
18437 image.handle(),
18438 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018439 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018440 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18441 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018442
18443 vkCmdEndRenderPass(m_commandBuffer->handle());
18444 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018445 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018446
18447 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18448 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18449 vkDestroyImageView(m_device->device(), view, nullptr);
18450}
18451
18452TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018453 TEST_DESCRIPTION(
18454 "Validate that when an imageView of a depth/stencil image "
18455 "is used as a depth/stencil framebuffer attachment, the "
18456 "aspectMask is ignored and both depth and stencil image "
18457 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018458
18459 VkFormatProperties format_properties;
18460 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
18461 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
18462 return;
18463 }
18464
18465 m_errorMonitor->ExpectSuccess();
18466
18467 ASSERT_NO_FATAL_FAILURE(InitState());
18468
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018469 VkAttachmentDescription attachment = {0,
18470 VK_FORMAT_D32_SFLOAT_S8_UINT,
18471 VK_SAMPLE_COUNT_1_BIT,
18472 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18473 VK_ATTACHMENT_STORE_OP_STORE,
18474 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
18475 VK_ATTACHMENT_STORE_OP_DONT_CARE,
18476 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
18477 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018478
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018479 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018480
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018481 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018482
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018483 VkSubpassDependency dep = {0,
18484 0,
18485 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18486 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
18487 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18488 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
18489 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018490
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018491 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018492
18493 VkResult err;
18494 VkRenderPass rp;
18495 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18496 ASSERT_VK_SUCCESS(err);
18497
18498 VkImageObj image(m_device);
18499 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018500 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018501 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018502 ASSERT_TRUE(image.initialized());
18503 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
18504
18505 VkImageViewCreateInfo ivci = {
18506 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
18507 nullptr,
18508 0,
18509 image.handle(),
18510 VK_IMAGE_VIEW_TYPE_2D,
18511 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018512 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
18513 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018514 };
18515 VkImageView view;
18516 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
18517 ASSERT_VK_SUCCESS(err);
18518
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018519 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018520 VkFramebuffer fb;
18521 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18522 ASSERT_VK_SUCCESS(err);
18523
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018524 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 -070018525 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018526 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18527
18528 VkImageMemoryBarrier imb = {};
18529 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18530 imb.pNext = nullptr;
18531 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18532 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18533 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18534 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18535 imb.srcQueueFamilyIndex = 0;
18536 imb.dstQueueFamilyIndex = 0;
18537 imb.image = image.handle();
18538 imb.subresourceRange.aspectMask = 0x6;
18539 imb.subresourceRange.baseMipLevel = 0;
18540 imb.subresourceRange.levelCount = 0x1;
18541 imb.subresourceRange.baseArrayLayer = 0;
18542 imb.subresourceRange.layerCount = 0x1;
18543
18544 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018545 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
18546 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018547
18548 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070018549 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018550 QueueCommandBuffer(false);
18551 m_errorMonitor->VerifyNotFound();
18552
18553 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18554 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18555 vkDestroyImageView(m_device->device(), view, nullptr);
18556}
18557
18558TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018559 TEST_DESCRIPTION(
18560 "Ensure that layout transitions work correctly without "
18561 "errors, when an attachment reference is "
18562 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018563
18564 m_errorMonitor->ExpectSuccess();
18565
18566 ASSERT_NO_FATAL_FAILURE(InitState());
18567
18568 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018569 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018570
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018571 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018572
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018573 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018574
18575 VkRenderPass rp;
18576 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
18577 ASSERT_VK_SUCCESS(err);
18578
18579 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018580 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018581 VkFramebuffer fb;
18582 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
18583 ASSERT_VK_SUCCESS(err);
18584
18585 // Record a command buffer which just begins and ends the renderpass. The
18586 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018587 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 -070018588 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018589 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
18590 vkCmdEndRenderPass(m_commandBuffer->handle());
18591 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070018592 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018593
18594 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18595 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18596}
18597
18598// This is a positive test. No errors are expected.
18599TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018600 TEST_DESCRIPTION(
18601 "Create a stencil-only attachment with a LOAD_OP set to "
18602 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018603 VkResult result = VK_SUCCESS;
18604 VkImageFormatProperties formatProps;
18605 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018606 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
18607 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018608 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
18609 return;
18610 }
18611
18612 ASSERT_NO_FATAL_FAILURE(InitState());
18613 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
18614 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018615 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018616 VkAttachmentDescription att = {};
18617 VkAttachmentReference ref = {};
18618 att.format = depth_stencil_fmt;
18619 att.samples = VK_SAMPLE_COUNT_1_BIT;
18620 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
18621 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
18622 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
18623 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
18624 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18625 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18626
18627 VkClearValue clear;
18628 clear.depthStencil.depth = 1.0;
18629 clear.depthStencil.stencil = 0;
18630 ref.attachment = 0;
18631 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18632
18633 VkSubpassDescription subpass = {};
18634 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
18635 subpass.flags = 0;
18636 subpass.inputAttachmentCount = 0;
18637 subpass.pInputAttachments = NULL;
18638 subpass.colorAttachmentCount = 0;
18639 subpass.pColorAttachments = NULL;
18640 subpass.pResolveAttachments = NULL;
18641 subpass.pDepthStencilAttachment = &ref;
18642 subpass.preserveAttachmentCount = 0;
18643 subpass.pPreserveAttachments = NULL;
18644
18645 VkRenderPass rp;
18646 VkRenderPassCreateInfo rp_info = {};
18647 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
18648 rp_info.attachmentCount = 1;
18649 rp_info.pAttachments = &att;
18650 rp_info.subpassCount = 1;
18651 rp_info.pSubpasses = &subpass;
18652 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
18653 ASSERT_VK_SUCCESS(result);
18654
18655 VkImageView *depthView = m_depthStencil->BindInfo();
18656 VkFramebufferCreateInfo fb_info = {};
18657 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
18658 fb_info.pNext = NULL;
18659 fb_info.renderPass = rp;
18660 fb_info.attachmentCount = 1;
18661 fb_info.pAttachments = depthView;
18662 fb_info.width = 100;
18663 fb_info.height = 100;
18664 fb_info.layers = 1;
18665 VkFramebuffer fb;
18666 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
18667 ASSERT_VK_SUCCESS(result);
18668
18669 VkRenderPassBeginInfo rpbinfo = {};
18670 rpbinfo.clearValueCount = 1;
18671 rpbinfo.pClearValues = &clear;
18672 rpbinfo.pNext = NULL;
18673 rpbinfo.renderPass = rp;
18674 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
18675 rpbinfo.renderArea.extent.width = 100;
18676 rpbinfo.renderArea.extent.height = 100;
18677 rpbinfo.renderArea.offset.x = 0;
18678 rpbinfo.renderArea.offset.y = 0;
18679 rpbinfo.framebuffer = fb;
18680
18681 VkFence fence = {};
18682 VkFenceCreateInfo fence_ci = {};
18683 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18684 fence_ci.pNext = nullptr;
18685 fence_ci.flags = 0;
18686 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
18687 ASSERT_VK_SUCCESS(result);
18688
18689 m_commandBuffer->BeginCommandBuffer();
18690 m_commandBuffer->BeginRenderPass(rpbinfo);
18691 m_commandBuffer->EndRenderPass();
18692 m_commandBuffer->EndCommandBuffer();
18693 m_commandBuffer->QueueCommandBuffer(fence);
18694
18695 VkImageObj destImage(m_device);
18696 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 -070018697 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018698 VkImageMemoryBarrier barrier = {};
18699 VkImageSubresourceRange range;
18700 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18701 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18702 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
18703 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18704 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18705 barrier.image = m_depthStencil->handle();
18706 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18707 range.baseMipLevel = 0;
18708 range.levelCount = 1;
18709 range.baseArrayLayer = 0;
18710 range.layerCount = 1;
18711 barrier.subresourceRange = range;
18712 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
18713 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
18714 cmdbuf.BeginCommandBuffer();
18715 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 -070018716 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018717 barrier.srcAccessMask = 0;
18718 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18719 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18720 barrier.image = destImage.handle();
18721 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
18722 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 -070018723 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018724 VkImageCopy cregion;
18725 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18726 cregion.srcSubresource.mipLevel = 0;
18727 cregion.srcSubresource.baseArrayLayer = 0;
18728 cregion.srcSubresource.layerCount = 1;
18729 cregion.srcOffset.x = 0;
18730 cregion.srcOffset.y = 0;
18731 cregion.srcOffset.z = 0;
18732 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18733 cregion.dstSubresource.mipLevel = 0;
18734 cregion.dstSubresource.baseArrayLayer = 0;
18735 cregion.dstSubresource.layerCount = 1;
18736 cregion.dstOffset.x = 0;
18737 cregion.dstOffset.y = 0;
18738 cregion.dstOffset.z = 0;
18739 cregion.extent.width = 100;
18740 cregion.extent.height = 100;
18741 cregion.extent.depth = 1;
18742 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018743 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018744 cmdbuf.EndCommandBuffer();
18745
18746 VkSubmitInfo submit_info;
18747 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18748 submit_info.pNext = NULL;
18749 submit_info.waitSemaphoreCount = 0;
18750 submit_info.pWaitSemaphores = NULL;
18751 submit_info.pWaitDstStageMask = NULL;
18752 submit_info.commandBufferCount = 1;
18753 submit_info.pCommandBuffers = &cmdbuf.handle();
18754 submit_info.signalSemaphoreCount = 0;
18755 submit_info.pSignalSemaphores = NULL;
18756
18757 m_errorMonitor->ExpectSuccess();
18758 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18759 m_errorMonitor->VerifyNotFound();
18760
18761 vkQueueWaitIdle(m_device->m_queue);
18762 vkDestroyFence(m_device->device(), fence, nullptr);
18763 vkDestroyRenderPass(m_device->device(), rp, nullptr);
18764 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
18765}
18766
18767// This is a positive test. No errors should be generated.
18768TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
18769 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
18770
18771 m_errorMonitor->ExpectSuccess();
18772 ASSERT_NO_FATAL_FAILURE(InitState());
18773
18774 VkEvent event;
18775 VkEventCreateInfo event_create_info{};
18776 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
18777 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
18778
18779 VkCommandPool command_pool;
18780 VkCommandPoolCreateInfo pool_create_info{};
18781 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18782 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18783 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18784 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18785
18786 VkCommandBuffer command_buffer;
18787 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18788 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18789 command_buffer_allocate_info.commandPool = command_pool;
18790 command_buffer_allocate_info.commandBufferCount = 1;
18791 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18792 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18793
18794 VkQueue queue = VK_NULL_HANDLE;
18795 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
18796
18797 {
18798 VkCommandBufferBeginInfo begin_info{};
18799 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18800 vkBeginCommandBuffer(command_buffer, &begin_info);
18801
18802 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 -070018803 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018804 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
18805 vkEndCommandBuffer(command_buffer);
18806 }
18807 {
18808 VkSubmitInfo submit_info{};
18809 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18810 submit_info.commandBufferCount = 1;
18811 submit_info.pCommandBuffers = &command_buffer;
18812 submit_info.signalSemaphoreCount = 0;
18813 submit_info.pSignalSemaphores = nullptr;
18814 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18815 }
18816 { vkSetEvent(m_device->device(), event); }
18817
18818 vkQueueWaitIdle(queue);
18819
18820 vkDestroyEvent(m_device->device(), event, nullptr);
18821 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18822 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18823
18824 m_errorMonitor->VerifyNotFound();
18825}
18826// This is a positive test. No errors should be generated.
18827TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
18828 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
18829
18830 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018831 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018832
18833 m_errorMonitor->ExpectSuccess();
18834
18835 VkQueryPool query_pool;
18836 VkQueryPoolCreateInfo query_pool_create_info{};
18837 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18838 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18839 query_pool_create_info.queryCount = 1;
18840 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18841
18842 VkCommandPool command_pool;
18843 VkCommandPoolCreateInfo pool_create_info{};
18844 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18845 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18846 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18847 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18848
18849 VkCommandBuffer command_buffer;
18850 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18851 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18852 command_buffer_allocate_info.commandPool = command_pool;
18853 command_buffer_allocate_info.commandBufferCount = 1;
18854 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18855 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
18856
18857 VkCommandBuffer secondary_command_buffer;
18858 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18859 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
18860
18861 VkQueue queue = VK_NULL_HANDLE;
18862 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18863
18864 uint32_t qfi = 0;
18865 VkBufferCreateInfo buff_create_info = {};
18866 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18867 buff_create_info.size = 1024;
18868 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18869 buff_create_info.queueFamilyIndexCount = 1;
18870 buff_create_info.pQueueFamilyIndices = &qfi;
18871
18872 VkResult err;
18873 VkBuffer buffer;
18874 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18875 ASSERT_VK_SUCCESS(err);
18876 VkMemoryAllocateInfo mem_alloc = {};
18877 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18878 mem_alloc.pNext = NULL;
18879 mem_alloc.allocationSize = 1024;
18880 mem_alloc.memoryTypeIndex = 0;
18881
18882 VkMemoryRequirements memReqs;
18883 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
18884 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
18885 if (!pass) {
18886 vkDestroyBuffer(m_device->device(), buffer, NULL);
18887 return;
18888 }
18889
18890 VkDeviceMemory mem;
18891 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18892 ASSERT_VK_SUCCESS(err);
18893 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18894 ASSERT_VK_SUCCESS(err);
18895
18896 VkCommandBufferInheritanceInfo hinfo = {};
18897 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18898 hinfo.renderPass = VK_NULL_HANDLE;
18899 hinfo.subpass = 0;
18900 hinfo.framebuffer = VK_NULL_HANDLE;
18901 hinfo.occlusionQueryEnable = VK_FALSE;
18902 hinfo.queryFlags = 0;
18903 hinfo.pipelineStatistics = 0;
18904
18905 {
18906 VkCommandBufferBeginInfo begin_info{};
18907 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18908 begin_info.pInheritanceInfo = &hinfo;
18909 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
18910
18911 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
18912 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
18913
18914 vkEndCommandBuffer(secondary_command_buffer);
18915
18916 begin_info.pInheritanceInfo = nullptr;
18917 vkBeginCommandBuffer(command_buffer, &begin_info);
18918
18919 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
18920 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
18921
18922 vkEndCommandBuffer(command_buffer);
18923 }
18924 {
18925 VkSubmitInfo submit_info{};
18926 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18927 submit_info.commandBufferCount = 1;
18928 submit_info.pCommandBuffers = &command_buffer;
18929 submit_info.signalSemaphoreCount = 0;
18930 submit_info.pSignalSemaphores = nullptr;
18931 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
18932 }
18933
18934 vkQueueWaitIdle(queue);
18935
18936 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
18937 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
18938 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
18939 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18940 vkDestroyBuffer(m_device->device(), buffer, NULL);
18941 vkFreeMemory(m_device->device(), mem, NULL);
18942
18943 m_errorMonitor->VerifyNotFound();
18944}
18945
18946// This is a positive test. No errors should be generated.
18947TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
18948 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
18949
18950 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018951 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018952
18953 m_errorMonitor->ExpectSuccess();
18954
18955 VkQueryPool query_pool;
18956 VkQueryPoolCreateInfo query_pool_create_info{};
18957 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
18958 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
18959 query_pool_create_info.queryCount = 1;
18960 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
18961
18962 VkCommandPool command_pool;
18963 VkCommandPoolCreateInfo pool_create_info{};
18964 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18965 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18966 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18967 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18968
18969 VkCommandBuffer command_buffer[2];
18970 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18971 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18972 command_buffer_allocate_info.commandPool = command_pool;
18973 command_buffer_allocate_info.commandBufferCount = 2;
18974 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18975 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
18976
18977 VkQueue queue = VK_NULL_HANDLE;
18978 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
18979
18980 uint32_t qfi = 0;
18981 VkBufferCreateInfo buff_create_info = {};
18982 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18983 buff_create_info.size = 1024;
18984 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
18985 buff_create_info.queueFamilyIndexCount = 1;
18986 buff_create_info.pQueueFamilyIndices = &qfi;
18987
18988 VkResult err;
18989 VkBuffer buffer;
18990 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
18991 ASSERT_VK_SUCCESS(err);
18992 VkMemoryAllocateInfo mem_alloc = {};
18993 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18994 mem_alloc.pNext = NULL;
18995 mem_alloc.allocationSize = 1024;
18996 mem_alloc.memoryTypeIndex = 0;
18997
18998 VkMemoryRequirements memReqs;
18999 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19000 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19001 if (!pass) {
19002 vkDestroyBuffer(m_device->device(), buffer, NULL);
19003 return;
19004 }
19005
19006 VkDeviceMemory mem;
19007 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19008 ASSERT_VK_SUCCESS(err);
19009 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19010 ASSERT_VK_SUCCESS(err);
19011
19012 {
19013 VkCommandBufferBeginInfo begin_info{};
19014 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19015 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19016
19017 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
19018 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
19019
19020 vkEndCommandBuffer(command_buffer[0]);
19021
19022 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19023
19024 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
19025
19026 vkEndCommandBuffer(command_buffer[1]);
19027 }
19028 {
19029 VkSubmitInfo submit_info{};
19030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19031 submit_info.commandBufferCount = 2;
19032 submit_info.pCommandBuffers = command_buffer;
19033 submit_info.signalSemaphoreCount = 0;
19034 submit_info.pSignalSemaphores = nullptr;
19035 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19036 }
19037
19038 vkQueueWaitIdle(queue);
19039
19040 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
19041 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
19042 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19043 vkDestroyBuffer(m_device->device(), buffer, NULL);
19044 vkFreeMemory(m_device->device(), mem, NULL);
19045
19046 m_errorMonitor->VerifyNotFound();
19047}
19048
Tony Barbourc46924f2016-11-04 11:49:52 -060019049TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019050 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
19051
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019052 ASSERT_NO_FATAL_FAILURE(InitState());
19053 VkEvent event;
19054 VkEventCreateInfo event_create_info{};
19055 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19056 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19057
19058 VkCommandPool command_pool;
19059 VkCommandPoolCreateInfo pool_create_info{};
19060 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19061 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19062 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19063 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19064
19065 VkCommandBuffer command_buffer;
19066 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19067 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19068 command_buffer_allocate_info.commandPool = command_pool;
19069 command_buffer_allocate_info.commandBufferCount = 1;
19070 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19071 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19072
19073 VkQueue queue = VK_NULL_HANDLE;
19074 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19075
19076 {
19077 VkCommandBufferBeginInfo begin_info{};
19078 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19079 vkBeginCommandBuffer(command_buffer, &begin_info);
19080
19081 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019082 vkEndCommandBuffer(command_buffer);
19083 }
19084 {
19085 VkSubmitInfo submit_info{};
19086 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19087 submit_info.commandBufferCount = 1;
19088 submit_info.pCommandBuffers = &command_buffer;
19089 submit_info.signalSemaphoreCount = 0;
19090 submit_info.pSignalSemaphores = nullptr;
19091 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19092 }
19093 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
19095 "that is already in use by a "
19096 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019097 vkSetEvent(m_device->device(), event);
19098 m_errorMonitor->VerifyFound();
19099 }
19100
19101 vkQueueWaitIdle(queue);
19102
19103 vkDestroyEvent(m_device->device(), event, nullptr);
19104 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19105 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19106}
19107
19108// This is a positive test. No errors should be generated.
19109TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019110 TEST_DESCRIPTION(
19111 "Two command buffers with two separate fences are each "
19112 "run through a Submit & WaitForFences cycle 3 times. This "
19113 "previously revealed a bug so running this positive test "
19114 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019115 m_errorMonitor->ExpectSuccess();
19116
19117 ASSERT_NO_FATAL_FAILURE(InitState());
19118 VkQueue queue = VK_NULL_HANDLE;
19119 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19120
19121 static const uint32_t NUM_OBJECTS = 2;
19122 static const uint32_t NUM_FRAMES = 3;
19123 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
19124 VkFence fences[NUM_OBJECTS] = {};
19125
19126 VkCommandPool cmd_pool;
19127 VkCommandPoolCreateInfo cmd_pool_ci = {};
19128 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19129 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
19130 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19131 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
19132 ASSERT_VK_SUCCESS(err);
19133
19134 VkCommandBufferAllocateInfo cmd_buf_info = {};
19135 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19136 cmd_buf_info.commandPool = cmd_pool;
19137 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19138 cmd_buf_info.commandBufferCount = 1;
19139
19140 VkFenceCreateInfo fence_ci = {};
19141 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19142 fence_ci.pNext = nullptr;
19143 fence_ci.flags = 0;
19144
19145 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19146 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
19147 ASSERT_VK_SUCCESS(err);
19148 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
19149 ASSERT_VK_SUCCESS(err);
19150 }
19151
19152 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
19153 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
19154 // Create empty cmd buffer
19155 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
19156 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19157
19158 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
19159 ASSERT_VK_SUCCESS(err);
19160 err = vkEndCommandBuffer(cmd_buffers[obj]);
19161 ASSERT_VK_SUCCESS(err);
19162
19163 VkSubmitInfo submit_info = {};
19164 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19165 submit_info.commandBufferCount = 1;
19166 submit_info.pCommandBuffers = &cmd_buffers[obj];
19167 // Submit cmd buffer and wait for fence
19168 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
19169 ASSERT_VK_SUCCESS(err);
19170 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
19171 ASSERT_VK_SUCCESS(err);
19172 err = vkResetFences(m_device->device(), 1, &fences[obj]);
19173 ASSERT_VK_SUCCESS(err);
19174 }
19175 }
19176 m_errorMonitor->VerifyNotFound();
19177 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
19178 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
19179 vkDestroyFence(m_device->device(), fences[i], nullptr);
19180 }
19181}
19182// This is a positive test. No errors should be generated.
19183TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019184 TEST_DESCRIPTION(
19185 "Two command buffers, each in a separate QueueSubmit call "
19186 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019187
19188 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019189 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019190
19191 m_errorMonitor->ExpectSuccess();
19192
19193 VkSemaphore semaphore;
19194 VkSemaphoreCreateInfo semaphore_create_info{};
19195 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19196 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19197
19198 VkCommandPool command_pool;
19199 VkCommandPoolCreateInfo pool_create_info{};
19200 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19201 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19202 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19203 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19204
19205 VkCommandBuffer command_buffer[2];
19206 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19207 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19208 command_buffer_allocate_info.commandPool = command_pool;
19209 command_buffer_allocate_info.commandBufferCount = 2;
19210 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19211 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19212
19213 VkQueue queue = VK_NULL_HANDLE;
19214 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19215
19216 {
19217 VkCommandBufferBeginInfo begin_info{};
19218 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19219 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19220
19221 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 -070019222 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019223
19224 VkViewport viewport{};
19225 viewport.maxDepth = 1.0f;
19226 viewport.minDepth = 0.0f;
19227 viewport.width = 512;
19228 viewport.height = 512;
19229 viewport.x = 0;
19230 viewport.y = 0;
19231 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19232 vkEndCommandBuffer(command_buffer[0]);
19233 }
19234 {
19235 VkCommandBufferBeginInfo begin_info{};
19236 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19237 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19238
19239 VkViewport viewport{};
19240 viewport.maxDepth = 1.0f;
19241 viewport.minDepth = 0.0f;
19242 viewport.width = 512;
19243 viewport.height = 512;
19244 viewport.x = 0;
19245 viewport.y = 0;
19246 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19247 vkEndCommandBuffer(command_buffer[1]);
19248 }
19249 {
19250 VkSubmitInfo submit_info{};
19251 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19252 submit_info.commandBufferCount = 1;
19253 submit_info.pCommandBuffers = &command_buffer[0];
19254 submit_info.signalSemaphoreCount = 1;
19255 submit_info.pSignalSemaphores = &semaphore;
19256 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19257 }
19258 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019259 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019260 VkSubmitInfo submit_info{};
19261 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19262 submit_info.commandBufferCount = 1;
19263 submit_info.pCommandBuffers = &command_buffer[1];
19264 submit_info.waitSemaphoreCount = 1;
19265 submit_info.pWaitSemaphores = &semaphore;
19266 submit_info.pWaitDstStageMask = flags;
19267 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19268 }
19269
19270 vkQueueWaitIdle(m_device->m_queue);
19271
19272 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19273 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19274 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19275
19276 m_errorMonitor->VerifyNotFound();
19277}
19278
19279// This is a positive test. No errors should be generated.
19280TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019281 TEST_DESCRIPTION(
19282 "Two command buffers, each in a separate QueueSubmit call "
19283 "submitted on separate queues, the second having a fence"
19284 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019285
19286 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019287 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019288
19289 m_errorMonitor->ExpectSuccess();
19290
19291 VkFence fence;
19292 VkFenceCreateInfo fence_create_info{};
19293 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19294 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19295
19296 VkSemaphore semaphore;
19297 VkSemaphoreCreateInfo semaphore_create_info{};
19298 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19299 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19300
19301 VkCommandPool command_pool;
19302 VkCommandPoolCreateInfo pool_create_info{};
19303 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19304 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19305 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19306 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19307
19308 VkCommandBuffer command_buffer[2];
19309 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19310 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19311 command_buffer_allocate_info.commandPool = command_pool;
19312 command_buffer_allocate_info.commandBufferCount = 2;
19313 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19314 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19315
19316 VkQueue queue = VK_NULL_HANDLE;
19317 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19318
19319 {
19320 VkCommandBufferBeginInfo begin_info{};
19321 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19322 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19323
19324 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 -070019325 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019326
19327 VkViewport viewport{};
19328 viewport.maxDepth = 1.0f;
19329 viewport.minDepth = 0.0f;
19330 viewport.width = 512;
19331 viewport.height = 512;
19332 viewport.x = 0;
19333 viewport.y = 0;
19334 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19335 vkEndCommandBuffer(command_buffer[0]);
19336 }
19337 {
19338 VkCommandBufferBeginInfo begin_info{};
19339 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19340 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19341
19342 VkViewport viewport{};
19343 viewport.maxDepth = 1.0f;
19344 viewport.minDepth = 0.0f;
19345 viewport.width = 512;
19346 viewport.height = 512;
19347 viewport.x = 0;
19348 viewport.y = 0;
19349 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19350 vkEndCommandBuffer(command_buffer[1]);
19351 }
19352 {
19353 VkSubmitInfo submit_info{};
19354 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19355 submit_info.commandBufferCount = 1;
19356 submit_info.pCommandBuffers = &command_buffer[0];
19357 submit_info.signalSemaphoreCount = 1;
19358 submit_info.pSignalSemaphores = &semaphore;
19359 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19360 }
19361 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019362 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019363 VkSubmitInfo submit_info{};
19364 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19365 submit_info.commandBufferCount = 1;
19366 submit_info.pCommandBuffers = &command_buffer[1];
19367 submit_info.waitSemaphoreCount = 1;
19368 submit_info.pWaitSemaphores = &semaphore;
19369 submit_info.pWaitDstStageMask = flags;
19370 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19371 }
19372
19373 vkQueueWaitIdle(m_device->m_queue);
19374
19375 vkDestroyFence(m_device->device(), fence, nullptr);
19376 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19377 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19378 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19379
19380 m_errorMonitor->VerifyNotFound();
19381}
19382
19383// This is a positive test. No errors should be generated.
19384TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019385 TEST_DESCRIPTION(
19386 "Two command buffers, each in a separate QueueSubmit call "
19387 "submitted on separate queues, the second having a fence"
19388 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019389
19390 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019391 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019392
19393 m_errorMonitor->ExpectSuccess();
19394
19395 VkFence fence;
19396 VkFenceCreateInfo fence_create_info{};
19397 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19398 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19399
19400 VkSemaphore semaphore;
19401 VkSemaphoreCreateInfo semaphore_create_info{};
19402 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19403 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19404
19405 VkCommandPool command_pool;
19406 VkCommandPoolCreateInfo pool_create_info{};
19407 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19408 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19409 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19410 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19411
19412 VkCommandBuffer command_buffer[2];
19413 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19414 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19415 command_buffer_allocate_info.commandPool = command_pool;
19416 command_buffer_allocate_info.commandBufferCount = 2;
19417 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19418 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19419
19420 VkQueue queue = VK_NULL_HANDLE;
19421 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19422
19423 {
19424 VkCommandBufferBeginInfo begin_info{};
19425 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19426 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19427
19428 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 -070019429 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019430
19431 VkViewport viewport{};
19432 viewport.maxDepth = 1.0f;
19433 viewport.minDepth = 0.0f;
19434 viewport.width = 512;
19435 viewport.height = 512;
19436 viewport.x = 0;
19437 viewport.y = 0;
19438 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19439 vkEndCommandBuffer(command_buffer[0]);
19440 }
19441 {
19442 VkCommandBufferBeginInfo begin_info{};
19443 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19444 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19445
19446 VkViewport viewport{};
19447 viewport.maxDepth = 1.0f;
19448 viewport.minDepth = 0.0f;
19449 viewport.width = 512;
19450 viewport.height = 512;
19451 viewport.x = 0;
19452 viewport.y = 0;
19453 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19454 vkEndCommandBuffer(command_buffer[1]);
19455 }
19456 {
19457 VkSubmitInfo submit_info{};
19458 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19459 submit_info.commandBufferCount = 1;
19460 submit_info.pCommandBuffers = &command_buffer[0];
19461 submit_info.signalSemaphoreCount = 1;
19462 submit_info.pSignalSemaphores = &semaphore;
19463 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19464 }
19465 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019466 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019467 VkSubmitInfo submit_info{};
19468 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19469 submit_info.commandBufferCount = 1;
19470 submit_info.pCommandBuffers = &command_buffer[1];
19471 submit_info.waitSemaphoreCount = 1;
19472 submit_info.pWaitSemaphores = &semaphore;
19473 submit_info.pWaitDstStageMask = flags;
19474 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19475 }
19476
19477 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19478 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19479
19480 vkDestroyFence(m_device->device(), fence, nullptr);
19481 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19482 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19483 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19484
19485 m_errorMonitor->VerifyNotFound();
19486}
19487
19488TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019489 ASSERT_NO_FATAL_FAILURE(InitState());
19490 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
19491 printf("Test requires two queues, skipping\n");
19492 return;
19493 }
19494
19495 VkResult err;
19496
19497 m_errorMonitor->ExpectSuccess();
19498
19499 VkQueue q0 = m_device->m_queue;
19500 VkQueue q1 = nullptr;
19501 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
19502 ASSERT_NE(q1, nullptr);
19503
19504 // An (empty) command buffer. We must have work in the first submission --
19505 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019506 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019507 VkCommandPool pool;
19508 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
19509 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019510 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
19511 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019512 VkCommandBuffer cb;
19513 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
19514 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019515 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019516 err = vkBeginCommandBuffer(cb, &cbbi);
19517 ASSERT_VK_SUCCESS(err);
19518 err = vkEndCommandBuffer(cb);
19519 ASSERT_VK_SUCCESS(err);
19520
19521 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019522 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019523 VkSemaphore s;
19524 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
19525 ASSERT_VK_SUCCESS(err);
19526
19527 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019528 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019529
19530 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
19531 ASSERT_VK_SUCCESS(err);
19532
19533 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019534 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019535 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019536
19537 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
19538 ASSERT_VK_SUCCESS(err);
19539
19540 // Wait for q0 idle
19541 err = vkQueueWaitIdle(q0);
19542 ASSERT_VK_SUCCESS(err);
19543
19544 // Command buffer should have been completed (it was on q0); reset the pool.
19545 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
19546
19547 m_errorMonitor->VerifyNotFound();
19548
19549 // Force device completely idle and clean up resources
19550 vkDeviceWaitIdle(m_device->device());
19551 vkDestroyCommandPool(m_device->device(), pool, nullptr);
19552 vkDestroySemaphore(m_device->device(), s, nullptr);
19553}
19554
19555// This is a positive test. No errors should be generated.
19556TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019557 TEST_DESCRIPTION(
19558 "Two command buffers, each in a separate QueueSubmit call "
19559 "submitted on separate queues, the second having a fence, "
19560 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019561
19562 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019563 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019564
19565 m_errorMonitor->ExpectSuccess();
19566
19567 ASSERT_NO_FATAL_FAILURE(InitState());
19568 VkFence fence;
19569 VkFenceCreateInfo fence_create_info{};
19570 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19571 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19572
19573 VkSemaphore semaphore;
19574 VkSemaphoreCreateInfo semaphore_create_info{};
19575 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19576 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19577
19578 VkCommandPool command_pool;
19579 VkCommandPoolCreateInfo pool_create_info{};
19580 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19581 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19582 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19583 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19584
19585 VkCommandBuffer command_buffer[2];
19586 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19587 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19588 command_buffer_allocate_info.commandPool = command_pool;
19589 command_buffer_allocate_info.commandBufferCount = 2;
19590 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19591 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19592
19593 VkQueue queue = VK_NULL_HANDLE;
19594 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19595
19596 {
19597 VkCommandBufferBeginInfo begin_info{};
19598 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19599 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19600
19601 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 -070019602 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019603
19604 VkViewport viewport{};
19605 viewport.maxDepth = 1.0f;
19606 viewport.minDepth = 0.0f;
19607 viewport.width = 512;
19608 viewport.height = 512;
19609 viewport.x = 0;
19610 viewport.y = 0;
19611 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19612 vkEndCommandBuffer(command_buffer[0]);
19613 }
19614 {
19615 VkCommandBufferBeginInfo begin_info{};
19616 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19617 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19618
19619 VkViewport viewport{};
19620 viewport.maxDepth = 1.0f;
19621 viewport.minDepth = 0.0f;
19622 viewport.width = 512;
19623 viewport.height = 512;
19624 viewport.x = 0;
19625 viewport.y = 0;
19626 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19627 vkEndCommandBuffer(command_buffer[1]);
19628 }
19629 {
19630 VkSubmitInfo submit_info{};
19631 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19632 submit_info.commandBufferCount = 1;
19633 submit_info.pCommandBuffers = &command_buffer[0];
19634 submit_info.signalSemaphoreCount = 1;
19635 submit_info.pSignalSemaphores = &semaphore;
19636 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19637 }
19638 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019639 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019640 VkSubmitInfo submit_info{};
19641 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19642 submit_info.commandBufferCount = 1;
19643 submit_info.pCommandBuffers = &command_buffer[1];
19644 submit_info.waitSemaphoreCount = 1;
19645 submit_info.pWaitSemaphores = &semaphore;
19646 submit_info.pWaitDstStageMask = flags;
19647 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19648 }
19649
19650 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19651
19652 vkDestroyFence(m_device->device(), fence, nullptr);
19653 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19654 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19655 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19656
19657 m_errorMonitor->VerifyNotFound();
19658}
19659
19660// This is a positive test. No errors should be generated.
19661TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019662 TEST_DESCRIPTION(
19663 "Two command buffers, each in a separate QueueSubmit call "
19664 "on the same queue, sharing a signal/wait semaphore, the "
19665 "second having a fence, "
19666 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019667
19668 m_errorMonitor->ExpectSuccess();
19669
19670 ASSERT_NO_FATAL_FAILURE(InitState());
19671 VkFence fence;
19672 VkFenceCreateInfo fence_create_info{};
19673 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19674 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19675
19676 VkSemaphore semaphore;
19677 VkSemaphoreCreateInfo semaphore_create_info{};
19678 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19679 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19680
19681 VkCommandPool command_pool;
19682 VkCommandPoolCreateInfo pool_create_info{};
19683 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19684 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19685 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19686 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19687
19688 VkCommandBuffer command_buffer[2];
19689 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19690 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19691 command_buffer_allocate_info.commandPool = command_pool;
19692 command_buffer_allocate_info.commandBufferCount = 2;
19693 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19694 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19695
19696 {
19697 VkCommandBufferBeginInfo begin_info{};
19698 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19699 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19700
19701 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 -070019702 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019703
19704 VkViewport viewport{};
19705 viewport.maxDepth = 1.0f;
19706 viewport.minDepth = 0.0f;
19707 viewport.width = 512;
19708 viewport.height = 512;
19709 viewport.x = 0;
19710 viewport.y = 0;
19711 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19712 vkEndCommandBuffer(command_buffer[0]);
19713 }
19714 {
19715 VkCommandBufferBeginInfo begin_info{};
19716 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19717 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19718
19719 VkViewport viewport{};
19720 viewport.maxDepth = 1.0f;
19721 viewport.minDepth = 0.0f;
19722 viewport.width = 512;
19723 viewport.height = 512;
19724 viewport.x = 0;
19725 viewport.y = 0;
19726 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19727 vkEndCommandBuffer(command_buffer[1]);
19728 }
19729 {
19730 VkSubmitInfo submit_info{};
19731 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19732 submit_info.commandBufferCount = 1;
19733 submit_info.pCommandBuffers = &command_buffer[0];
19734 submit_info.signalSemaphoreCount = 1;
19735 submit_info.pSignalSemaphores = &semaphore;
19736 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19737 }
19738 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019739 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019740 VkSubmitInfo submit_info{};
19741 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19742 submit_info.commandBufferCount = 1;
19743 submit_info.pCommandBuffers = &command_buffer[1];
19744 submit_info.waitSemaphoreCount = 1;
19745 submit_info.pWaitSemaphores = &semaphore;
19746 submit_info.pWaitDstStageMask = flags;
19747 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19748 }
19749
19750 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19751
19752 vkDestroyFence(m_device->device(), fence, nullptr);
19753 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
19754 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19755 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19756
19757 m_errorMonitor->VerifyNotFound();
19758}
19759
19760// This is a positive test. No errors should be generated.
19761TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019762 TEST_DESCRIPTION(
19763 "Two command buffers, each in a separate QueueSubmit call "
19764 "on the same queue, no fences, followed by a third QueueSubmit with NO "
19765 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019766
19767 m_errorMonitor->ExpectSuccess();
19768
19769 ASSERT_NO_FATAL_FAILURE(InitState());
19770 VkFence fence;
19771 VkFenceCreateInfo fence_create_info{};
19772 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19773 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19774
19775 VkCommandPool command_pool;
19776 VkCommandPoolCreateInfo pool_create_info{};
19777 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19778 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19779 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19780 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19781
19782 VkCommandBuffer command_buffer[2];
19783 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19784 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19785 command_buffer_allocate_info.commandPool = command_pool;
19786 command_buffer_allocate_info.commandBufferCount = 2;
19787 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19788 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19789
19790 {
19791 VkCommandBufferBeginInfo begin_info{};
19792 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19793 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19794
19795 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 -070019796 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019797
19798 VkViewport viewport{};
19799 viewport.maxDepth = 1.0f;
19800 viewport.minDepth = 0.0f;
19801 viewport.width = 512;
19802 viewport.height = 512;
19803 viewport.x = 0;
19804 viewport.y = 0;
19805 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19806 vkEndCommandBuffer(command_buffer[0]);
19807 }
19808 {
19809 VkCommandBufferBeginInfo begin_info{};
19810 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19811 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19812
19813 VkViewport viewport{};
19814 viewport.maxDepth = 1.0f;
19815 viewport.minDepth = 0.0f;
19816 viewport.width = 512;
19817 viewport.height = 512;
19818 viewport.x = 0;
19819 viewport.y = 0;
19820 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19821 vkEndCommandBuffer(command_buffer[1]);
19822 }
19823 {
19824 VkSubmitInfo submit_info{};
19825 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19826 submit_info.commandBufferCount = 1;
19827 submit_info.pCommandBuffers = &command_buffer[0];
19828 submit_info.signalSemaphoreCount = 0;
19829 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19830 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19831 }
19832 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019833 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019834 VkSubmitInfo submit_info{};
19835 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19836 submit_info.commandBufferCount = 1;
19837 submit_info.pCommandBuffers = &command_buffer[1];
19838 submit_info.waitSemaphoreCount = 0;
19839 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19840 submit_info.pWaitDstStageMask = flags;
19841 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19842 }
19843
19844 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
19845
19846 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19847 ASSERT_VK_SUCCESS(err);
19848
19849 vkDestroyFence(m_device->device(), fence, nullptr);
19850 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19851 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19852
19853 m_errorMonitor->VerifyNotFound();
19854}
19855
19856// This is a positive test. No errors should be generated.
19857TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019858 TEST_DESCRIPTION(
19859 "Two command buffers, each in a separate QueueSubmit call "
19860 "on the same queue, the second having a fence, followed "
19861 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019862
19863 m_errorMonitor->ExpectSuccess();
19864
19865 ASSERT_NO_FATAL_FAILURE(InitState());
19866 VkFence fence;
19867 VkFenceCreateInfo fence_create_info{};
19868 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19869 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19870
19871 VkCommandPool command_pool;
19872 VkCommandPoolCreateInfo pool_create_info{};
19873 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19874 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19875 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19876 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19877
19878 VkCommandBuffer command_buffer[2];
19879 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19880 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19881 command_buffer_allocate_info.commandPool = command_pool;
19882 command_buffer_allocate_info.commandBufferCount = 2;
19883 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19884 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19885
19886 {
19887 VkCommandBufferBeginInfo begin_info{};
19888 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19889 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19890
19891 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 -070019892 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019893
19894 VkViewport viewport{};
19895 viewport.maxDepth = 1.0f;
19896 viewport.minDepth = 0.0f;
19897 viewport.width = 512;
19898 viewport.height = 512;
19899 viewport.x = 0;
19900 viewport.y = 0;
19901 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19902 vkEndCommandBuffer(command_buffer[0]);
19903 }
19904 {
19905 VkCommandBufferBeginInfo begin_info{};
19906 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19907 vkBeginCommandBuffer(command_buffer[1], &begin_info);
19908
19909 VkViewport viewport{};
19910 viewport.maxDepth = 1.0f;
19911 viewport.minDepth = 0.0f;
19912 viewport.width = 512;
19913 viewport.height = 512;
19914 viewport.x = 0;
19915 viewport.y = 0;
19916 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
19917 vkEndCommandBuffer(command_buffer[1]);
19918 }
19919 {
19920 VkSubmitInfo submit_info{};
19921 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19922 submit_info.commandBufferCount = 1;
19923 submit_info.pCommandBuffers = &command_buffer[0];
19924 submit_info.signalSemaphoreCount = 0;
19925 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
19926 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19927 }
19928 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019929 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019930 VkSubmitInfo submit_info{};
19931 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19932 submit_info.commandBufferCount = 1;
19933 submit_info.pCommandBuffers = &command_buffer[1];
19934 submit_info.waitSemaphoreCount = 0;
19935 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
19936 submit_info.pWaitDstStageMask = flags;
19937 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
19938 }
19939
19940 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19941
19942 vkDestroyFence(m_device->device(), fence, nullptr);
19943 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
19944 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19945
19946 m_errorMonitor->VerifyNotFound();
19947}
19948
19949// This is a positive test. No errors should be generated.
19950TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019951 TEST_DESCRIPTION(
19952 "Two command buffers each in a separate SubmitInfo sent in a single "
19953 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019954 ASSERT_NO_FATAL_FAILURE(InitState());
19955
19956 m_errorMonitor->ExpectSuccess();
19957
19958 VkFence fence;
19959 VkFenceCreateInfo fence_create_info{};
19960 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19961 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
19962
19963 VkSemaphore semaphore;
19964 VkSemaphoreCreateInfo semaphore_create_info{};
19965 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19966 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
19967
19968 VkCommandPool command_pool;
19969 VkCommandPoolCreateInfo pool_create_info{};
19970 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19971 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19972 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19973 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19974
19975 VkCommandBuffer command_buffer[2];
19976 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19977 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19978 command_buffer_allocate_info.commandPool = command_pool;
19979 command_buffer_allocate_info.commandBufferCount = 2;
19980 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19981 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
19982
19983 {
19984 VkCommandBufferBeginInfo begin_info{};
19985 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19986 vkBeginCommandBuffer(command_buffer[0], &begin_info);
19987
19988 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 -070019989 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019990
19991 VkViewport viewport{};
19992 viewport.maxDepth = 1.0f;
19993 viewport.minDepth = 0.0f;
19994 viewport.width = 512;
19995 viewport.height = 512;
19996 viewport.x = 0;
19997 viewport.y = 0;
19998 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
19999 vkEndCommandBuffer(command_buffer[0]);
20000 }
20001 {
20002 VkCommandBufferBeginInfo begin_info{};
20003 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20004 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20005
20006 VkViewport viewport{};
20007 viewport.maxDepth = 1.0f;
20008 viewport.minDepth = 0.0f;
20009 viewport.width = 512;
20010 viewport.height = 512;
20011 viewport.x = 0;
20012 viewport.y = 0;
20013 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20014 vkEndCommandBuffer(command_buffer[1]);
20015 }
20016 {
20017 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020018 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020019
20020 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20021 submit_info[0].pNext = NULL;
20022 submit_info[0].commandBufferCount = 1;
20023 submit_info[0].pCommandBuffers = &command_buffer[0];
20024 submit_info[0].signalSemaphoreCount = 1;
20025 submit_info[0].pSignalSemaphores = &semaphore;
20026 submit_info[0].waitSemaphoreCount = 0;
20027 submit_info[0].pWaitSemaphores = NULL;
20028 submit_info[0].pWaitDstStageMask = 0;
20029
20030 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20031 submit_info[1].pNext = NULL;
20032 submit_info[1].commandBufferCount = 1;
20033 submit_info[1].pCommandBuffers = &command_buffer[1];
20034 submit_info[1].waitSemaphoreCount = 1;
20035 submit_info[1].pWaitSemaphores = &semaphore;
20036 submit_info[1].pWaitDstStageMask = flags;
20037 submit_info[1].signalSemaphoreCount = 0;
20038 submit_info[1].pSignalSemaphores = NULL;
20039 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
20040 }
20041
20042 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20043
20044 vkDestroyFence(m_device->device(), fence, nullptr);
20045 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20046 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20047 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20048
20049 m_errorMonitor->VerifyNotFound();
20050}
20051
20052TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
20053 m_errorMonitor->ExpectSuccess();
20054
20055 ASSERT_NO_FATAL_FAILURE(InitState());
20056 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20057
Tony Barbour552f6c02016-12-21 14:34:07 -070020058 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020059
20060 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
20061 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20062 m_errorMonitor->VerifyNotFound();
20063 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
20064 m_errorMonitor->VerifyNotFound();
20065 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
20066 m_errorMonitor->VerifyNotFound();
20067
20068 m_commandBuffer->EndCommandBuffer();
20069 m_errorMonitor->VerifyNotFound();
20070}
20071
20072TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020073 TEST_DESCRIPTION(
20074 "Positive test where we create a renderpass with an "
20075 "attachment that uses LOAD_OP_CLEAR, the first subpass "
20076 "has a valid layout, and a second subpass then uses a "
20077 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020078 m_errorMonitor->ExpectSuccess();
20079 ASSERT_NO_FATAL_FAILURE(InitState());
20080
20081 VkAttachmentReference attach[2] = {};
20082 attach[0].attachment = 0;
20083 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20084 attach[1].attachment = 0;
20085 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20086 VkSubpassDescription subpasses[2] = {};
20087 // First subpass clears DS attach on load
20088 subpasses[0].pDepthStencilAttachment = &attach[0];
20089 // 2nd subpass reads in DS as input attachment
20090 subpasses[1].inputAttachmentCount = 1;
20091 subpasses[1].pInputAttachments = &attach[1];
20092 VkAttachmentDescription attach_desc = {};
20093 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
20094 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
20095 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
20096 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20097 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20098 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20099 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20100 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
20101 VkRenderPassCreateInfo rpci = {};
20102 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20103 rpci.attachmentCount = 1;
20104 rpci.pAttachments = &attach_desc;
20105 rpci.subpassCount = 2;
20106 rpci.pSubpasses = subpasses;
20107
20108 // Now create RenderPass and verify no errors
20109 VkRenderPass rp;
20110 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
20111 m_errorMonitor->VerifyNotFound();
20112
20113 vkDestroyRenderPass(m_device->device(), rp, NULL);
20114}
20115
20116TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020117 TEST_DESCRIPTION(
20118 "Test that pipeline validation accepts matrices passed "
20119 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020120 m_errorMonitor->ExpectSuccess();
20121
20122 ASSERT_NO_FATAL_FAILURE(InitState());
20123 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20124
20125 VkVertexInputBindingDescription input_binding;
20126 memset(&input_binding, 0, sizeof(input_binding));
20127
20128 VkVertexInputAttributeDescription input_attribs[2];
20129 memset(input_attribs, 0, sizeof(input_attribs));
20130
20131 for (int i = 0; i < 2; i++) {
20132 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20133 input_attribs[i].location = i;
20134 }
20135
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020136 char const *vsSource =
20137 "#version 450\n"
20138 "\n"
20139 "layout(location=0) in mat2x4 x;\n"
20140 "out gl_PerVertex {\n"
20141 " vec4 gl_Position;\n"
20142 "};\n"
20143 "void main(){\n"
20144 " gl_Position = x[0] + x[1];\n"
20145 "}\n";
20146 char const *fsSource =
20147 "#version 450\n"
20148 "\n"
20149 "layout(location=0) out vec4 color;\n"
20150 "void main(){\n"
20151 " color = vec4(1);\n"
20152 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020153
20154 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20155 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20156
20157 VkPipelineObj pipe(m_device);
20158 pipe.AddColorAttachment();
20159 pipe.AddShader(&vs);
20160 pipe.AddShader(&fs);
20161
20162 pipe.AddVertexInputBindings(&input_binding, 1);
20163 pipe.AddVertexInputAttribs(input_attribs, 2);
20164
20165 VkDescriptorSetObj descriptorSet(m_device);
20166 descriptorSet.AppendDummy();
20167 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20168
20169 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20170
20171 /* expect success */
20172 m_errorMonitor->VerifyNotFound();
20173}
20174
20175TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
20176 m_errorMonitor->ExpectSuccess();
20177
20178 ASSERT_NO_FATAL_FAILURE(InitState());
20179 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20180
20181 VkVertexInputBindingDescription input_binding;
20182 memset(&input_binding, 0, sizeof(input_binding));
20183
20184 VkVertexInputAttributeDescription input_attribs[2];
20185 memset(input_attribs, 0, sizeof(input_attribs));
20186
20187 for (int i = 0; i < 2; i++) {
20188 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20189 input_attribs[i].location = i;
20190 }
20191
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020192 char const *vsSource =
20193 "#version 450\n"
20194 "\n"
20195 "layout(location=0) in vec4 x[2];\n"
20196 "out gl_PerVertex {\n"
20197 " vec4 gl_Position;\n"
20198 "};\n"
20199 "void main(){\n"
20200 " gl_Position = x[0] + x[1];\n"
20201 "}\n";
20202 char const *fsSource =
20203 "#version 450\n"
20204 "\n"
20205 "layout(location=0) out vec4 color;\n"
20206 "void main(){\n"
20207 " color = vec4(1);\n"
20208 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020209
20210 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20211 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20212
20213 VkPipelineObj pipe(m_device);
20214 pipe.AddColorAttachment();
20215 pipe.AddShader(&vs);
20216 pipe.AddShader(&fs);
20217
20218 pipe.AddVertexInputBindings(&input_binding, 1);
20219 pipe.AddVertexInputAttribs(input_attribs, 2);
20220
20221 VkDescriptorSetObj descriptorSet(m_device);
20222 descriptorSet.AppendDummy();
20223 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20224
20225 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20226
20227 m_errorMonitor->VerifyNotFound();
20228}
20229
20230TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020231 TEST_DESCRIPTION(
20232 "Test that pipeline validation accepts consuming a vertex attribute "
20233 "through multiple vertex shader inputs, each consuming a different "
20234 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020235 m_errorMonitor->ExpectSuccess();
20236
20237 ASSERT_NO_FATAL_FAILURE(InitState());
20238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20239
20240 VkVertexInputBindingDescription input_binding;
20241 memset(&input_binding, 0, sizeof(input_binding));
20242
20243 VkVertexInputAttributeDescription input_attribs[3];
20244 memset(input_attribs, 0, sizeof(input_attribs));
20245
20246 for (int i = 0; i < 3; i++) {
20247 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
20248 input_attribs[i].location = i;
20249 }
20250
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020251 char const *vsSource =
20252 "#version 450\n"
20253 "\n"
20254 "layout(location=0) in vec4 x;\n"
20255 "layout(location=1) in vec3 y1;\n"
20256 "layout(location=1, component=3) in float y2;\n"
20257 "layout(location=2) in vec4 z;\n"
20258 "out gl_PerVertex {\n"
20259 " vec4 gl_Position;\n"
20260 "};\n"
20261 "void main(){\n"
20262 " gl_Position = x + vec4(y1, y2) + z;\n"
20263 "}\n";
20264 char const *fsSource =
20265 "#version 450\n"
20266 "\n"
20267 "layout(location=0) out vec4 color;\n"
20268 "void main(){\n"
20269 " color = vec4(1);\n"
20270 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020271
20272 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20273 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20274
20275 VkPipelineObj pipe(m_device);
20276 pipe.AddColorAttachment();
20277 pipe.AddShader(&vs);
20278 pipe.AddShader(&fs);
20279
20280 pipe.AddVertexInputBindings(&input_binding, 1);
20281 pipe.AddVertexInputAttribs(input_attribs, 3);
20282
20283 VkDescriptorSetObj descriptorSet(m_device);
20284 descriptorSet.AppendDummy();
20285 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20286
20287 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20288
20289 m_errorMonitor->VerifyNotFound();
20290}
20291
20292TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
20293 m_errorMonitor->ExpectSuccess();
20294
20295 ASSERT_NO_FATAL_FAILURE(InitState());
20296 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20297
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020298 char const *vsSource =
20299 "#version 450\n"
20300 "out gl_PerVertex {\n"
20301 " vec4 gl_Position;\n"
20302 "};\n"
20303 "void main(){\n"
20304 " gl_Position = vec4(0);\n"
20305 "}\n";
20306 char const *fsSource =
20307 "#version 450\n"
20308 "\n"
20309 "layout(location=0) out vec4 color;\n"
20310 "void main(){\n"
20311 " color = vec4(1);\n"
20312 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020313
20314 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20315 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20316
20317 VkPipelineObj pipe(m_device);
20318 pipe.AddColorAttachment();
20319 pipe.AddShader(&vs);
20320 pipe.AddShader(&fs);
20321
20322 VkDescriptorSetObj descriptorSet(m_device);
20323 descriptorSet.AppendDummy();
20324 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20325
20326 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20327
20328 m_errorMonitor->VerifyNotFound();
20329}
20330
20331TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020332 TEST_DESCRIPTION(
20333 "Test that pipeline validation accepts the relaxed type matching rules "
20334 "set out in 14.1.3: fundamental type must match, and producer side must "
20335 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020336 m_errorMonitor->ExpectSuccess();
20337
20338 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
20339
20340 ASSERT_NO_FATAL_FAILURE(InitState());
20341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20342
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020343 char const *vsSource =
20344 "#version 450\n"
20345 "out gl_PerVertex {\n"
20346 " vec4 gl_Position;\n"
20347 "};\n"
20348 "layout(location=0) out vec3 x;\n"
20349 "layout(location=1) out ivec3 y;\n"
20350 "layout(location=2) out vec3 z;\n"
20351 "void main(){\n"
20352 " gl_Position = vec4(0);\n"
20353 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
20354 "}\n";
20355 char const *fsSource =
20356 "#version 450\n"
20357 "\n"
20358 "layout(location=0) out vec4 color;\n"
20359 "layout(location=0) in float x;\n"
20360 "layout(location=1) flat in int y;\n"
20361 "layout(location=2) in vec2 z;\n"
20362 "void main(){\n"
20363 " color = vec4(1 + x + y + z.x);\n"
20364 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020365
20366 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20367 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20368
20369 VkPipelineObj pipe(m_device);
20370 pipe.AddColorAttachment();
20371 pipe.AddShader(&vs);
20372 pipe.AddShader(&fs);
20373
20374 VkDescriptorSetObj descriptorSet(m_device);
20375 descriptorSet.AppendDummy();
20376 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20377
20378 VkResult err = VK_SUCCESS;
20379 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20380 ASSERT_VK_SUCCESS(err);
20381
20382 m_errorMonitor->VerifyNotFound();
20383}
20384
20385TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020386 TEST_DESCRIPTION(
20387 "Test that pipeline validation accepts per-vertex variables "
20388 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020389 m_errorMonitor->ExpectSuccess();
20390
20391 ASSERT_NO_FATAL_FAILURE(InitState());
20392 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20393
20394 if (!m_device->phy().features().tessellationShader) {
20395 printf("Device does not support tessellation shaders; skipped.\n");
20396 return;
20397 }
20398
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020399 char const *vsSource =
20400 "#version 450\n"
20401 "void main(){}\n";
20402 char const *tcsSource =
20403 "#version 450\n"
20404 "layout(location=0) out int x[];\n"
20405 "layout(vertices=3) out;\n"
20406 "void main(){\n"
20407 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
20408 " gl_TessLevelInner[0] = 1;\n"
20409 " x[gl_InvocationID] = gl_InvocationID;\n"
20410 "}\n";
20411 char const *tesSource =
20412 "#version 450\n"
20413 "layout(triangles, equal_spacing, cw) in;\n"
20414 "layout(location=0) in int x[];\n"
20415 "out gl_PerVertex { vec4 gl_Position; };\n"
20416 "void main(){\n"
20417 " gl_Position.xyz = gl_TessCoord;\n"
20418 " gl_Position.w = x[0] + x[1] + x[2];\n"
20419 "}\n";
20420 char const *fsSource =
20421 "#version 450\n"
20422 "layout(location=0) out vec4 color;\n"
20423 "void main(){\n"
20424 " color = vec4(1);\n"
20425 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020426
20427 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20428 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
20429 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
20430 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20431
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020432 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
20433 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020434
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020435 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020436
20437 VkPipelineObj pipe(m_device);
20438 pipe.SetInputAssembly(&iasci);
20439 pipe.SetTessellation(&tsci);
20440 pipe.AddColorAttachment();
20441 pipe.AddShader(&vs);
20442 pipe.AddShader(&tcs);
20443 pipe.AddShader(&tes);
20444 pipe.AddShader(&fs);
20445
20446 VkDescriptorSetObj descriptorSet(m_device);
20447 descriptorSet.AppendDummy();
20448 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20449
20450 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20451
20452 m_errorMonitor->VerifyNotFound();
20453}
20454
20455TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020456 TEST_DESCRIPTION(
20457 "Test that pipeline validation accepts a user-defined "
20458 "interface block passed into the geometry shader. This "
20459 "is interesting because the 'extra' array level is not "
20460 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020461 m_errorMonitor->ExpectSuccess();
20462
20463 ASSERT_NO_FATAL_FAILURE(InitState());
20464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20465
20466 if (!m_device->phy().features().geometryShader) {
20467 printf("Device does not support geometry shaders; skipped.\n");
20468 return;
20469 }
20470
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020471 char const *vsSource =
20472 "#version 450\n"
20473 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
20474 "void main(){\n"
20475 " vs_out.x = vec4(1);\n"
20476 "}\n";
20477 char const *gsSource =
20478 "#version 450\n"
20479 "layout(triangles) in;\n"
20480 "layout(triangle_strip, max_vertices=3) out;\n"
20481 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
20482 "out gl_PerVertex { vec4 gl_Position; };\n"
20483 "void main() {\n"
20484 " gl_Position = gs_in[0].x;\n"
20485 " EmitVertex();\n"
20486 "}\n";
20487 char const *fsSource =
20488 "#version 450\n"
20489 "layout(location=0) out vec4 color;\n"
20490 "void main(){\n"
20491 " color = vec4(1);\n"
20492 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020493
20494 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20495 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
20496 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20497
20498 VkPipelineObj pipe(m_device);
20499 pipe.AddColorAttachment();
20500 pipe.AddShader(&vs);
20501 pipe.AddShader(&gs);
20502 pipe.AddShader(&fs);
20503
20504 VkDescriptorSetObj descriptorSet(m_device);
20505 descriptorSet.AppendDummy();
20506 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20507
20508 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20509
20510 m_errorMonitor->VerifyNotFound();
20511}
20512
20513TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020514 TEST_DESCRIPTION(
20515 "Test that pipeline validation accepts basic use of 64bit vertex "
20516 "attributes. This is interesting because they consume multiple "
20517 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020518 m_errorMonitor->ExpectSuccess();
20519
20520 ASSERT_NO_FATAL_FAILURE(InitState());
20521 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20522
20523 if (!m_device->phy().features().shaderFloat64) {
20524 printf("Device does not support 64bit vertex attributes; skipped.\n");
20525 return;
20526 }
20527
20528 VkVertexInputBindingDescription input_bindings[1];
20529 memset(input_bindings, 0, sizeof(input_bindings));
20530
20531 VkVertexInputAttributeDescription input_attribs[4];
20532 memset(input_attribs, 0, sizeof(input_attribs));
20533 input_attribs[0].location = 0;
20534 input_attribs[0].offset = 0;
20535 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20536 input_attribs[1].location = 2;
20537 input_attribs[1].offset = 32;
20538 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20539 input_attribs[2].location = 4;
20540 input_attribs[2].offset = 64;
20541 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20542 input_attribs[3].location = 6;
20543 input_attribs[3].offset = 96;
20544 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
20545
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020546 char const *vsSource =
20547 "#version 450\n"
20548 "\n"
20549 "layout(location=0) in dmat4 x;\n"
20550 "out gl_PerVertex {\n"
20551 " vec4 gl_Position;\n"
20552 "};\n"
20553 "void main(){\n"
20554 " gl_Position = vec4(x[0][0]);\n"
20555 "}\n";
20556 char const *fsSource =
20557 "#version 450\n"
20558 "\n"
20559 "layout(location=0) out vec4 color;\n"
20560 "void main(){\n"
20561 " color = vec4(1);\n"
20562 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020563
20564 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20565 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20566
20567 VkPipelineObj pipe(m_device);
20568 pipe.AddColorAttachment();
20569 pipe.AddShader(&vs);
20570 pipe.AddShader(&fs);
20571
20572 pipe.AddVertexInputBindings(input_bindings, 1);
20573 pipe.AddVertexInputAttribs(input_attribs, 4);
20574
20575 VkDescriptorSetObj descriptorSet(m_device);
20576 descriptorSet.AppendDummy();
20577 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20578
20579 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
20580
20581 m_errorMonitor->VerifyNotFound();
20582}
20583
20584TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
20585 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
20586 m_errorMonitor->ExpectSuccess();
20587
20588 ASSERT_NO_FATAL_FAILURE(InitState());
20589
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020590 char const *vsSource =
20591 "#version 450\n"
20592 "\n"
20593 "out gl_PerVertex {\n"
20594 " vec4 gl_Position;\n"
20595 "};\n"
20596 "void main(){\n"
20597 " gl_Position = vec4(1);\n"
20598 "}\n";
20599 char const *fsSource =
20600 "#version 450\n"
20601 "\n"
20602 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
20603 "layout(location=0) out vec4 color;\n"
20604 "void main() {\n"
20605 " color = subpassLoad(x);\n"
20606 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020607
20608 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
20609 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20610
20611 VkPipelineObj pipe(m_device);
20612 pipe.AddShader(&vs);
20613 pipe.AddShader(&fs);
20614 pipe.AddColorAttachment();
20615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20616
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020617 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
20618 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020619 VkDescriptorSetLayout dsl;
20620 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20621 ASSERT_VK_SUCCESS(err);
20622
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020623 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020624 VkPipelineLayout pl;
20625 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20626 ASSERT_VK_SUCCESS(err);
20627
20628 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020629 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20630 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20631 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
20632 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
20633 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 -060020634 };
20635 VkAttachmentReference color = {
20636 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
20637 };
20638 VkAttachmentReference input = {
20639 1, VK_IMAGE_LAYOUT_GENERAL,
20640 };
20641
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020642 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020643
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020644 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020645 VkRenderPass rp;
20646 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20647 ASSERT_VK_SUCCESS(err);
20648
20649 // should be OK. would go wrong here if it's going to...
20650 pipe.CreateVKPipeline(pl, rp);
20651
20652 m_errorMonitor->VerifyNotFound();
20653
20654 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20655 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20656 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20657}
20658
20659TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020660 TEST_DESCRIPTION(
20661 "Test that pipeline validation accepts a compute pipeline which declares a "
20662 "descriptor-backed resource which is not provided, but the shader does not "
20663 "statically use it. This is interesting because it requires compute pipelines "
20664 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020665 m_errorMonitor->ExpectSuccess();
20666
20667 ASSERT_NO_FATAL_FAILURE(InitState());
20668
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020669 char const *csSource =
20670 "#version 450\n"
20671 "\n"
20672 "layout(local_size_x=1) in;\n"
20673 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
20674 "void main(){\n"
20675 " // x is not used.\n"
20676 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020677
20678 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20679
20680 VkDescriptorSetObj descriptorSet(m_device);
20681 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
20682
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020683 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20684 nullptr,
20685 0,
20686 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20687 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20688 descriptorSet.GetPipelineLayout(),
20689 VK_NULL_HANDLE,
20690 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020691
20692 VkPipeline pipe;
20693 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20694
20695 m_errorMonitor->VerifyNotFound();
20696
20697 if (err == VK_SUCCESS) {
20698 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20699 }
20700}
20701
20702TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020703 TEST_DESCRIPTION(
20704 "Test that pipeline validation accepts a shader consuming only the "
20705 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020706 m_errorMonitor->ExpectSuccess();
20707
20708 ASSERT_NO_FATAL_FAILURE(InitState());
20709
20710 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020711 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20712 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20713 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020714 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020715 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020716 VkDescriptorSetLayout dsl;
20717 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20718 ASSERT_VK_SUCCESS(err);
20719
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020720 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020721 VkPipelineLayout pl;
20722 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20723 ASSERT_VK_SUCCESS(err);
20724
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020725 char const *csSource =
20726 "#version 450\n"
20727 "\n"
20728 "layout(local_size_x=1) in;\n"
20729 "layout(set=0, binding=0) uniform sampler s;\n"
20730 "layout(set=0, binding=1) uniform texture2D t;\n"
20731 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20732 "void main() {\n"
20733 " x = texture(sampler2D(t, s), vec2(0));\n"
20734 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020735 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20736
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020737 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20738 nullptr,
20739 0,
20740 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20741 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20742 pl,
20743 VK_NULL_HANDLE,
20744 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020745
20746 VkPipeline pipe;
20747 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20748
20749 m_errorMonitor->VerifyNotFound();
20750
20751 if (err == VK_SUCCESS) {
20752 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20753 }
20754
20755 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20756 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20757}
20758
20759TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020760 TEST_DESCRIPTION(
20761 "Test that pipeline validation accepts a shader consuming only the "
20762 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020763 m_errorMonitor->ExpectSuccess();
20764
20765 ASSERT_NO_FATAL_FAILURE(InitState());
20766
20767 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020768 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20769 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20770 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020771 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020772 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020773 VkDescriptorSetLayout dsl;
20774 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20775 ASSERT_VK_SUCCESS(err);
20776
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020777 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020778 VkPipelineLayout pl;
20779 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20780 ASSERT_VK_SUCCESS(err);
20781
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020782 char const *csSource =
20783 "#version 450\n"
20784 "\n"
20785 "layout(local_size_x=1) in;\n"
20786 "layout(set=0, binding=0) uniform texture2D t;\n"
20787 "layout(set=0, binding=1) uniform sampler s;\n"
20788 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
20789 "void main() {\n"
20790 " x = texture(sampler2D(t, s), vec2(0));\n"
20791 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020792 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20793
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020794 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20795 nullptr,
20796 0,
20797 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20798 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20799 pl,
20800 VK_NULL_HANDLE,
20801 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020802
20803 VkPipeline pipe;
20804 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20805
20806 m_errorMonitor->VerifyNotFound();
20807
20808 if (err == VK_SUCCESS) {
20809 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20810 }
20811
20812 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20813 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20814}
20815
20816TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020817 TEST_DESCRIPTION(
20818 "Test that pipeline validation accepts a shader consuming "
20819 "both the sampler and the image of a combined image+sampler "
20820 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020821 m_errorMonitor->ExpectSuccess();
20822
20823 ASSERT_NO_FATAL_FAILURE(InitState());
20824
20825 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020826 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
20827 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020828 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020829 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020830 VkDescriptorSetLayout dsl;
20831 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
20832 ASSERT_VK_SUCCESS(err);
20833
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020834 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020835 VkPipelineLayout pl;
20836 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
20837 ASSERT_VK_SUCCESS(err);
20838
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020839 char const *csSource =
20840 "#version 450\n"
20841 "\n"
20842 "layout(local_size_x=1) in;\n"
20843 "layout(set=0, binding=0) uniform texture2D t;\n"
20844 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
20845 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
20846 "void main() {\n"
20847 " x = texture(sampler2D(t, s), vec2(0));\n"
20848 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020849 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
20850
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020851 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
20852 nullptr,
20853 0,
20854 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
20855 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
20856 pl,
20857 VK_NULL_HANDLE,
20858 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020859
20860 VkPipeline pipe;
20861 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
20862
20863 m_errorMonitor->VerifyNotFound();
20864
20865 if (err == VK_SUCCESS) {
20866 vkDestroyPipeline(m_device->device(), pipe, nullptr);
20867 }
20868
20869 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
20870 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
20871}
20872
20873TEST_F(VkPositiveLayerTest, ValidStructPNext) {
20874 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
20875
20876 ASSERT_NO_FATAL_FAILURE(InitState());
20877
20878 // Positive test to check parameter_validation and unique_objects support
20879 // for NV_dedicated_allocation
20880 uint32_t extension_count = 0;
20881 bool supports_nv_dedicated_allocation = false;
20882 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
20883 ASSERT_VK_SUCCESS(err);
20884
20885 if (extension_count > 0) {
20886 std::vector<VkExtensionProperties> available_extensions(extension_count);
20887
20888 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
20889 ASSERT_VK_SUCCESS(err);
20890
20891 for (const auto &extension_props : available_extensions) {
20892 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
20893 supports_nv_dedicated_allocation = true;
20894 }
20895 }
20896 }
20897
20898 if (supports_nv_dedicated_allocation) {
20899 m_errorMonitor->ExpectSuccess();
20900
20901 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
20902 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
20903 dedicated_buffer_create_info.pNext = nullptr;
20904 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
20905
20906 uint32_t queue_family_index = 0;
20907 VkBufferCreateInfo buffer_create_info = {};
20908 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20909 buffer_create_info.pNext = &dedicated_buffer_create_info;
20910 buffer_create_info.size = 1024;
20911 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
20912 buffer_create_info.queueFamilyIndexCount = 1;
20913 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
20914
20915 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070020916 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020917 ASSERT_VK_SUCCESS(err);
20918
20919 VkMemoryRequirements memory_reqs;
20920 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
20921
20922 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
20923 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
20924 dedicated_memory_info.pNext = nullptr;
20925 dedicated_memory_info.buffer = buffer;
20926 dedicated_memory_info.image = VK_NULL_HANDLE;
20927
20928 VkMemoryAllocateInfo memory_info = {};
20929 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20930 memory_info.pNext = &dedicated_memory_info;
20931 memory_info.allocationSize = memory_reqs.size;
20932
20933 bool pass;
20934 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
20935 ASSERT_TRUE(pass);
20936
20937 VkDeviceMemory buffer_memory;
20938 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
20939 ASSERT_VK_SUCCESS(err);
20940
20941 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
20942 ASSERT_VK_SUCCESS(err);
20943
20944 vkDestroyBuffer(m_device->device(), buffer, NULL);
20945 vkFreeMemory(m_device->device(), buffer_memory, NULL);
20946
20947 m_errorMonitor->VerifyNotFound();
20948 }
20949}
20950
20951TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
20952 VkResult err;
20953
20954 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
20955
20956 ASSERT_NO_FATAL_FAILURE(InitState());
20957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20958
20959 std::vector<const char *> device_extension_names;
20960 auto features = m_device->phy().features();
20961 // Artificially disable support for non-solid fill modes
20962 features.fillModeNonSolid = false;
20963 // The sacrificial device object
20964 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
20965
20966 VkRenderpassObj render_pass(&test_device);
20967
20968 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
20969 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
20970 pipeline_layout_ci.setLayoutCount = 0;
20971 pipeline_layout_ci.pSetLayouts = NULL;
20972
20973 VkPipelineLayout pipeline_layout;
20974 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
20975 ASSERT_VK_SUCCESS(err);
20976
20977 VkPipelineRasterizationStateCreateInfo rs_ci = {};
20978 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
20979 rs_ci.pNext = nullptr;
20980 rs_ci.lineWidth = 1.0f;
20981 rs_ci.rasterizerDiscardEnable = true;
20982
20983 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
20984 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
20985
20986 // Set polygonMode=FILL. No error is expected
20987 m_errorMonitor->ExpectSuccess();
20988 {
20989 VkPipelineObj pipe(&test_device);
20990 pipe.AddShader(&vs);
20991 pipe.AddShader(&fs);
20992 pipe.AddColorAttachment();
20993 // Set polygonMode to a good value
20994 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
20995 pipe.SetRasterization(&rs_ci);
20996 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
20997 }
20998 m_errorMonitor->VerifyNotFound();
20999
21000 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
21001}
21002
21003TEST_F(VkPositiveLayerTest, ValidPushConstants) {
21004 VkResult err;
21005 ASSERT_NO_FATAL_FAILURE(InitState());
21006 ASSERT_NO_FATAL_FAILURE(InitViewport());
21007 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21008
21009 VkPipelineLayout pipeline_layout;
21010 VkPushConstantRange pc_range = {};
21011 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
21012 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
21013 pipeline_layout_ci.pushConstantRangeCount = 1;
21014 pipeline_layout_ci.pPushConstantRanges = &pc_range;
21015
21016 //
21017 // Check for invalid push constant ranges in pipeline layouts.
21018 //
21019 struct PipelineLayoutTestCase {
21020 VkPushConstantRange const range;
21021 char const *msg;
21022 };
21023
21024 // Check for overlapping ranges
21025 const uint32_t ranges_per_test = 5;
21026 struct OverlappingRangeTestCase {
21027 VkPushConstantRange const ranges[ranges_per_test];
21028 char const *msg;
21029 };
21030
21031 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021032 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
21033 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
21034 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
21035 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
21036 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
21037 ""},
21038 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
21039 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
21040 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
21041 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
21042 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
21043 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021044 for (const auto &iter : overlapping_range_tests_pos) {
21045 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
21046 m_errorMonitor->ExpectSuccess();
21047 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21048 m_errorMonitor->VerifyNotFound();
21049 if (VK_SUCCESS == err) {
21050 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21051 }
21052 }
21053
21054 //
21055 // CmdPushConstants tests
21056 //
21057 const uint8_t dummy_values[100] = {};
21058
Tony Barbour552f6c02016-12-21 14:34:07 -070021059 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021060
21061 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021062 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
21063 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
21064 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
21065 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
21066 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
21067 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021068
21069 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
21070 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021071 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
21072 {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 -060021073 };
21074
21075 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
21076 pipeline_layout_ci.pPushConstantRanges = pc_range4;
21077 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
21078 ASSERT_VK_SUCCESS(err);
21079 for (const auto &iter : cmd_overlap_tests_pos) {
21080 m_errorMonitor->ExpectSuccess();
21081 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021082 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021083 m_errorMonitor->VerifyNotFound();
21084 }
21085 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
21086
Tony Barbour552f6c02016-12-21 14:34:07 -070021087 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021088}
21089
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021090#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021091TEST_F(VkPositiveLayerTest, LongFenceChain)
21092{
21093 m_errorMonitor->ExpectSuccess();
21094
21095 ASSERT_NO_FATAL_FAILURE(InitState());
21096 VkResult err;
21097
21098 std::vector<VkFence> fences;
21099
21100 const int chainLength = 32768;
21101
21102 for (int i = 0; i < chainLength; i++) {
21103 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
21104 VkFence fence;
21105 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
21106 ASSERT_VK_SUCCESS(err);
21107
21108 fences.push_back(fence);
21109
21110 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
21111 0, nullptr, 0, nullptr };
21112 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
21113 ASSERT_VK_SUCCESS(err);
21114
21115 }
21116
21117 // BOOM, stack overflow.
21118 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
21119
21120 for (auto fence : fences)
21121 vkDestroyFence(m_device->device(), fence, nullptr);
21122
21123 m_errorMonitor->VerifyNotFound();
21124}
21125#endif
21126
Cody Northrop1242dfd2016-07-13 17:24:59 -060021127#if defined(ANDROID) && defined(VALIDATION_APK)
21128static bool initialized = false;
21129static bool active = false;
21130
21131// Convert Intents to argv
21132// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021133std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021134 std::vector<std::string> args;
21135 JavaVM &vm = *app.activity->vm;
21136 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021137 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021138
21139 JNIEnv &env = *p_env;
21140 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021141 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021142 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021143 jmethodID get_string_extra_method =
21144 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060021145 jvalue get_string_extra_args;
21146 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021147 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060021148
21149 std::string args_str;
21150 if (extra_str) {
21151 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
21152 args_str = extra_utf;
21153 env.ReleaseStringUTFChars(extra_str, extra_utf);
21154 env.DeleteLocalRef(extra_str);
21155 }
21156
21157 env.DeleteLocalRef(get_string_extra_args.l);
21158 env.DeleteLocalRef(intent);
21159 vm.DetachCurrentThread();
21160
21161 // split args_str
21162 std::stringstream ss(args_str);
21163 std::string arg;
21164 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021165 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021166 }
21167
21168 return args;
21169}
21170
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021171static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021173static void processCommand(struct android_app *app, int32_t cmd) {
21174 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021175 case APP_CMD_INIT_WINDOW: {
21176 if (app->window) {
21177 initialized = true;
21178 }
21179 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021180 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021181 case APP_CMD_GAINED_FOCUS: {
21182 active = true;
21183 break;
21184 }
21185 case APP_CMD_LOST_FOCUS: {
21186 active = false;
21187 break;
21188 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021189 }
21190}
21191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021192void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021193 app_dummy();
21194
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021195 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060021196
21197 int vulkanSupport = InitVulkan();
21198 if (vulkanSupport == 0) {
21199 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
21200 return;
21201 }
21202
21203 app->onAppCmd = processCommand;
21204 app->onInputEvent = processInput;
21205
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021206 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021207 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021208 struct android_poll_source *source;
21209 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060021210 if (source) {
21211 source->process(app, source);
21212 }
21213
21214 if (app->destroyRequested != 0) {
21215 VkTestFramework::Finish();
21216 return;
21217 }
21218 }
21219
21220 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021221 // Use the following key to send arguments to gtest, i.e.
21222 // --es args "--gtest_filter=-VkLayerTest.foo"
21223 const char key[] = "args";
21224 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021225
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021226 std::string filter = "";
21227 if (args.size() > 0) {
21228 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
21229 filter += args[0];
21230 } else {
21231 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
21232 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021234 int argc = 2;
21235 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
21236 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021237
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021238 // Route output to files until we can override the gtest output
21239 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
21240 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021242 ::testing::InitGoogleTest(&argc, argv);
21243 VkTestFramework::InitArgs(&argc, argv);
21244 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021245
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021246 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021247
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021248 if (result != 0) {
21249 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
21250 } else {
21251 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
21252 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060021253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021254 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060021255
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021256 fclose(stdout);
21257 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021258
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021259 ANativeActivity_finish(app->activity);
Cody Northrop1242dfd2016-07-13 17:24:59 -060021260
Mark Lobodzinskice751c62016-09-08 10:45:35 -060021261 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060021262 }
21263 }
21264}
21265#endif
21266
Tony Barbour300a6082015-04-07 13:44:53 -060021267int main(int argc, char **argv) {
21268 int result;
21269
Cody Northrop8e54a402016-03-08 22:25:52 -070021270#ifdef ANDROID
21271 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021272 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070021273#endif
21274
Tony Barbour300a6082015-04-07 13:44:53 -060021275 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060021276 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060021277
21278 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
21279
21280 result = RUN_ALL_TESTS();
21281
Tony Barbour6918cd52015-04-09 12:58:51 -060021282 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060021283 return result;
21284}